use of org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode in project beam by apache.
the class ZetaSqlTimeFunctionsTest method testTimeColumn.
@Test
public void testTimeColumn() {
String sql = "SELECT FORMAT_TIME('%T', time_field) FROM table_with_time";
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql);
PCollection<Row> stream = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
PAssert.that(stream).containsInAnyOrder(Row.withSchema(Schema.builder().addStringField("f_time_str").build()).addValues("15:30:00").build(), Row.withSchema(Schema.builder().addStringField("f_time_str").build()).addValues("23:35:59").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 ZetaSqlTimeFunctionsTest method testDateTimeFromYearMonthDayHourMinuteSecond.
@Test
public void testDateTimeFromYearMonthDayHourMinuteSecond() {
String sql = "SELECT DATETIME(2008, 12, 25, 15, 30, 0)";
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql);
PCollection<Row> stream = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
PAssert.that(stream).containsInAnyOrder(Row.withSchema(Schema.builder().addLogicalTypeField("f_datetime", SqlTypes.DATETIME).build()).addValues(LocalDateTime.of(2008, 12, 25, 15, 30, 0)).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 ZetaSqlTimeFunctionsTest method testTimestampDiffNegativeResult.
@Test
public void testTimestampDiffNegativeResult() {
String sql = "SELECT TIMESTAMP_DIFF(TIMESTAMP '2018-08-14', TIMESTAMP '2018-10-14', DAY)";
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql);
PCollection<Row> stream = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
PAssert.that(stream).containsInAnyOrder(Row.withSchema(Schema.builder().addInt64Field("f_timestamp_diff").build()).addValues(-61L).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 ZetaSqlTimeFunctionsTest method testTimestampFromString.
@Test
public void testTimestampFromString() {
String sql = "SELECT TIMESTAMP('2008-12-25 15:30:00', 'America/Los_Angeles')";
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql);
PCollection<Row> stream = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
PAssert.that(stream).containsInAnyOrder(Row.withSchema(Schema.builder().addDateTimeField("f_timestamp").build()).addValues(parseTimestampWithTimeZone("2008-12-25 15:30:00-08")).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 ZetaSqlTimeFunctionsTest method testTimestampAddWithParameter2.
@Test
public void testTimestampAddWithParameter2() {
String sql = "SELECT TIMESTAMP_ADD(@p0, INTERVAL @p1 MINUTE)";
ImmutableMap<String, Value> params = ImmutableMap.of("p0", parseTimestampWithTZToValue("2008-12-25 15:30:00+07:30"), "p1", Value.createInt64Value(10L));
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql, params);
PCollection<Row> stream = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
final Schema schema = Schema.builder().addDateTimeField("field1").build();
PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues(parseTimestampWithTimeZone("2008-12-25 15:40:00+07:30")).build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
Aggregations