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/05/14 04:11:20 UTC

[GitHub] [beam] rahul8383 commented on a change in pull request #11581: [BEAM-8307] NPE in Calcite dialect when input PCollection has logical…

rahul8383 commented on a change in pull request #11581:
URL: https://github.com/apache/beam/pull/11581#discussion_r424860201



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/logicaltypes/LogicalDecimal.java
##########
@@ -0,0 +1,69 @@
+/*
+ * 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 static org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument;
+
+import java.math.BigDecimal;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.values.Row;
+
+/** A LogicalType representing a Decimal type with custom precision and scale. */
+@Experimental(Experimental.Kind.SCHEMAS)
+public class LogicalDecimal extends IdenticalBaseTAndInputTLogicalType<BigDecimal> {
+  public static final String IDENTIFIER = "beam:logical_type:decimal:v1";
+  private static final Schema schema =
+      Schema.builder().addInt32Field("precision").addInt32Field("scale").build();
+  private final int precision;
+  private final int scale;
+
+  private LogicalDecimal(int precision, int scale) {
+    super(
+        IDENTIFIER,
+        Schema.FieldType.row(schema),
+        Row.withSchema(schema).addValues(precision, scale).build(),
+        Schema.FieldType.STRING);

Review comment:
       @TheNeuralBit Modified `RowCoderTest.testLogicalType()` which exercises coder for the standard logical types.




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