Esempio n. 1
0
        public void GetTable_PartialSchema_ComplexTypes()
        {
            var    client    = BigQueryClient.Create(_fixture.ProjectId);
            string datasetId = _fixture.DatasetId;
            string tableId   = _fixture.PeopleTableId;
            var    options   = new GetTableOptions
            {
                SelectedFields = "age,gender,phoneNumber,children.gender,children.age"
            };
            var table = client.GetTable(datasetId, tableId, options);

            // We still have 4 top level fields because nesting is preserved
            // when requesting a partial table schema.
            Assert.Equal(4, table.Schema.Fields.Count);

            Assert.Equal("age", table.Schema.Fields[0].Name);
            Assert.Equal("gender", table.Schema.Fields[1].Name);

            Assert.Equal("phoneNumber", table.Schema.Fields[2].Name);
            Assert.Equal(2, table.Schema.Fields[2].Fields.Count);
            Assert.Equal("areaCode", table.Schema.Fields[2].Fields[0].Name);
            Assert.Equal("number", table.Schema.Fields[2].Fields[1].Name);

            Assert.Equal("children", table.Schema.Fields[3].Name);
            Assert.Equal(2, table.Schema.Fields[3].Fields.Count);
            Assert.Equal("gender", table.Schema.Fields[3].Fields[0].Name);
            Assert.Equal("age", table.Schema.Fields[3].Fields[1].Name);
        }
Esempio n. 2
0
 /// <summary>
 /// Retrieves an SNMP table from an agent.
 /// </summary>
 /// <param name="snmp">The SNMP session object to use.</param>
 /// <param name="pdu">The PDU object used to convey the request type
 /// and some security parameters (variable bindings are ignored; may
 /// be an empty array).</param>
 /// <param name="target">The SNMP target.</param>
 /// <param name="columnOids">The OIDs of table columns to retrieve. The
 /// columns should share table indexes  (e.g., be a part of the same or
 /// AUGMENTed table).</param>
 /// <param name="options">The options for the operation.</param>
 /// <param name="nRequests">Will be incremented every time a response
 /// is received.</param>
 /// <returns>The retrieved rows. Due to performance reasons, the rows
 /// are returned as a jagged array  but the array is guaranteed to be
 /// rectangular.  It contains either valid variable bindings or <b>null</b>
 /// values for table "holes".</returns>
 /// <remarks>This method returns table rows for the specified set of
 /// columns. A typical example includes the retrieval of a complete
 /// table but a number of parameters makes this method more flexible.
 /// For more information on internal behavior, see the
 /// <see cref="TableReader.UseAsyncInvoke"/> property.</remarks>
 public static Vb[][] GetTable(Snmp snmp, Pdu pdu, SnmpTarget target,
                               Oid[] columnOids, GetTableOptions options, ref int nRequests)
 {
     return(GetTable(snmp, pdu, target, columnOids,
                     options.startRowIndex, options.endRowIndex,
                     options.maxRows, options.rowsPerQuery, ref nRequests));
 }
        public void ModifyRequest_NoOp()
        {
            var request = new GetRequest(null, "project", "dataset", "table");
            var options = new GetTableOptions();

            options.ModifyRequest(request);
        }
