Search in sources :

Example 61 with Row

use of org.apache.beam.sdk.values.Row in project beam by apache.

the class SchemaIOTableProviderWrapperTest method testBuildIOReader.

@Test
public void testBuildIOReader() {
    TestSchemaIOTableProviderWrapper provider = new TestSchemaIOTableProviderWrapper();
    BeamSqlTable beamSqlTable = provider.buildBeamSqlTable(testTable);
    PCollection<Row> result = beamSqlTable.buildIOReader(pipeline.begin());
    PAssert.that(result).containsInAnyOrder(rows);
    pipeline.run();
}
Also used : BeamSqlTable(org.apache.beam.sdk.extensions.sql.meta.BeamSqlTable) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 62 with Row

use of org.apache.beam.sdk.values.Row in project beam by apache.

the class BeamSalUhfSpecialTypeAndValueTest method testSHA1.

@Test
public void testSHA1() throws Exception {
    Schema resultType = Schema.builder().addByteArrayField("field").build();
    Row resultRow1 = Row.withSchema(resultType).addValues(DigestUtils.sha1("foobar".getBytes(UTF_8))).build();
    Row resultRow2 = Row.withSchema(resultType).addValues(DigestUtils.sha1(" ".getBytes(UTF_8))).build();
    Row resultRow3 = Row.withSchema(resultType).addValues(DigestUtils.sha1("abcABCжщфЖЩФ".getBytes(UTF_8))).build();
    String sql = "SELECT SHA1(f_bytes) FROM PCOLLECTION WHERE f_func = 'HashingFn'";
    PCollection<Row> result = boundedInputBytes.apply("testUdf", SqlTransform.query(sql));
    PAssert.that(result).containsInAnyOrder(resultRow1, resultRow2, resultRow3);
    pipeline.run().waitUntilFinish();
}
Also used : Schema(org.apache.beam.sdk.schemas.Schema) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 63 with Row

use of org.apache.beam.sdk.values.Row in project beam by apache.

the class BeamSalUhfSpecialTypeAndValueTest method testLeftPad.

@Test
public void testLeftPad() throws Exception {
    Schema resultType = Schema.builder().addNullableField("field", FieldType.BYTES).build();
    Row resultRow = Row.withSchema(resultType).addValue("".getBytes(UTF_8)).build();
    Row resultRow2 = Row.withSchema(resultType).addValue("abcdef".getBytes(UTF_8)).build();
    Row resultRow3 = Row.withSchema(resultType).addValue("abcd".getBytes(UTF_8)).build();
    Row resultRow4 = Row.withSchema(resultType).addValue("defgabcdef".getBytes(UTF_8)).build();
    Row resultRow5 = Row.withSchema(resultType).addValue("defghdeabc".getBytes(UTF_8)).build();
    Row resultRow6 = Row.withSchema(resultType).addValue("----abc".getBytes(UTF_8)).build();
    Row resultRow7 = Row.withSchema(resultType).addValue("defdefd".getBytes(UTF_8)).build();
    Row resultRow8 = Row.withSchema(resultType).addValue(null).build();
    String sql = "SELECT LPAD(f_bytes_one, length, f_bytes_two) FROM PCOLLECTION";
    PCollection<Row> result = boundedInputBytesPaddingTest.apply("testUdf", SqlTransform.query(sql));
    PAssert.that(result).containsInAnyOrder(resultRow, resultRow2, resultRow3, resultRow4, resultRow5, resultRow6, resultRow7, resultRow8);
    pipeline.run().waitUntilFinish();
}
Also used : Schema(org.apache.beam.sdk.schemas.Schema) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 64 with Row

use of org.apache.beam.sdk.values.Row in project beam by apache.

the class BeamSalUhfSpecialTypeAndValueTest method testSHA256.

@Test
public void testSHA256() throws Exception {
    Schema resultType = Schema.builder().addByteArrayField("field").build();
    Row resultRow1 = Row.withSchema(resultType).addValues(DigestUtils.sha256("foobar".getBytes(UTF_8))).build();
    Row resultRow2 = Row.withSchema(resultType).addValues(DigestUtils.sha256(" ".getBytes(UTF_8))).build();
    Row resultRow3 = Row.withSchema(resultType).addValues(DigestUtils.sha256("abcABCжщфЖЩФ".getBytes(UTF_8))).build();
    String sql = "SELECT SHA256(f_bytes) FROM PCOLLECTION WHERE f_func = 'HashingFn'";
    PCollection<Row> result = boundedInputBytes.apply("testUdf", SqlTransform.query(sql));
    PAssert.that(result).containsInAnyOrder(resultRow1, resultRow2, resultRow3);
    pipeline.run().waitUntilFinish();
}
Also used : Schema(org.apache.beam.sdk.schemas.Schema) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 65 with Row

use of org.apache.beam.sdk.values.Row in project beam by apache.

the class SchemaUtilTest method testBeamRowMapperArray.

@Test
public void testBeamRowMapperArray() throws Exception {
    ResultSet mockArrayElementsResultSet = mock(ResultSet.class);
    when(mockArrayElementsResultSet.next()).thenReturn(true, true, true, false);
    when(mockArrayElementsResultSet.getInt(eq(1))).thenReturn(10, 20, 30);
    Array mockArray = mock(Array.class);
    when(mockArray.getResultSet()).thenReturn(mockArrayElementsResultSet);
    ResultSet mockResultSet = mock(ResultSet.class);
    when(mockResultSet.getArray(eq(1))).thenReturn(mockArray);
    Schema wantSchema = Schema.builder().addField("array", Schema.FieldType.array(Schema.FieldType.INT32)).build();
    Row wantRow = Row.withSchema(wantSchema).addValues((Object) ImmutableList.of(10, 20, 30)).build();
    SchemaUtil.BeamRowMapper beamRowMapper = SchemaUtil.BeamRowMapper.of(wantSchema);
    Row haveRow = beamRowMapper.mapRow(mockResultSet);
    assertEquals(wantRow, haveRow);
}
Also used : Array(java.sql.Array) Schema(org.apache.beam.sdk.schemas.Schema) ResultSet(java.sql.ResultSet) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Aggregations

Row (org.apache.beam.sdk.values.Row)958 Test (org.junit.Test)879 Schema (org.apache.beam.sdk.schemas.Schema)566 ByteString (com.google.protobuf.ByteString)219 BeamRelNode (org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode)206 Matchers.containsString (org.hamcrest.Matchers.containsString)85 Category (org.junit.experimental.categories.Category)72 Value (com.google.zetasql.Value)66 List (java.util.List)49 FieldAccessDescriptor (org.apache.beam.sdk.schemas.FieldAccessDescriptor)49 DateTime (org.joda.time.DateTime)46 UsesSchema (org.apache.beam.sdk.testing.UsesSchema)43 DefaultSchema (org.apache.beam.sdk.schemas.annotations.DefaultSchema)36 PCollection (org.apache.beam.sdk.values.PCollection)36 BeamSqlEnv (org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv)35 FieldType (org.apache.beam.sdk.schemas.Schema.FieldType)33 ArrayList (java.util.ArrayList)29 BeamIOSourceRel (org.apache.beam.sdk.extensions.sql.impl.rel.BeamIOSourceRel)28 ImmutableList (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList)28 Ignore (org.junit.Ignore)27