use of org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode in project beam by apache.
the class CalciteQueryPlannerTest method testNonCumulativeCostMetadataHandler.
@Test
public void testNonCumulativeCostMetadataHandler() {
String sql = "select * from medium_table";
BeamRelNode root = env.parseQuery(sql);
Assert.assertTrue(root.getCluster().getMetadataQuery().getNonCumulativeCost(root) instanceof BeamCostModel);
Assert.assertFalse(root.getCluster().getMetadataQuery().getNonCumulativeCost(root).isInfinite());
}
use of org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode in project beam by apache.
the class CalciteQueryPlannerTest method testCumulativeCostMetaDataHandler.
@Test
public void testCumulativeCostMetaDataHandler() {
// This handler is not our handler. It tests if the cumulative handler of Calcite works as
// expected.
String sql = "select * from medium_table";
BeamRelNode root = env.parseQuery(sql);
Assert.assertTrue(root.getCluster().getMetadataQuery().getCumulativeCost(root) instanceof BeamCostModel);
Assert.assertFalse(root.getCluster().getMetadataQuery().getCumulativeCost(root).isInfinite());
}
use of org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode in project beam by apache.
the class IOPushDownRuleTest method testIsProjectRenameOnlyProgram.
@Test
public void testIsProjectRenameOnlyProgram() {
List<Pair<Pair<String, Boolean>, Boolean>> tests = ImmutableList.of(// Selecting fields in a different order is only allowed with project push-down.
Pair.of(Pair.of("select unused2, name, id from TEST", true), true), Pair.of(Pair.of("select unused2, name, id from TEST", false), false), Pair.of(Pair.of("select id from TEST", false), true), Pair.of(Pair.of("select * from TEST", false), true), Pair.of(Pair.of("select id, name from TEST", false), true), Pair.of(Pair.of("select id+10 from TEST", false), false), // Note that we only care about projects.
Pair.of(Pair.of("select id from TEST where name='one'", false), true));
for (Pair<Pair<String, Boolean>, Boolean> test : tests) {
String sqlQuery = test.left.left;
boolean projectPushDownSupported = test.left.right;
boolean expectedAnswer = test.right;
BeamRelNode basicRel = sqlEnv.parseQuery(sqlQuery);
assertThat(basicRel, instanceOf(Calc.class));
Calc calc = (Calc) basicRel;
assertThat(test.toString(), BeamIOPushDownRule.INSTANCE.isProjectRenameOnlyProgram(calc.getProgram(), projectPushDownSupported), equalTo(expectedAnswer));
}
}
use of org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode in project beam by apache.
the class ZetaSqlJavaUdfTest method testNestedJavaUdf.
@Test
public void testNestedJavaUdf() {
String sql = String.format("CREATE FUNCTION increment(i INT64) RETURNS INT64 LANGUAGE java " + "OPTIONS (path='%s'); " + "SELECT increment(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(3L).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 testUdfFromCatalog.
/**
* This tests a subset of the code path used by {@link #testSqlTransformRegisterUdf()}.
*/
@Test
public void testUdfFromCatalog() throws NoSuchMethodException {
// Add IncrementFn to Calcite schema.
JdbcConnection jdbcConnection = JdbcDriver.connect(new ReadOnlyTableProvider("empty_table_provider", ImmutableMap.of()), PipelineOptionsFactory.create());
Method method = IncrementFn.class.getMethod("eval", Long.class);
jdbcConnection.getCurrentSchemaPlus().add("increment", ScalarFunctionImpl.create(method));
this.config = Frameworks.newConfigBuilder(config).defaultSchema(jdbcConnection.getCurrentSchemaPlus()).build();
String sql = "SELECT increment(0);";
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql);
PCollection<Row> stream = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
final Schema schema = Schema.builder().addInt64Field("field1").build();
PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues(1L).build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
Aggregations