Esempio n. 4
0
 /// <summary>
 /// Starts an asynchronous SNMP table retrieval operation.
 /// </summary>
 /// <param name="snmp">The SNMP session object to use.</param>
 /// <param name="pdu">The PDU object used to convey the request type
 /// and some security parameters (variable bindings are ignored; may
 /// be an empty array).</param>
 /// <param name="target">The SNMP target.</param>
 /// <param name="columnOids">The OIDs of table columns to retrieve. The
 /// columns should share table indexes  (e.g., be a part of the same or
 /// AUGMENTed table).</param>
 /// <param name="options">The options for the operation.</param>
 /// <param name="callback">Callback method to invoke when a table is read
 /// or <b>null</b>.</param>
 /// <param name="callbackData">User state.</param>
 /// <returns><see cref="IAsyncResult"/> object.</returns>
 /// <remarks>
 /// This method starts asynchronous table retrieval for the specified set
 /// of columns. A typical example includes the retrieval of a whole table
 /// but a number of parameters makes this method more flexible.  In order
 /// to complete the operation and free related resources, <see cref="EndGetTable"/>
 /// must be later called,  usually, in the callback method specified
 /// by <b>callback</b> parameter.
 /// </remarks>
 public static IAsyncResult BeginGetTable(Snmp snmp, Pdu pdu, SnmpTarget target,
                                          Oid[] columnOids, GetTableOptions options,
                                          AsyncCallback callback, object callbackData)
 {
     return(BeginGetTable(snmp, pdu, target, columnOids,
                          options.startRowIndex, options.endRowIndex,
                          options.maxRows, options.rowsPerQuery, callback, callbackData));
 }
        public void ModifyRequest_NoOp()
        {
            var request = new GetRequest(null, "project", "dataset", "table");
            var options = new GetTableOptions();

            options.ModifyRequest(request);

            Assert.Null(request.SelectedFields);
        }
        public void ModifyRequest()
        {
            var request = new GetRequest(null, "project", "dataset", "table");
            var options = new GetTableOptions
            {
                SelectedFields = "a,b,c"
            };

            options.ModifyRequest(request);

            Assert.Equal("a,b,c", request.SelectedFields);
        }
Esempio n. 7
0
        public void GetTableEquivalents()
        {
            var datasetId = "dataset";
            var tableId   = "table";
            var reference = GetTableReference(datasetId, tableId);
            var options   = new GetTableOptions();

            VerifyEquivalent(new BigQueryTable(new DerivedBigQueryClient(), GetTable(reference)),
                             client => client.GetTable(MatchesWhenSerialized(reference), options),
                             client => client.GetTable(datasetId, tableId, options),
                             client => client.GetTable(ProjectId, datasetId, tableId, options),
                             client => new BigQueryDataset(client, GetDataset(datasetId)).GetTable(tableId, options));
        }
Esempio n. 8
0
        public void GetTable_FullSchema(GetTableOptions options)
        {
            var    client    = BigQueryClient.Create(_fixture.ProjectId);
            string datasetId = _fixture.DatasetId;
            string tableId   = _fixture.HighScoreExtendedTableId;

            var table = client.GetTable(datasetId, tableId, options);

            Assert.Equal(4, table.Schema.Fields.Count);
            Assert.Equal("player", table.Schema.Fields[0].Name);
            Assert.Equal("gameStarted", table.Schema.Fields[1].Name);
            Assert.Equal("score", table.Schema.Fields[2].Name);
            Assert.Equal("gameFinished", table.Schema.Fields[3].Name);
        }
Esempio n. 9
0
        public void GetTableAsyncEquivalents()
        {
            var datasetId = "dataset";
            var tableId   = "table";
            var reference = GetTableReference(datasetId, tableId);
            var options   = new GetTableOptions();
            var token     = new CancellationTokenSource().Token;

            VerifyEquivalentAsync(new BigQueryTable(new DerivedBigQueryClient(), GetTable(reference)),
                                  client => client.GetTableAsync(MatchesWhenSerialized(reference), options, token),
                                  client => client.GetTableAsync(datasetId, tableId, options, token),
                                  client => client.GetTableAsync(ProjectId, datasetId, tableId, options, token),
                                  client => new BigQueryDataset(client, GetDataset(datasetId)).GetTableAsync(tableId, options, token));
        }
Esempio n. 10
0
        public void GetTable_PartialSchema_SimpleTypes()
        {
            var    client    = BigQueryClient.Create(_fixture.ProjectId);
            string datasetId = _fixture.DatasetId;
            string tableId   = _fixture.HighScoreExtendedTableId;
            var    options   = new GetTableOptions
            {
                SelectedFields = "player,score"
            };
            var table = client.GetTable(datasetId, tableId, options);

            Assert.Equal(2, table.Schema.Fields.Count);
            Assert.Equal("player", table.Schema.Fields[0].Name);
            Assert.Equal("score", table.Schema.Fields[1].Name);
        }
