lourdu rajan
lourdu rajan

Reputation: 379

Build Nested structure using BeamSQL

In BigQuery we have "ARRAY_AGG" function which helps to convert the normal collection to Nested collection. Is there a similar way to build same kind of nested structure collection using BeamSQL?. Something like below query in BeamSQL,

"Select column1, ARRAY_AGG(STRUCT(column2, column3)) from PCOLLECTION Group by Column1"

Upvotes: 1

Views: 615

Answers (1)

Anton
Anton

Reputation: 2539

If I understood your question correctly, you should be able to use ARRAY constructor like "SELECT ARRAY[1, 2, 3] f_arr", this passes:

  @Test
  public void testArrayConstructor() {
    BeamSqlEnv sqlEnv = BeamSqlEnv.inMemory(readOnlyTableProvider);
    PCollection<Row> stream =
        BeamSqlRelUtils.toPCollection(pipeline, sqlEnv.parseQuery("SELECT ARRAY[1, 2, 3] f_arr"));
    PAssert.that(stream)
        .containsInAnyOrder(
            Row.withSchema(Schema.builder().addArrayField("f_arr", FieldType.INT32).build())
                .addValue(Arrays.asList(1, 2, 3))
                .build());
    pipeline.run().waitUntilFinish(Duration.standardMinutes(2));
  }

See also:

Upvotes: 1

Related Questions