[ https://issues.apache.org/jira/browse/BEAM-9641?focusedWorklogId=431032&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-431032 ]
ASF GitHub Bot logged work on BEAM-9641: ---------------------------------------- Author: ASF GitHub Bot Created on: 06/May/20 05:38 Start Date: 06/May/20 05:38 Worklog Time Spent: 10m Work Description: robinyqiu commented on a change in pull request #11272: URL: https://github.com/apache/beam/pull/11272#discussion_r418871819 ########## File path: sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamCalcRel.java ########## @@ -427,17 +430,12 @@ private static Expression value( private static Expression value(Expression value, Schema.FieldType type) { if (type.getTypeName().isLogicalType()) { - Expression millisField = Expressions.call(value, "getMillis"); String logicalId = type.getLogicalType().getIdentifier(); if (logicalId.equals(TimeType.IDENTIFIER)) { - return nullOr(value, Expressions.convert_(millisField, int.class)); - } else if (logicalId.equals(DateType.IDENTIFIER)) { - value = - nullOr( - value, - Expressions.convert_( - Expressions.divide(millisField, Expressions.constant(MILLIS_PER_DAY)), - int.class)); + return nullOr( + value, Expressions.convert_(Expressions.call(value, "getMillis"), int.class)); + } else if (logicalId.equals(SqlTypes.DATE.getIdentifier())) { Review comment: Done. I hope I could use a switch statement here, but unfortunately there is no constant `IDENTIFIER` defined in the `LogicalType` class. (I could add it to each concrete SQL logical type I create, but I don't think that is a good style.) ########## File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/logicaltypes/Date.java ########## @@ -0,0 +1,62 @@ +/* + * 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 org.apache.beam.sdk.schemas.Schema; + +/** + * A date without a time-zone. + * + * <p>It cannot represent an instant on the time-line without additional information such as an Review comment: Done. ########## File path: sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamEnumerableConverter.java ########## @@ -303,8 +303,8 @@ private static Object fieldToAvatica(Schema.FieldType type, Object beamValue) { String logicalId = type.getLogicalType().getIdentifier(); if (logicalId.equals(TimeType.IDENTIFIER)) { return (int) ((ReadableInstant) beamValue).getMillis(); - } else if (logicalId.equals(DateType.IDENTIFIER)) { - return (int) (((ReadableInstant) beamValue).getMillis() / MILLIS_PER_DAY); + } else if (logicalId.equals(SqlTypes.DATE.getIdentifier())) { Review comment: Done. ########## File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/logicaltypes/Date.java ########## @@ -0,0 +1,62 @@ +/* + * 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 org.apache.beam.sdk.schemas.Schema; + +/** + * A date without a time-zone. + * + * <p>It cannot represent an instant on the time-line without additional information such as an + * offset or time-zone. + */ +public class Date implements Schema.LogicalType<LocalDate, Long> { Review comment: I think Andrew is basically suggesting using a `PassThroughLogicalType<Long>` as a logical type for `DATE`. I think we could definitely consider this if performance becomes a problem in the future. (It's not easy to change the in-memory type for `Date` after it is made public, but we can easily define a new `SqlDate`.) For now I think we can leave it as is. It's more human readable (e.g. writing tests for `DATE` type in spec tests is simpler). ---------------------------------------------------------------- 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 Issue Time Tracking ------------------- Worklog Id: (was: 431032) Time Spent: 1h 50m (was: 1h 40m) > Support ZetaSQL DATE functions in BeamSQL > ----------------------------------------- > > Key: BEAM-9641 > URL: https://issues.apache.org/jira/browse/BEAM-9641 > Project: Beam > Issue Type: New Feature > Components: dsl-sql-zetasql > Reporter: Yueyang Qiu > Assignee: Yueyang Qiu > Priority: Major > Labels: zetasql-compliance > Time Spent: 1h 50m > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.3.4#803005)