Esempio n. 11
0
        public void GetOrCreateTableEquivalents()
        {
            var datasetId     = "dataset";
            var tableId       = "table";
            var schema        = new TableSchemaBuilder().Build();
            var reference     = GetTableReference(datasetId, tableId);
            var getOptions    = new GetTableOptions();
            var createOptions = new CreateTableOptions();

            VerifyEquivalent(new BigQueryTable(new DerivedBigQueryClient(), GetTable(reference)),
                             client => client.GetOrCreateTable(MatchesWhenSerialized(reference), schema, getOptions, createOptions),
                             client => client.GetOrCreateTable(datasetId, tableId, schema, getOptions, createOptions),
                             client => client.GetOrCreateTable(ProjectId, datasetId, tableId, schema, getOptions, createOptions),
                             client => new BigQueryDataset(client, GetDataset(datasetId)).GetOrCreateTable(tableId, schema, getOptions, createOptions));
        }
Esempio n. 12
0
        public void GetOrCreateTableAsyncEquivalents()
        {
            var datasetId     = "dataset";
            var tableId       = "table";
            var schema        = new TableSchemaBuilder().Build();
            var reference     = GetTableReference(datasetId, tableId);
            var getOptions    = new GetTableOptions();
            var createOptions = new CreateTableOptions();
            var token         = new CancellationTokenSource().Token;

            VerifyEquivalentAsync(new BigqueryTable(new DerivedBigqueryClient(), GetTable(reference)),
                                  client => client.GetOrCreateTableAsync(MatchesWhenSerialized(reference), schema, getOptions, createOptions, token),
                                  client => client.GetOrCreateTableAsync(datasetId, tableId, schema, getOptions, createOptions, token),
                                  client => client.GetOrCreateTableAsync(ProjectId, datasetId, tableId, schema, getOptions, createOptions, token),
                                  client => new BigqueryDataset(client, GetDataset(datasetId)).GetOrCreateTableAsync(tableId, schema, getOptions, createOptions, token));
        }
Esempio n. 13
0
        public void GetTable_PartialSchema_SimpleTypes_Ordered()
        {
            var    client    = BigQueryClient.Create(_fixture.ProjectId);
            string datasetId = _fixture.DatasetId;
            string tableId   = _fixture.HighScoreExtendedTableId;
            var    options   = new GetTableOptions
            {
                // Specify selected fields in a different order
                // to the one they were created in.
                SelectedFields = "score,player"
            };
            var table = client.GetTable(datasetId, tableId, options);

            Assert.Equal(2, table.Schema.Fields.Count);
            // The schema still contains the fields in the same order
            // as the one they were created in.
            Assert.Equal("player", table.Schema.Fields[0].Name);
            Assert.Equal("score", table.Schema.Fields[1].Name);
        }
Esempio n. 14
0
        public async Task ListRows_PartialSchema()
        {
            var    client    = BigQueryClient.Create(_fixture.ProjectId);
            string datasetId = _fixture.DatasetId;
            string tableId   = _fixture.PeopleTableId;
            var    options   = new GetTableOptions
            {
                SelectedFields = "age,gender,children.gender,children.age"
            };

            // Obtain the table's partial schema.
            var table = client.GetTable(datasetId, tableId, options);
            // Use the partial schema to obtain partial rows.
            // We are testing both the sync and async versions.
            var rowsAsync = client.ListRowsAsync(datasetId, tableId, table.Schema);
            var rows      = client.ListRows(datasetId, tableId, table.Schema);
            // Make sure we grab a row of a person with children for testing fields that should be present.
            var rowAsyncTask = rowsAsync.FirstAsync(row => ((Dictionary <string, object>[])row["children"])?.Length > 0);
            var rowSync      = rows.First(row => ((Dictionary <string, object>[])row["children"])?.Length > 0);
            var rowAsync     = await rowAsyncTask.ConfigureAwait(false);

            AssertPartialRow(rowSync);
            AssertPartialRow(rowAsync);

            void AssertPartialRow(BigQueryRow row)
            {
                // These should be present
                Assert.NotNull(row["age"]);
                Assert.NotNull(row["gender"]);
                var children = row["children"] as Dictionary <string, object>[];

                Assert.NotNull(children);
                Assert.NotNull(children[0]["gender"]);
                Assert.NotNull(children[0]["age"]);
                // These shouldn't
                Assert.Throws <KeyNotFoundException>(() => row["fullName"]);
                Assert.Throws <KeyNotFoundException>(() => children[0]["name"]);
            }
        }