You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2020/09/03 23:58:13 UTC

[GitHub] [beam] TheNeuralBit commented on a change in pull request #12764: [BEAM-10009] Add beam:logical_type:micros_instant:v1

TheNeuralBit commented on a change in pull request #12764:
URL: https://github.com/apache/beam/pull/12764#discussion_r483313450



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/logicaltypes/MicrosInstant.java
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.Instant;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.values.Row;
+
+/**
+ * A timestamp represented as microseconds since the epoch.
+ *
+ * <p>WARNING: This logical type exists solely for interoperability with other type systems such as
+ * SQL and other Beam SDKs. It should never be used in a native Java context where the {@code
+ * java.time.Instant} instances it describes may have higher than microsecond precision. Ignoring
+ * this will likely result in an {@code AssertionError} at pipeline execution time.
+ *
+ * <p>For a more faithful logical type to use with {@code java.time.Instant}, see {@link
+ * NanosInstant}.
+ */
+public class MicrosInstant implements Schema.LogicalType<Instant, Row> {
+  public static final String IDENTIFIER = "beam:logical_type:micros_instant:v1";
+  private final Schema schema;
+
+  public MicrosInstant() {
+    this.schema = Schema.builder().addInt64Field("seconds").addInt32Field("micros").build();
+  }
+
+  @Override
+  public Row toBaseType(Instant input) {

Review comment:
       That's a good question.. I don't think we have an answer for it documented anywhere. I think we should probably handle null checking outside of `toBaseType` and `toInputType`, so that we only do it when the type is marked `nullable`.




----------------------------------------------------------------
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:
users@infra.apache.org