Skip to content

Publish Array of Structure Code sample #2171

@prash-mi

Description

@prash-mi

Publish Array of Structure Code sample on the lines of below

   public static void queryWithArrayOfStructsNamedParams() {
      try {
         // Initialize client that will be used to send requests. This client only needs to be created
         // once, and can be reused for multiple requests.
         BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();

         // Create struct and add it to the list
         Map<String, QueryParameterValue> structMap = new HashMap<>();
         structMap.put("stringField", QueryParameterValue.string("test-stringField"));
         QueryParameterValue structQueryParam = QueryParameterValue.struct(structMap);
         List<QueryParameterValue> aryOfStruct = new ArrayList<>();
         aryOfStruct.add(structQueryParam);

         String query = "SELECT (@arrayOfStructField) AS record";
         QueryJobConfiguration queryConfig =
             QueryJobConfiguration.newBuilder(query)
                 .setUseLegacySql(false)
                 .addNamedParameter("arrayOfStructField", QueryParameterValue.array(aryOfStruct.toArray(), StandardSQLTypeName.STRING))
                 .build();
         TableResult results = bigquery.query(queryConfig);
         results
             .iterateAll()
             .forEach(row -> row.forEach(val -> System.out.printf("%s", val.toString())));
         System.out.println("Query with Array of struct parameter performed successfully.");
      } catch (BigQueryException | InterruptedException e) {
         System.out.println("Query not performed \n" + e);
      }
   }

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the googleapis/java-bigquery API.priority: p2Moderately-important priority. Fix may not be included in next release.samplesIssues that are directly related to samples.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions