use of org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode in project beam by apache.
the class ZetaSqlTimeFunctionsTest method testDateFromDateTime.
@Test
public void testDateFromDateTime() {
String sql = "SELECT DATE(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().addLogicalTypeField("f_date", SqlTypes.DATE).build()).addValues(LocalDate.of(2008, 12, 25)).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 testDateTimeAdd.
@Test
public void testDateTimeAdd() {
String sql = "SELECT " + "DATETIME_ADD(DATETIME '2008-12-25 15:30:00', INTERVAL 10 MICROSECOND), " + "DATETIME_ADD(DATETIME '2008-12-25 15:30:00', INTERVAL 10 MILLISECOND), " + "DATETIME_ADD(DATETIME '2008-12-25 15:30:00', INTERVAL 10 SECOND), " + "DATETIME_ADD(DATETIME '2008-12-25 15:30:00', INTERVAL 10 MINUTE), " + "DATETIME_ADD(DATETIME '2008-12-25 15:30:00', INTERVAL 10 HOUR), " + "DATETIME_ADD(DATETIME '2008-12-25 15:30:00', INTERVAL 10 DAY), " + "DATETIME_ADD(DATETIME '2008-12-25 15:30:00', INTERVAL 10 MONTH), " + "DATETIME_ADD(DATETIME '2008-12-25 15:30:00', INTERVAL 10 QUARTER), " + "DATETIME_ADD(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, 30, 0).withNano(10000), LocalDateTime.of(2008, 12, 25, 15, 30, 0).withNano(10000000), LocalDateTime.of(2008, 12, 25, 15, 30, 10), LocalDateTime.of(2008, 12, 25, 15, 40, 0), LocalDateTime.of(2008, 12, 26, 1, 30, 0), LocalDateTime.of(2009, 1, 4, 15, 30, 0), LocalDateTime.of(2009, 10, 25, 15, 30, 0), LocalDateTime.of(2011, 6, 25, 15, 30, 0), LocalDateTime.of(2018, 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 testDateTimeDiffNegativeResult.
@Test
public void testDateTimeDiffNegativeResult() {
String sql = "SELECT DATETIME_DIFF(DATETIME '2008-10-25 15:30:00', DATETIME '2008-12-25 15:30:00', 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_datetime_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 testTimestampFromDateWithDefaultTimezoneSet.
@Test
public // test default timezone works properly in query execution stage
void testTimestampFromDateWithDefaultTimezoneSet() {
String sql = "SELECT TIMESTAMP(DATE '2014-01-31')";
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
zetaSQLQueryPlanner.setDefaultTimezone("Asia/Shanghai");
pipeline.getOptions().as(BeamSqlPipelineOptions.class).setZetaSqlDefaultTimezone("Asia/Shanghai");
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("2014-01-31 00:00: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 testTimestampSub.
@Test
public void testTimestampSub() {
String sql = "SELECT " + "TIMESTAMP_SUB(TIMESTAMP '2008-12-25 15:30:00 UTC', INTERVAL 5+5 MINUTE), " + "TIMESTAMP_SUB(TIMESTAMP '2008-12-25 15:30:00+07:30', INTERVAL 10 MINUTE)";
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_sub").addDateTimeField("f_timestamp_with_time_zone_sub").build()).addValues(DateTimeUtils.parseTimestampWithUTCTimeZone("2008-12-25 15:20:00"), parseTimestampWithTimeZone("2008-12-25 15:20:00+0730")).build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
Aggregations