-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Reconcile schema nullability in BeamCoGBKJoinRel #38868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -325,6 +325,107 @@ private PCollection<Row> ordersUnbounded() { | |
| .buildUnbounded(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLeftOuterJoinWithNestedRows() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ran the test reverting BeamCoGBKJoinRel.java change it still passes
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, you're right - I think we don't actually need this backport after all, thanks |
||
| Schema nestedSchema = | ||
| Schema.builder().addInt32Field("nested_int").addStringField("nested_str").build(); | ||
| Schema lhsSchema = Schema.builder().addInt32Field("id").addStringField("val").build(); | ||
| Schema rhsSchema = | ||
| Schema.builder().addInt32Field("id").addRowField("nested", nestedSchema).build(); | ||
|
|
||
| PCollection<Row> lhs = | ||
| pipeline.apply( | ||
| "lhs", | ||
| org.apache.beam.sdk.transforms.Create.of( | ||
| Row.withSchema(lhsSchema).addValues(1, "lhs1").build(), | ||
| Row.withSchema(lhsSchema).addValues(2, "lhs2").build()) | ||
| .withRowSchema(lhsSchema)); | ||
|
|
||
| PCollection<Row> rhs = | ||
| pipeline.apply( | ||
| "rhs", | ||
| org.apache.beam.sdk.transforms.Create.of( | ||
| Row.withSchema(rhsSchema) | ||
| .addValues(1, Row.withSchema(nestedSchema).addValues(10, "nested1").build()) | ||
| .build()) | ||
| .withRowSchema(rhsSchema)); | ||
|
|
||
| String sql = | ||
| "SELECT lhs.id, lhs.val, rhs.nested FROM lhs LEFT OUTER JOIN rhs ON lhs.id = rhs.id"; | ||
|
|
||
| PCollection<Row> result = | ||
| PCollectionTuple.of("lhs", lhs).and("rhs", rhs).apply("sql", SqlTransform.query(sql)); | ||
|
|
||
| Schema expectedSchema = | ||
| Schema.builder() | ||
| .addInt32Field("id") | ||
| .addStringField("val") | ||
| .addNullableField("nested", Schema.FieldType.row(nestedSchema)) | ||
| .build(); | ||
|
|
||
| PAssert.that(result) | ||
| .containsInAnyOrder( | ||
| Row.withSchema(expectedSchema) | ||
| .addValues(1, "lhs1", Row.withSchema(nestedSchema).addValues(10, "nested1").build()) | ||
| .build(), | ||
| Row.withSchema(expectedSchema).addValues(2, "lhs2", null).build()); | ||
|
|
||
| pipeline.run(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLeftOuterJoinWithArrayOfNestedRows() { | ||
| Schema nestedSchema = | ||
| Schema.builder().addInt32Field("nested_int").addStringField("nested_str").build(); | ||
| Schema lhsSchema = Schema.builder().addInt32Field("id").addStringField("val").build(); | ||
| Schema rhsSchema = | ||
| Schema.builder() | ||
| .addInt32Field("id") | ||
| .addArrayField("nested_list", Schema.FieldType.row(nestedSchema)) | ||
| .build(); | ||
|
|
||
| PCollection<Row> lhs = | ||
| pipeline.apply( | ||
| "lhs", | ||
| org.apache.beam.sdk.transforms.Create.of( | ||
| Row.withSchema(lhsSchema).addValues(1, "lhs1").build(), | ||
| Row.withSchema(lhsSchema).addValues(2, "lhs2").build()) | ||
| .withRowSchema(lhsSchema)); | ||
|
|
||
| java.util.List<Row> nestedRows = | ||
| java.util.Arrays.asList( | ||
| Row.withSchema(nestedSchema).addValues(10, "nested1").build(), | ||
| Row.withSchema(nestedSchema).addValues(20, "nested2").build()); | ||
|
|
||
| PCollection<Row> rhs = | ||
| pipeline.apply( | ||
| "rhs", | ||
| org.apache.beam.sdk.transforms.Create.of( | ||
| Row.withSchema(rhsSchema).addValues(1, nestedRows).build()) | ||
| .withRowSchema(rhsSchema)); | ||
|
|
||
| String sql = | ||
| "SELECT lhs.id, lhs.val, rhs.nested_list FROM lhs LEFT OUTER JOIN rhs ON lhs.id = rhs.id"; | ||
|
|
||
| PCollection<Row> result = | ||
| PCollectionTuple.of("lhs", lhs).and("rhs", rhs).apply("sql", SqlTransform.query(sql)); | ||
|
|
||
| Schema expectedSchema = | ||
| Schema.builder() | ||
| .addInt32Field("id") | ||
| .addStringField("val") | ||
| .addNullableField( | ||
| "nested_list", Schema.FieldType.array(Schema.FieldType.row(nestedSchema))) | ||
| .build(); | ||
|
|
||
| PAssert.that(result) | ||
| .containsInAnyOrder( | ||
| Row.withSchema(expectedSchema).addValues(1, "lhs1", nestedRows).build(), | ||
| Row.withSchema(expectedSchema).addValues(2, "lhs2", null).build()); | ||
|
|
||
| pipeline.run(); | ||
| } | ||
|
|
||
| private PCollection<Row> queryFromOrderTables(String sql) { | ||
| return tuple( | ||
| "ORDER_DETAILS1", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To prevent an unexpected
IndexOutOfBoundsExceptionduring the loop, it is safer to defensively check that the field count ofcalciteSchemamatches the size ofdataFieldsbefore iterating.