use of org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode in project beam by apache.
the class ZetaSqlJavaUdfTest method testNullaryJavaUdf.
@Test
public void testNullaryJavaUdf() {
String sql = String.format("CREATE FUNCTION helloWorld() RETURNS STRING LANGUAGE java " + "OPTIONS (path='%s'); " + "SELECT helloWorld();", jarPath);
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql);
PCollection<Row> stream = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
Schema singleField = Schema.builder().addStringField("field1").build();
PAssert.that(stream).containsInAnyOrder(Row.withSchema(singleField).addValues("Hello world!").build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
use of org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode in project beam by apache.
the class ZetaSqlJavaUdfTest method testNullArgumentIsTypeChecked.
@Test
public void testNullArgumentIsTypeChecked() {
// The Java definition for isNull takes a String, but here we declare it in SQL with INT64.
String sql = String.format("CREATE FUNCTION isNull(i INT64) RETURNS INT64 LANGUAGE java " + "OPTIONS (path='%s'); " + "SELECT isNull(NULL);", jarPath);
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql);
// TODO(BEAM-11171) This should fail earlier, before compiling the CalcFn.
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("Could not compile CalcFn");
thrown.expectCause(allOf(isA(CompileException.class), hasProperty("message", containsString("No applicable constructor/method found for actual parameters \"java.lang.Long\""))));
BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
}
use of org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode in project beam by apache.
the class ZetaSqlJavaUdfTest method testFunctionSignatureTypeMismatchFailsPipelineConstruction.
@Test
public void testFunctionSignatureTypeMismatchFailsPipelineConstruction() {
// The Java definition for isNull takes a String, but here we pass it a Long.
String sql = String.format("CREATE FUNCTION isNull(i INT64) RETURNS BOOLEAN LANGUAGE java " + "OPTIONS (path='%s'); " + "SELECT isNull(0);", jarPath);
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql);
// TODO(BEAM-11171) This should fail earlier, before compiling the CalcFn.
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("Could not compile CalcFn");
thrown.expectCause(allOf(isA(CompileException.class), hasProperty("message", containsString("No applicable constructor/method found for actual parameters \"long\""))));
BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
}
use of org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode in project beam by apache.
the class ZetaSqlJavaUdfTest method testProjectUdfAndBuiltin.
@Test
public void testProjectUdfAndBuiltin() {
String sql = String.format("CREATE FUNCTION matches(str STRING, regStr STRING) RETURNS BOOLEAN LANGUAGE java OPTIONS (path='%s'); " + "SELECT matches(\"a\", \"a\"), 'apple'='beta'", jarPath);
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql);
PCollection<Row> stream = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
Schema schema = Schema.builder().addBooleanField("field1").addBooleanField("field2").build();
PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues(true, false).build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
use of org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode in project beam by apache.
the class ZetaSqlJavaUdfTest method testUnaryJavaUdf.
@Test
public void testUnaryJavaUdf() {
String sql = String.format("CREATE FUNCTION increment(i INT64) RETURNS INT64 LANGUAGE java " + "OPTIONS (path='%s'); " + "SELECT increment(1);", jarPath);
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql);
PCollection<Row> stream = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
Schema singleField = Schema.builder().addInt64Field("field1").build();
PAssert.that(stream).containsInAnyOrder(Row.withSchema(singleField).addValues(2L).build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
Aggregations