use of org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode in project beam by apache.
the class ZetaSqlTimeFunctionsTest method testTimestampLiteralWithUTCTimeZone.
@Test
public void testTimestampLiteralWithUTCTimeZone() {
String sql = "SELECT TIMESTAMP '2016-12-25 05:30:00+00'";
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("field1").build()).addValues(parseTimestampWithUTCTimeZone("2016-12-25 05:30:00")).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 testExtractDateTimeFromTimestamp.
@Test
public void testExtractDateTimeFromTimestamp() {
String sql = "SELECT EXTRACT(DATETIME FROM TIMESTAMP '2017-05-26 12:34:56')";
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("datetime", SqlTypes.DATETIME).build()).addValues(LocalDateTime.of(2017, 5, 26, 12, 34, 56)).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 testExtractFromDateTime.
// TODO[BEAM-9166]: Add a test for CURRENT_DATETIME function ("SELECT CURRENT_DATETIME()")
@Test
public void testExtractFromDateTime() {
String sql = "SELECT " + "EXTRACT(YEAR FROM DATETIME '2008-12-25 15:30:00') as year, " + "EXTRACT(QUARTER FROM DATETIME '2008-12-25 15:30:00') as quarter, " + "EXTRACT(MONTH FROM DATETIME '2008-12-25 15:30:00') as month, " + // + "EXTRACT(WEEK FROM DATETIME '2008-12-25 15:30:00') as week, "
"EXTRACT(DAY FROM DATETIME '2008-12-25 15:30:00') as day, " + "EXTRACT(DAYOFWEEK FROM DATETIME '2008-12-25 15:30:00') as dayofweek, " + "EXTRACT(DAYOFYEAR FROM DATETIME '2008-12-25 15:30:00') as dayofyear, " + "EXTRACT(HOUR FROM DATETIME '2008-12-25 15:30:00.123456') as hour, " + "EXTRACT(MINUTE FROM DATETIME '2008-12-25 15:30:00.123456') as minute, " + "EXTRACT(SECOND FROM DATETIME '2008-12-25 15:30:00.123456') as second, " + "EXTRACT(MILLISECOND FROM DATETIME '2008-12-25 15:30:00.123456') as millisecond, " + "EXTRACT(MICROSECOND FROM DATETIME '2008-12-25 15:30:00.123456') as microsecond, " + "EXTRACT(DATE FROM DATETIME '2008-12-25 15:30:00.123456') as date, " + "EXTRACT(TIME FROM DATETIME '2008-12-25 15:30:00.123456') as time ";
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql);
PCollection<Row> stream = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
final Schema schema = Schema.builder().addInt64Field("year").addInt64Field("quarter").addInt64Field("month").addInt64Field("day").addInt64Field("dayofweek").addInt64Field("dayofyear").addInt64Field("hour").addInt64Field("minute").addInt64Field("second").addInt64Field("millisecond").addInt64Field("microsecond").addLogicalTypeField("date", SqlTypes.DATE).addLogicalTypeField("time", SqlTypes.TIME).build();
PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues(2008L, 4L, 12L, // 52L,
25L, 5L, 360L, 15L, 30L, 0L, 123L, 123456L, LocalDate.of(2008, 12, 25), LocalTime.of(15, 30, 0, 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 testAggregateOnDate.
@Test
public void testAggregateOnDate() {
String sql = "SELECT MAX(date_field) FROM table_with_date 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("date_field", SqlTypes.DATE).build()).addValues(LocalDate.of(2020, 4, 7)).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 testExtractFromTime.
// TODO[BEAM-9166]: Add a test for CURRENT_TIME function ("SELECT CURRENT_TIME()")
@Test
public void testExtractFromTime() {
String sql = "SELECT " + "EXTRACT(HOUR FROM TIME '15:30:35.123456') as hour, " + "EXTRACT(MINUTE FROM TIME '15:30:35.123456') as minute, " + "EXTRACT(SECOND FROM TIME '15:30:35.123456') as second, " + "EXTRACT(MILLISECOND FROM TIME '15:30:35.123456') as millisecond, " + "EXTRACT(MICROSECOND FROM TIME '15:30:35.123456') as microsecond ";
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql);
PCollection<Row> stream = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
final Schema schema = Schema.builder().addInt64Field("hour").addInt64Field("minute").addInt64Field("second").addInt64Field("millisecond").addInt64Field("microsecond").build();
PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues(15L, 30L, 35L, 123L, 123456L).build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
Aggregations