[
https://issues.apache.org/jira/browse/BEAM-5121?focusedWorklogId=138459&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-138459
]
ASF GitHub Bot logged work on BEAM-5121:
----------------------------------------
Author: ASF GitHub Bot
Created on: 27/Aug/18 16:50
Start Date: 27/Aug/18 16:50
Worklog Time Spent: 10m
Work Description: akedin closed pull request #6246: [BEAM-5121] Test
complex types of Row and Array
URL: https://github.com/apache/beam/pull/6246
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamComplexTypeTest.java
b/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamComplexTypeTest.java
new file mode 100644
index 00000000000..c80fb51022e
--- /dev/null
+++
b/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamComplexTypeTest.java
@@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.extensions.sql;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.Arrays;
+import org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv;
+import org.apache.beam.sdk.extensions.sql.impl.rel.BeamSqlRelUtils;
+import org.apache.beam.sdk.extensions.sql.meta.provider.ReadOnlyTableProvider;
+import org.apache.beam.sdk.extensions.sql.mock.MockedBoundedTable;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.schemas.Schema.FieldType;
+import org.apache.beam.sdk.testing.PAssert;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.Row;
+import org.joda.time.Duration;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+
+/** Unit Tests for ComplexTypes, including nested ROW etc. */
+public class BeamComplexTypeTest {
+ private static final Schema innerRowSchema =
+ Schema.builder().addStringField("one").addInt64Field("two").build();
+
+ private static final Schema innerRowWithArraySchema =
+ Schema.builder().addStringField("one").addArrayField("array",
FieldType.INT64).build();
+
+ private static final Schema nestedRowWithArraySchema =
+ Schema.builder()
+ .addStringField("field1")
+ .addRowField("field2", innerRowWithArraySchema)
+ .addInt64Field("field3")
+ .addArrayField("field4", FieldType.array(FieldType.STRING))
+ .build();
+
+ private static final Schema nestedRowSchema =
+ Schema.builder()
+ .addStringField("nonRowfield1")
+ .addRowField("RowField", innerRowSchema)
+ .addInt64Field("nonRowfield2")
+ .addRowField("RowFieldTwo", innerRowSchema)
+ .build();
+
+ private static final Schema rowWithArraySchema =
+ Schema.builder()
+ .addStringField("field1")
+ .addInt64Field("field2")
+ .addArrayField("field3", FieldType.INT64)
+ .build();
+
+ private static final Schema flattenedRowSchema =
+ Schema.builder()
+ .addStringField("field1")
+ .addStringField("field2")
+ .addInt64Field("field3")
+ .addInt64Field("field4")
+ .addStringField("field5")
+ .addInt64Field("field6")
+ .build();
+
+ private static final ReadOnlyTableProvider readOnlyTableProvider =
+ new ReadOnlyTableProvider(
+ "test_provider",
+ ImmutableMap.of(
+ "arrayWithRowTestTable",
+
MockedBoundedTable.of(FieldType.array(FieldType.row(innerRowSchema)), "col")
+ .addRows(
+
Arrays.asList(Row.withSchema(innerRowSchema).addValues("str", 1L).build())),
+ "nestedArrayTestTable",
+
MockedBoundedTable.of(FieldType.array(FieldType.array(FieldType.INT64)), "col")
+ .addRows(Arrays.asList(Arrays.asList(1L, 2L, 3L),
Arrays.asList(4L, 5L))),
+ "nestedRowTestTable",
+ MockedBoundedTable.of(Schema.FieldType.row(nestedRowSchema),
"col")
+ .addRows(
+ Row.withSchema(nestedRowSchema)
+ .addValues(
+ "str",
+
Row.withSchema(innerRowSchema).addValues("inner_str_one", 1L).build(),
+ 2L,
+
Row.withSchema(innerRowSchema).addValues("inner_str_two", 3L).build())
+ .build()),
+ "basicRowTestTable",
+ MockedBoundedTable.of(Schema.FieldType.row(innerRowSchema),
"col")
+
.addRows(Row.withSchema(innerRowSchema).addValues("innerStr", 1L).build()),
+ "rowWithArrayTestTable",
+ MockedBoundedTable.of(Schema.FieldType.row(rowWithArraySchema),
"col")
+ .addRows(
+ Row.withSchema(rowWithArraySchema)
+ .addValues("str", 4L, Arrays.asList(5L, 6L))
+ .build())));
+
+ @Rule public transient TestPipeline pipeline = TestPipeline.create();
+
+ @Test
+ public void testNestedRow() {
+ BeamSqlEnv sqlEnv = BeamSqlEnv.inMemory(readOnlyTableProvider);
+ PCollection<Row> stream =
+ BeamSqlRelUtils.toPCollection(
+ pipeline, sqlEnv.parseQuery("SELECT nestedRowTestTable.col FROM
nestedRowTestTable"));
+ PAssert.that(stream)
+ .containsInAnyOrder(
+ Row.withSchema(flattenedRowSchema)
+ .addValues("str", "inner_str_one", 1L, 2L, "inner_str_two", 3L)
+ .build());
+ pipeline.run().waitUntilFinish(Duration.standardMinutes(2));
+ }
+
+ @Test
+ public void testArrayWithRow() {
+ BeamSqlEnv sqlEnv = BeamSqlEnv.inMemory(readOnlyTableProvider);
+ PCollection<Row> stream =
+ BeamSqlRelUtils.toPCollection(
+ pipeline,
+ sqlEnv.parseQuery("SELECT arrayWithRowTestTable.col[0] FROM
arrayWithRowTestTable"));
+ PAssert.that(stream)
+ .containsInAnyOrder(Row.withSchema(innerRowSchema).addValues("str",
1L).build());
+ pipeline.run().waitUntilFinish(Duration.standardMinutes(2));
+ }
+
+ @Test
+ public void testNestedArray() {
+ BeamSqlEnv sqlEnv = BeamSqlEnv.inMemory(readOnlyTableProvider);
+ PCollection<Row> stream =
+ BeamSqlRelUtils.toPCollection(
+ pipeline,
+ sqlEnv.parseQuery(
+ "SELECT nestedArrayTestTable.col[0][2],
nestedArrayTestTable.col[1][0] FROM nestedArrayTestTable"));
+ PAssert.that(stream)
+ .containsInAnyOrder(
+
Row.withSchema(Schema.builder().addInt64Field("field1").addInt64Field("field2").build())
+ .addValues(3L, 4L)
+ .build());
+ pipeline.run().waitUntilFinish(Duration.standardMinutes(2));
+ }
+
+ @Test
+ public void testBasicRow() {
+ BeamSqlEnv sqlEnv = BeamSqlEnv.inMemory(readOnlyTableProvider);
+ PCollection<Row> stream =
+ BeamSqlRelUtils.toPCollection(
+ pipeline, sqlEnv.parseQuery("SELECT col FROM basicRowTestTable"));
+ PAssert.that(stream)
+
.containsInAnyOrder(Row.withSchema(innerRowSchema).addValues("innerStr",
1L).build());
+ pipeline.run().waitUntilFinish(Duration.standardMinutes(2));
+ }
+
+ @Test
+ public void testRowWithArray() {
+ BeamSqlEnv sqlEnv = BeamSqlEnv.inMemory(readOnlyTableProvider);
+ PCollection<Row> stream =
+ BeamSqlRelUtils.toPCollection(
+ pipeline,
+ sqlEnv.parseQuery(
+ "SELECT rowWithArrayTestTable.col.field3[1] FROM
rowWithArrayTestTable"));
+ PAssert.that(stream)
+ .containsInAnyOrder(
+
Row.withSchema(Schema.builder().addInt64Field("int64").build()).addValue(6L).build());
+ pipeline.run().waitUntilFinish(Duration.standardMinutes(2));
+ }
+
+ @Ignore("https://issues.apache.org/jira/browse/BEAM-5189")
+ @Test
+ public void testFieldAccessToNestedRow() {
+ BeamSqlEnv sqlEnv = BeamSqlEnv.inMemory(readOnlyTableProvider);
+ PCollection<Row> stream =
+ BeamSqlRelUtils.toPCollection(
+ pipeline,
+ sqlEnv.parseQuery(
+ "SELECT nestedRowTestTable.col.RowField.one,
nestedRowTestTable.col.RowFieldTwo.two FROM nestedRowTestTable"));
+ PAssert.that(stream)
+ .containsInAnyOrder(
+ Row.withSchema(
+
Schema.builder().addStringField("field1").addInt64Field("field2").build())
+ .addValues("inner_str_one", 3L)
+ .build());
+ pipeline.run().waitUntilFinish(Duration.standardMinutes(2));
+ }
+}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 138459)
Time Spent: 1h 50m (was: 1h 40m)
> Investigate flattening issue of nested Row
> ------------------------------------------
>
> Key: BEAM-5121
> URL: https://issues.apache.org/jira/browse/BEAM-5121
> Project: Beam
> Issue Type: Sub-task
> Components: dsl-sql
> Reporter: Rui Wang
> Assignee: Rui Wang
> Priority: Major
> Time Spent: 1h 50m
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)