ZijieSong946 commented on a change in pull request #12348: URL: https://github.com/apache/beam/pull/12348#discussion_r465319230
########## File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/logicaltypes/DateTime.java ########## @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.sdk.schemas.logicaltypes; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import org.apache.beam.sdk.schemas.Schema; +import org.apache.beam.sdk.values.Row; + +/** + * A datetime without a time-zone. + * + * <p>It cannot represent an instant on the time-line without additional information such as an + * offset or time-zone. + * + * <p>Its input type is a {@link LocalDateTime}, and base type is a {@link Row} containing Date + * field and Time field. Date field is the same as the base type of {@link Date}, which is a Long + * that represents incrementing count of days where day 0 is 1970-01-01 (ISO). Time field is the + * same as the base type of {@link Time}, which is a Long that represents a count of time in + * nanoseconds. + */ +public class DateTime implements Schema.LogicalType<LocalDateTime, Row> { + public static final String DATE_FIELD = "Date"; Review comment: Done. ########## File path: sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/impl/schema/BeamSqlRowCoderTest.java ########## @@ -51,6 +52,7 @@ public void encodeAndDecode() throws Exception { .add("col_string_varchar", SqlTypeName.VARCHAR) .add("col_time", SqlTypeName.TIME) .add("col_date", SqlTypeName.DATE) + .add("col_datetime", SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE) Review comment: OK. Done. ########## File path: sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamComplexTypeTest.java ########## @@ -412,32 +398,141 @@ public void testNullDatetimeFields() { .addNullableField("year_with_null", FieldType.INT64) .addField("mm", FieldType.INT64) .addNullableField("month_with_null", FieldType.INT64) + .build(); + + PAssert.that(outputRow) + .containsInAnyOrder( + Row.withSchema(outputRowSchema).addValues(2019L, null, 06L, null).build()); + + pipeline.run().waitUntilFinish(Duration.standardMinutes(2)); + } + + @Test + public void testNullSqlLogicalTypeDateFields() { + Schema dateTimeFieldSchema = + Schema.builder() + .addField("dateTypeField", FieldType.logicalType(SqlTypes.DATE)) + .addNullableField("nullableDateTypeField", FieldType.logicalType(SqlTypes.DATE)) + .build(); + + Row dateRow = + Row.withSchema(dateTimeFieldSchema).addValues(LocalDate.of(2019, 6, 27), null).build(); + + PCollection<Row> outputRow = + pipeline + .apply(Create.of(dateRow)) + .setRowSchema(dateTimeFieldSchema) + .apply( + SqlTransform.query( + "select EXTRACT(DAY from dateTypeField) as dd, " + + " EXTRACT(DAY from nullableDateTypeField) as day_with_null, " + + " dateTypeField + interval '1' day as date_with_day_added, " + + " nullableDateTypeField + interval '1' day as day_added_with_null " + + " from PCOLLECTION")); + + Schema outputRowSchema = + Schema.builder() + .addField("dd", FieldType.INT64) + .addNullableField("day_with_null", FieldType.INT64) + .addField("date_with_day_added", FieldType.logicalType(SqlTypes.DATE)) + .addNullableField("day_added_with_null", FieldType.logicalType(SqlTypes.DATE)) + .build(); + + PAssert.that(outputRow) + .containsInAnyOrder( + Row.withSchema(outputRowSchema) + .addValues(27L, null, LocalDate.of(2019, 6, 28), null) + .build()); + + pipeline.run().waitUntilFinish(Duration.standardMinutes(2)); + } + + @Test + public void testNullSqlLogicalTypeTimeFields() { Review comment: Done. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org