[ 
https://issues.apache.org/jira/browse/HIVE-25179?focusedWorklogId=605021&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-605021
 ]

ASF GitHub Bot logged work on HIVE-25179:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 02/Jun/21 08:11
            Start Date: 02/Jun/21 08:11
    Worklog Time Spent: 10m 
      Work Description: lcspinter commented on a change in pull request #2333:
URL: https://github.com/apache/hive/pull/2333#discussion_r643752741



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/PartitionTransform.java
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.hadoop.hive.ql.parse;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class PartitionTransform {
+
+  private static final Map<Integer, TransformTypes> TRANSFORMS = Stream
+      .of(new Object[][] { { HiveParser.TOK_IDENTITY, TransformTypes.IDENTITY 
},
+          { HiveParser.TOK_YEAR, TransformTypes.YEAR }, { 
HiveParser.TOK_MONTH, TransformTypes.MONTH },
+          { HiveParser.TOK_DAY, TransformTypes.DAY }, { HiveParser.TOK_HOUR, 
TransformTypes.HOUR },
+          { HiveParser.TOK_TRUNCATE, TransformTypes.TRUNCATE }, { 
HiveParser.TOK_BUCKET, TransformTypes.BUCKET } })
+      .collect(Collectors.toMap(e -> (Integer) e[0], e -> (TransformTypes) 
e[1]));
+
+  /**
+   * Parse the partition transform specifications from the AST Tree node.
+   * @param node AST Tree node, must be not null
+   * @return list of partition transforms
+   */
+  public static List<PartitionTransformSpec> getPartitionTransformSpec(ASTNode 
node) {
+    List<PartitionTransformSpec> partSpecList = new ArrayList<>();
+    for (int i = 0; i < node.getChildCount(); i++) {
+      PartitionTransformSpec spec = new PartitionTransformSpec();
+      ASTNode child = (ASTNode) node.getChild(i);
+      for (int j = 0; j < child.getChildCount(); j++) {
+        ASTNode grandChild = (ASTNode) child.getChild(j);
+        switch (grandChild.getToken().getType()) {
+        case HiveParser.TOK_IDENTITY:
+        case HiveParser.TOK_YEAR:
+        case HiveParser.TOK_MONTH:
+        case HiveParser.TOK_DAY:
+        case HiveParser.TOK_HOUR:
+          spec.transformType = TRANSFORMS.get(grandChild.getToken().getType());
+          break;
+        case HiveParser.TOK_TRUNCATE:
+        case HiveParser.TOK_BUCKET:
+          spec.transformType = TRANSFORMS.get(grandChild.getToken().getType());
+          spec.transformParam = 
Integer.valueOf(grandChild.getChild(0).getText());
+          break;
+        default:
+          spec.name = grandChild.getText();
+        }
+      }
+      partSpecList.add(spec);
+    }
+
+    return partSpecList;
+  }
+
+  public enum TransformTypes {
+    IDENTITY, YEAR, MONTH, DAY, HOUR, TRUNCATE, BUCKET
+  }
+
+  public static class PartitionTransformSpec {
+    public String name;
+    public TransformTypes transformType;
+    public int transformParam;

Review comment:
       In the case of TRUNCATE and BUCKET, the existence of the transform param 
is validated during the query parsing, but I agree It can be misleading for 
transform types with additional params. 

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/PartitionTransform.java
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.hadoop.hive.ql.parse;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class PartitionTransform {
+
+  private static final Map<Integer, TransformTypes> TRANSFORMS = Stream
+      .of(new Object[][] { { HiveParser.TOK_IDENTITY, TransformTypes.IDENTITY 
},
+          { HiveParser.TOK_YEAR, TransformTypes.YEAR }, { 
HiveParser.TOK_MONTH, TransformTypes.MONTH },
+          { HiveParser.TOK_DAY, TransformTypes.DAY }, { HiveParser.TOK_HOUR, 
TransformTypes.HOUR },
+          { HiveParser.TOK_TRUNCATE, TransformTypes.TRUNCATE }, { 
HiveParser.TOK_BUCKET, TransformTypes.BUCKET } })
+      .collect(Collectors.toMap(e -> (Integer) e[0], e -> (TransformTypes) 
e[1]));
+
+  /**
+   * Parse the partition transform specifications from the AST Tree node.
+   * @param node AST Tree node, must be not null
+   * @return list of partition transforms
+   */
+  public static List<PartitionTransformSpec> getPartitionTransformSpec(ASTNode 
node) {
+    List<PartitionTransformSpec> partSpecList = new ArrayList<>();
+    for (int i = 0; i < node.getChildCount(); i++) {
+      PartitionTransformSpec spec = new PartitionTransformSpec();
+      ASTNode child = (ASTNode) node.getChild(i);
+      for (int j = 0; j < child.getChildCount(); j++) {
+        ASTNode grandChild = (ASTNode) child.getChild(j);
+        switch (grandChild.getToken().getType()) {
+        case HiveParser.TOK_IDENTITY:

Review comment:
       Done.




-- 
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: 605021)
    Time Spent: 3h 50m  (was: 3h 40m)

> Support all partition transforms for Iceberg in create table
> ------------------------------------------------------------
>
>                 Key: HIVE-25179
>                 URL: https://issues.apache.org/jira/browse/HIVE-25179
>             Project: Hive
>          Issue Type: New Feature
>            Reporter: László Pintér
>            Assignee: László Pintér
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 3h 50m
>  Remaining Estimate: 0h
>
> Enhance table create syntax with support to partition transforms:
> {code:sql}
> CREATE TABLE ... PARTITIONED BY SPEC(
> year_field year,
> month_field month,
> day_field day,
> hour_field hour,
> truncate_field truncate[3],
> bucket_field bucket[5],
> identity_field identity
> ) STORED BY ICEBERG;
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to