Example #1
0
    public void TestDeleteDataset()
    {
        var    snippet   = new BigQueryDeleteDataset();
        string datasetId = TestUtil.RandomName();

        _client.CreateDataset(datasetId);
        snippet.DeleteDataset(_projectId, datasetId);
        var output = _stringOut.ToString();

        Assert.Contains($"{datasetId} deleted", output);
    }
        /// <summary>
        /// Imports data from a CSV source
        /// </summary>
        /// <param name="datasetId">Dataset identifier.</param>
        /// <param name="tableId">Table identifier.</param>
        /// <param name="client">A BigQuery client.</param>
        public static void LoadTableFromCSV(string datasetId,
                                            string tableId, BigQueryClient client)
        {
            // [START bigquery_load_table_gcs_csv]
            var gcsURI = "gs://cloud-samples-data/bigquery/us-states/us-states.csv";

            var dataset = client.CreateDataset(datasetId);

            var schema = new TableSchemaBuilder {
                { "name", BigQueryDbType.String },
                { "post_abbr", BigQueryDbType.String }
            }.Build();

            var jobOptions = new CreateLoadJobOptions()
            {
                // The source format defaults to CSV; line below is optional.
                SourceFormat    = FileFormat.Csv,
                SkipLeadingRows = 1
            };

            var loadJob = client.CreateLoadJob(gcsURI, dataset.GetTableReference(tableId),
                                               schema, jobOptions);

            loadJob.PollUntilCompleted();

            // [END bigquery_load_table_gcs_csv]
        }
        /// <summary>
        /// Loads the table from a JSON source.
        /// </summary>
        /// <param name="client">BigQuery client</param>
        /// <param name="datasetId"></param>
        /// <param name="tableId"></param>
        public static void LoadTableFromJSON(BigQueryClient client,
                                             string datasetId, string tableId)
        {
            // [START bigquery_load_table_gcs_json]
            var gcsURI = "gs://cloud-samples-data/bigquery/us-states/us-states.json";

            var dataset = client.CreateDataset(datasetId);

            var schema = new TableSchemaBuilder {
                { "name", BigQueryDbType.String },
                { "post_abbr", BigQueryDbType.String }
            }.Build();

            var jobOptions = new CreateLoadJobOptions()
            {
                SourceFormat = FileFormat.NewlineDelimitedJson
            };

            var loadJob = client.CreateLoadJob(gcsURI, dataset.GetTableReference(tableId),
                                               schema, jobOptions);

            loadJob.PollUntilCompleted();

            // [END bigquery_load_table_gcs_json]
        }
        public BigQueryDataset CreateDataset(string projectId,
                                             string location, string datasetId
                                             )
        {
            BigQueryClient client = BigQueryClient.Create(projectId);
            var            createDatasetOptions = new CreateDatasetOptions()
            {
                // Specify the geographic location where the dataset should reside.
                Location = location
            };

            // Create the dataset
            return(client.CreateDataset(
                       datasetId: datasetId, options: createDatasetOptions));
        }
        static void Main(string[] args)
        {
            // Your Google Cloud Platform project ID
            string projectId = "YOUR_PROJECT_ID";

            // Instantiates a client
            BigQueryClient client = BigQueryClient.Create(projectId);

            // The id for the new dataset
            string datasetId = "my_new_dataset";

            // Creates the dataset
            BigQueryDataset dataset = client.CreateDataset(datasetId);

            Console.WriteLine($"Dataset {dataset.FullyQualifiedId} created.");
        }
Example #6
0
    public BigQueryDataset CreateDataset(
        string projectId = "your-project-id",
        string location  = "US"
        )
    {
        BigQueryClient client  = BigQueryClient.Create(projectId);
        var            dataset = new Dataset
        {
            // Specify the geographic location where the dataset should reside.
            Location = location
        };

        // Create the dataset
        return(client.CreateDataset(
                   datasetId: "your_new_dataset_id", dataset));
    }
Example #7
0
    public AssetFixture()
    {
        ProjectId = Environment.GetEnvironmentVariable("GOOGLE_PROJECT_ID");
        if (string.IsNullOrEmpty(ProjectId))
        {
            throw new Exception("missing GOOGLE_PROJECT_ID");
        }

        _bucketFixture = new RandomBucketFixture();
        BucketName     = _bucketFixture.BucketName;

        _bigQueryClient = BigQueryClient.Create(ProjectId);
        DatasetId       = RandomDatasetId();
        var dataset = new Dataset {
            Location = "US"
        };

        _bigQueryClient.CreateDataset(datasetId: DatasetId, dataset);
    }
Example #8
0
    public AssetFixture()
    {
        ProjectId = Environment.GetEnvironmentVariable("GOOGLE_PROJECT_ID");
        if (string.IsNullOrEmpty(ProjectId))
        {
            throw new Exception("missing GOOGLE_PROJECT_ID");
        }

        _bucketFixture = new RandomBucketFixture();
        BucketName     = _bucketFixture.BucketName;

        _bigQueryClient = BigQueryClient.Create(ProjectId);
        DatasetId       = RandomDatasetId();
        var dataset = new Dataset {
            Location = "US"
        };

        _bigQueryClient.CreateDataset(datasetId: DatasetId, dataset);

        // Wait 10 seconds to let resource creation events go to CAI.
        Thread.Sleep(10000);
    }