use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlTimeFunctionsTest method testDateTimeAddWithParameter.
@Test
public void testDateTimeAddWithParameter() {
String sql = "SELECT DATETIME_ADD(@p0, INTERVAL @p1 HOUR)";
LocalDateTime datetime = LocalDateTime.of(2008, 12, 25, 15, 30, 0).withNano(123456000);
ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createDatetimeValue(datetime), "p1", Value.createInt64Value(3L));
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql, params);
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, 18, 30, 0).withNano(123456000)).build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlTimeFunctionsTest method testTimestampAddWithParameter1.
@Test
public void testTimestampAddWithParameter1() {
String sql = "SELECT TIMESTAMP_ADD(@p0, INTERVAL @p1 MILLISECOND)";
ImmutableMap<String, Value> params = ImmutableMap.of("p0", parseTimestampWithTZToValue("2001-01-01 00:00:00+00"), "p1", Value.createInt64Value(1L));
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("2001-01-01 00:00:00.001+00")).build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlTimeFunctionsTest method testDateAddWithParameter.
@Test
public void testDateAddWithParameter() {
String sql = "SELECT " + "DATE_ADD(@p0, INTERVAL @p1 DAY), " + "DATE_ADD(@p2, INTERVAL @p3 DAY), " + "DATE_ADD(@p4, INTERVAL @p5 YEAR), " + "DATE_ADD(@p6, INTERVAL @p7 DAY), " + "DATE_ADD(@p8, INTERVAL @p9 MONTH)";
ImmutableMap<String, Value> params = ImmutableMap.<String, Value>builder().put("p0", // 1970-01-01
Value.createDateValue(0)).put("p1", Value.createInt64Value(2L)).put("p2", parseDateToValue("2019-01-01")).put("p3", Value.createInt64Value(2L)).put("p4", Value.createSimpleNullValue(TypeKind.TYPE_DATE)).put("p5", Value.createInt64Value(1L)).put("p6", parseDateToValue("2000-02-29")).put("p7", Value.createInt64Value(-365L)).put("p8", parseDateToValue("1999-03-31")).put("p9", Value.createInt64Value(-1L)).build();
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql, params);
PCollection<Row> stream = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
final Schema schema = Schema.builder().addLogicalTypeField("f_date1", SqlTypes.DATE).addLogicalTypeField("f_date2", SqlTypes.DATE).addNullableField("f_date3", FieldType.logicalType(SqlTypes.DATE)).addLogicalTypeField("f_date4", SqlTypes.DATE).addLogicalTypeField("f_date5", SqlTypes.DATE).build();
PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues(LocalDate.of(1970, 1, 3), LocalDate.of(2019, 1, 3), null, LocalDate.of(1999, 3, 1), LocalDate.of(1999, 2, 28)).build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlTimeFunctionsTest method testTimeAddWithParameter.
@Test
public void testTimeAddWithParameter() {
String sql = "SELECT TIME_ADD(@p0, INTERVAL @p1 SECOND)";
ImmutableMap<String, Value> params = ImmutableMap.of("p0", parseTimeToValue("12:13:14.123"), "p1", Value.createInt64Value(1L));
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql, params);
PCollection<Row> stream = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
PAssert.that(stream).containsInAnyOrder(Row.withSchema(Schema.builder().addLogicalTypeField("f_time", SqlTypes.TIME).build()).addValues(LocalTime.of(12, 13, 15, 123000000)).build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlDialectSpecTest method testNullIfPositive.
@Test
public void testNullIfPositive() {
String sql = "SELECT NULLIF(@p0, @p1) AS ColA";
ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createStringValue("null"), "p1", Value.createStringValue("null"));
PCollection<Row> stream = execute(sql, params);
final Schema schema = Schema.builder().addNullableField("field1", FieldType.STRING).build();
PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValue(null).build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
Aggregations