コード例 #1
0
        public void TestImportFromCloudStorage()
        {
            string datasetId         = "datasetForTestImportFromCloudStorage";
            string newTableId        = "tableForTestImportFromCloudStorage";
            string jsonGcsSampleFile = "sample.json";
            string gcsFolder         = "test";
            string gcsUploadTestWord = "exampleJsonFromGCS";

            CreateDataset(datasetId, _client);
            CreateTable(datasetId, newTableId, _client);
            // Import data.
            ImportDataFromCloudStorage(_projectId, datasetId, newTableId, _client,
                                       jsonGcsSampleFile, gcsFolder);
            // Run query to get table data.
            var              newTable = _client.GetTable(datasetId, newTableId);
            string           query    = $"SELECT title, unique_words FROM {newTable}";
            BigqueryQueryJob results  = AsyncQuery(_projectId, datasetId, newTableId,
                                                   query, _client);
            // Get first row and confirm it contains the expected value.
            var row = results.GetRows().First();

            Assert.Equal(gcsUploadTestWord, row["title"]);
            DeleteTable(datasetId, newTableId, _client);
            DeleteDataset(datasetId, _client);
        }
コード例 #2
0
        public void TestAsyncQuery()
        {
            string           projectId = "bigquery-public-data";
            string           datasetId = "samples";
            string           tableId   = "shakespeare";
            var              table     = _client.GetTable(projectId, datasetId, tableId);
            string           query     = $@"SELECT corpus AS title, COUNT(*) AS unique_words FROM {table} 
                GROUP BY title ORDER BY unique_words DESC LIMIT 42";
            BigqueryQueryJob results   = AsyncQuery(projectId, datasetId, tableId, query, _client);

            Assert.True(results.GetRows().Count() > 0);
        }
コード例 #3
0
        public void TestLegacySqlSyncQuery()
        {
            string           projectId = "bigquery-public-data";
            string           datasetId = "samples";
            string           tableId   = "shakespeare";
            var              table     = _client.GetTable(projectId, datasetId, tableId);
            string           query     = $"SELECT TOP(corpus, 42) as title, COUNT(*) as unique_words FROM [{table.FullyQualifiedId}]";
            BigqueryQueryJob results   = LegacySqlSyncQuery(
                projectId, datasetId, tableId, query, 10000, _client);

            Assert.True(results.GetRows().Count() > 0);
        }
コード例 #4
0
        // [END sync_query]

        // [START sync_query_legacy_sql]
        public BigqueryQueryJob LegacySqlSyncQuery(string projectId, string datasetId,
                                                   string tableId, string query, double timeoutMs, BigqueryClient client)
        {
            var         table = client.GetTable(projectId, datasetId, tableId);
            BigqueryJob job   = client.CreateQueryJob(query,
                                                      new CreateQueryJobOptions {
                UseLegacySql = true
            });
            // Get the query result, waiting for the timespan specified in milliseconds.
            BigqueryQueryJob result = client.GetQueryResults(job.Reference.JobId,
                                                             new GetQueryResultsOptions {
                Timeout = TimeSpan.FromMilliseconds(timeoutMs)
            });

            return(result);
        }
コード例 #5
0
        public void TestImportDataFromStream()
        {
            string datasetId         = "datasetForTestImportDataFromStream";
            string newTableId        = "tableForTestImportDataFromStream";
            string gcsUploadTestWord = "exampleJsonFromStream";

            CreateDataset(datasetId, _client);
            CreateTable(datasetId, newTableId, _client);
            // Import data.
            UploadJson(datasetId, newTableId, _client);
            // Query table to get first row and confirm it contains the expected value.
            var              newTable = _client.GetTable(datasetId, newTableId);
            string           query    = $"SELECT title, unique_words FROM {newTable}";
            BigqueryQueryJob results  = AsyncQuery(_projectId, datasetId, newTableId, query, _client);
            var              row      = results.GetRows().First();

            Assert.Equal(gcsUploadTestWord, row["title"]);
            DeleteTable(datasetId, newTableId, _client);
            DeleteDataset(datasetId, _client);
        }
コード例 #6
0
        public void TestImportDataFromFile()
        {
            string datasetId           = "datasetForTestImportDataFromFile";
            string newTableId          = "tableForTestImportDataFromFile";
            string uploadTestWord      = "additionalExampleJsonFromFile";
            long   uploadTestWordValue = 9814072356;
            string filePath            = "..\\..\\..\\test\\data\\sample.json";

            CreateDataset(datasetId, _client);
            CreateTable(datasetId, newTableId, _client);
            // Import data.
            UploadJsonFromFile(_projectId, datasetId, newTableId, filePath, _client);
            // Query table to get first row and confirm it contains the expected value
            var              newTable = _client.GetTable(datasetId, newTableId);
            string           query    = $"SELECT title, unique_words FROM {newTable} WHERE title = '{uploadTestWord}'";
            BigqueryQueryJob results  = AsyncQuery(_projectId, datasetId, newTableId, query, _client);
            var              row      = results.GetRows().Last();

            Assert.Equal(uploadTestWordValue, row["unique_words"]);
            DeleteTable(datasetId, newTableId, _client);
            DeleteDataset(datasetId, _client);
        }