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



##########
File path: 
sdks/java/extensions/sbe/src/main/java/org/apache/beam/sdk/extensions/sbe/SbeLogicalTypes.java
##########
@@ -0,0 +1,264 @@
+/*
+ * 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.extensions.sbe;
+
+import static org.apache.beam.sdk.extensions.sbe.Schemas.TZ_TIME_SCHEMA;
+import static org.apache.beam.sdk.extensions.sbe.Schemas.UTC_TIME_SCHEMA;
+
+import java.time.LocalDate;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.annotations.Experimental.Kind;
+import org.apache.beam.sdk.extensions.sbe.TimeValues.TZTimeOnlyValue;
+import org.apache.beam.sdk.extensions.sbe.TimeValues.TZTimestampValue;
+import org.apache.beam.sdk.extensions.sbe.TimeValues.UTCTimeOnlyValue;
+import org.apache.beam.sdk.extensions.sbe.TimeValues.UTCTimestampValue;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.schemas.Schema.FieldType;
+import org.apache.beam.sdk.schemas.Schema.LogicalType;
+import org.apache.beam.sdk.schemas.logicaltypes.PassThroughLogicalType;
+import org.apache.beam.sdk.values.Row;
+import org.checkerframework.checker.initialization.qual.Initialized;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.checker.nullness.qual.UnknownKeyFor;
+
+/**
+ * Classes that represent various SBE semantic types.
+ *
+ * <p>Not all of SBE's semantic types are represented here, as some can be 
reasonably represented in
+ * Beam schemas with just a primitive.
+ */
+@Experimental(Kind.SCHEMAS)
+public final class SbeLogicalTypes {
+  public static final Uint8 UINT_8 = new Uint8();
+  public static final Uint16 UINT_16 = new Uint16();
+  public static final Uint32 UINT_32 = new Uint32();
+  public static final Uint64 UINT_64 = new Uint64();
+
+  public static final UTCTimestamp UTC_TIMESTAMP = new UTCTimestamp();
+  public static final UTCTimeOnly UTC_TIME_ONLY = new UTCTimeOnly();
+  public static final UTCDateOnly UTC_DATE_ONLY = new UTCDateOnly();
+  public static final TZTimestamp TZ_TIMESTAMP = new TZTimestamp();
+  public static final TZTimeOnly TZ_TIME_ONLY = new TZTimeOnly();
+  public static final LocalMktDate LOCAL_MKT_DATE = new LocalMktDate();
+
+  // Default argument type values
+  private static final String DEFAULT_STRING_ARG = "";
+
+  private SbeLogicalTypes() {}
+
+  // Unsigned types are all stored at the next highest value. This prevents 
unexpected behavior
+  // when reading and likely has negligible space impact.

Review comment:
       The space impact will be 2x which could be non-trivial if there are many 
unsigned integer fields. We could at least save the space on the wire by using 
the same bit width for the base type. But that would still consume memory on 
the worker. You'd also have to make a custom logical type for that.
   
   Another option is the protobuf approach. It just maps unsigned integers to 
their signed counterparts directly and users are responsible for munging 
negative values. See footnote [2] here: 
https://developers.google.com/protocol-buffers/docs/proto3#scalar
   
   @reuvenlax have you thought at all about the best way to represent unsigned 
integers in Java beam schemas?

##########
File path: 
sdks/java/extensions/sbe/src/main/java/org/apache/beam/sdk/extensions/sbe/TimeValues.java
##########
@@ -0,0 +1,460 @@
+/*
+ * 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.extensions.sbe;
+
+import static org.apache.beam.sdk.extensions.sbe.Schemas.TZ_TIME_SCHEMA;
+import static 
org.apache.beam.sdk.extensions.sbe.Schemas.TimeFieldNames.TIME_FIELD_NAME;
+import static 
org.apache.beam.sdk.extensions.sbe.Schemas.TimeFieldNames.TIME_ZONE_HOUR_FIELD_NAME;
+import static 
org.apache.beam.sdk.extensions.sbe.Schemas.TimeFieldNames.TIME_ZONE_MINUTE_FIELD_NAME;
+import static 
org.apache.beam.sdk.extensions.sbe.Schemas.TimeFieldNames.UNIT_FIELD_NAME;
+import static org.apache.beam.sdk.extensions.sbe.Schemas.UTC_TIME_SCHEMA;
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument;
+
+import java.time.Instant;
+import java.time.OffsetDateTime;
+import java.time.OffsetTime;
+import java.time.ZoneOffset;
+import java.time.temporal.ChronoUnit;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+import org.apache.beam.sdk.values.Row;
+import org.checkerframework.checker.initialization.qual.Initialized;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+/**
+ * Representations of SBE value types.
+ *
+ * <p>These are convertible to/from a {@link Row} that is a direct mapping of 
an SBE composite type.
+ */
+public final class TimeValues {

Review comment:
       Would it be possible to just use joda or java time types instead of 
defining our own date/time classes?




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to