use of org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode in project beam by apache.
the class ZetaSqlTimeFunctionsTest method testTimestampTrunc.
@Test
public void testTimestampTrunc() {
String sql = "SELECT TIMESTAMP_TRUNC(TIMESTAMP '2017-11-06 00:00:00+12', ISOWEEK, 'UTC')";
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_trunc").build()).addValues(DateTimeUtils.parseTimestampWithUTCTimeZone("2017-10-30 00:00: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 testTimestampToUnixInt64.
@Test
public void testTimestampToUnixInt64() {
String sql = "SELECT " + "UNIX_SECONDS(TIMESTAMP '2008-12-25 15:30:00 UTC'), " + "UNIX_MILLIS(TIMESTAMP '2008-12-25 15:30:00.123 UTC')";
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_unix_seconds").addInt64Field("f_unix_millis").build()).addValues(1230219000L, 1230219000123L).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 testDateToUnixInt64.
@Test
public void testDateToUnixInt64() {
String sql = "SELECT UNIX_DATE(DATE '2008-12-25')";
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_unix_date").build()).addValues(14238L).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 testDateTimeColumn.
@Test
public void testDateTimeColumn() {
String sql = "SELECT FORMAT_DATETIME('%D %T %E6S', datetime_field) FROM table_with_datetime";
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(), Row.withSchema(Schema.builder().addStringField("f_datetime_str").build()).addValues("10/06/12 11:45:00 00.987654").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 testTimestampFromDate.
@Test
public void testTimestampFromDate() {
String sql = "SELECT TIMESTAMP(DATE '2014-01-31')";
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("2014-01-31 00:00:00+00")).build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
Aggregations