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/04 19:07:02 UTC

[GitHub] [beam] TheNeuralBit commented on a change in pull request #11569: [BEAM-9840] Support for Parameterized Types when converting from HCat…

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



##########
File path: sdks/java/io/hcatalog/src/test/java/org/apache/beam/sdk/io/hcatalog/SchemaUtilsTest.java
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.io.hcatalog;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class SchemaUtilsTest {
+  @Test
+  public void testParameterizedTypesToBeamTypes() {
+    List<FieldSchema> listOfFieldSchema = new ArrayList<>();
+    listOfFieldSchema.add(new FieldSchema("parameterizedChar", "char(10)", null));
+    listOfFieldSchema.add(new FieldSchema("parameterizedVarchar", "varchar(100)", null));
+    listOfFieldSchema.add(new FieldSchema("parameterizedDecimal", "decimal(30,16)", null));
+
+    Schema expectedSchema =
+        Schema.builder()
+            .addNullableField("parameterizedChar", Schema.FieldType.STRING)
+            .addNullableField("parameterizedVarchar", Schema.FieldType.STRING)
+            .addNullableField("parameterizedDecimal", Schema.FieldType.DECIMAL)

Review comment:
       I think these should map to logical types instead of to primitives so we don't lose the information from the parameter. Unfortunately we don't (yet) have good logical types in `schemas.logicaltypes` to map them to, but maybe we will after your other PR, https://github.com/apache/beam/pull/11581 (or you could just add the relevant ones here).
   
   `char(10)` looks like it could map to a `FixedLengthString` logical type, `varchar(100)` probably deserves its own type, maybe just called `Varchar`? and I've been meaning to add a logical type for DECIMAL parameterized by precision and scale as part of [BEAM-7554](https://issues.apache.org/jira/browse/BEAM-7554) (and deprecate the primitive one).




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