use of org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode in project beam by apache.
the class ZetaSqlTimeFunctionsTest method testDateTimeSub.
@Test
public void testDateTimeSub() {
String sql = "SELECT " + "DATETIME_SUB(DATETIME '2008-12-25 15:30:00', INTERVAL 10 MICROSECOND), " + "DATETIME_SUB(DATETIME '2008-12-25 15:30:00', INTERVAL 10 MILLISECOND), " + "DATETIME_SUB(DATETIME '2008-12-25 15:30:00', INTERVAL 10 SECOND), " + "DATETIME_SUB(DATETIME '2008-12-25 15:30:00', INTERVAL 10 MINUTE), " + "DATETIME_SUB(DATETIME '2008-12-25 15:30:00', INTERVAL 10 HOUR), " + "DATETIME_SUB(DATETIME '2008-12-25 15:30:00', INTERVAL 10 DAY), " + "DATETIME_SUB(DATETIME '2008-12-25 15:30:00', INTERVAL 10 MONTH), " + "DATETIME_SUB(DATETIME '2008-12-25 15:30:00', INTERVAL 10 QUARTER), " + "DATETIME_SUB(DATETIME '2008-12-25 15:30:00', INTERVAL 10 YEAR) ";
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_time1", SqlTypes.DATETIME).addLogicalTypeField("f_time2", SqlTypes.DATETIME).addLogicalTypeField("f_time3", SqlTypes.DATETIME).addLogicalTypeField("f_time4", SqlTypes.DATETIME).addLogicalTypeField("f_time5", SqlTypes.DATETIME).addLogicalTypeField("f_time6", SqlTypes.DATETIME).addLogicalTypeField("f_time7", SqlTypes.DATETIME).addLogicalTypeField("f_time8", SqlTypes.DATETIME).addLogicalTypeField("f_time9", SqlTypes.DATETIME).build()).addValues(LocalDateTime.of(2008, 12, 25, 15, 29, 59).withNano(999990000), LocalDateTime.of(2008, 12, 25, 15, 29, 59).withNano(990000000), LocalDateTime.of(2008, 12, 25, 15, 29, 50), LocalDateTime.of(2008, 12, 25, 15, 20, 0), LocalDateTime.of(2008, 12, 25, 5, 30, 0), LocalDateTime.of(2008, 12, 15, 15, 30, 0), LocalDateTime.of(2008, 2, 25, 15, 30, 0), LocalDateTime.of(2006, 6, 25, 15, 30, 0), LocalDateTime.of(1998, 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 testTimestampFromUnixInt64.
@Test
public void testTimestampFromUnixInt64() {
String sql = "SELECT " + "TIMESTAMP_FROM_UNIX_SECONDS(1230219000), " + "TIMESTAMP_FROM_UNIX_MILLIS(1230219000123) ";
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_seconds").addDateTimeField("f_timestamp_millis").build()).addValues(DateTimeUtils.parseTimestampWithUTCTimeZone("2008-12-25 15:30:00"), DateTimeUtils.parseTimestampWithUTCTimeZone("2008-12-25 15:30:00.123")).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 testParseDateTime.
@Test
public void testParseDateTime() {
String sql = "SELECT PARSE_DATETIME('%Y-%m-%d %H:%M:%E6S', '2008-12-25 15:30:00.123456')";
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).withNano(123456000)).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 testAggregateOnTime.
@Test
public void testAggregateOnTime() {
String sql = "SELECT MAX(time_field) FROM table_with_time GROUP BY str_field";
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("time_field", SqlTypes.TIME).build()).addValues(LocalTime.of(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 testFormatDateTime.
@Test
public void testFormatDateTime() {
String sql = "SELECT FORMAT_DATETIME('%D %T %E6S', DATETIME '2008-12-25 15:30:00.123456')";
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_datetime_str").build()).addValues("12/25/08 15:30:00 00.123456").build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
Aggregations