You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2021/06/21 20:12:11 UTC

[GitHub] [iceberg] jackye1995 commented on a change in pull request #2701: Hive: support create table with partition transform through table property

jackye1995 commented on a change in pull request #2701:
URL: https://github.com/apache/iceberg/pull/2701#discussion_r655673144



##########
File path: mr/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergPartitionTextParser.java
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.iceberg.mr.hive;
+
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.exceptions.ValidationException;
+
+/**
+ * Parser for inputs received from config {@link org.apache.iceberg.mr.InputFormatConfig#PARTITIONING}
+ */
+class HiveIcebergPartitionTextParser {
+  private static final int PARTITION_TEXT_MAX_LENGTH = 1000;
+
+  private static final Pattern BUCKET_PATTERN = Pattern.compile("bucket\\((.*?),(.*?)\\)", Pattern.CASE_INSENSITIVE);
+  private static final Pattern TRUNCATE_PATTERN = Pattern.compile(
+      "truncate\\((.*?),(.*?)\\)", Pattern.CASE_INSENSITIVE);
+  private static final Pattern YEAR_PATTERN = Pattern.compile("year\\((.*?)\\)", Pattern.CASE_INSENSITIVE);
+  private static final Pattern MONTH_PATTERN = Pattern.compile("month\\((.*?)\\)", Pattern.CASE_INSENSITIVE);
+  private static final Pattern DAY_PATTERN = Pattern.compile("day\\((.*?)\\)", Pattern.CASE_INSENSITIVE);
+  private static final Pattern HOUR_PATTERN = Pattern.compile("hour\\((.*?)\\)", Pattern.CASE_INSENSITIVE);
+  private static final Pattern ALWAYS_NULL_PATTERN = Pattern.compile(
+      "alwaysNull\\((.*?)\\)", Pattern.CASE_INSENSITIVE);
+  private static final String INTEGER_PATTERN = "\\d+";
+  private static final String PIPE_DELIMITER = "\\|";
+
+  private HiveIcebergPartitionTextParser() {
+  }
+
+  private static boolean build2ArgTransform(Pattern transformPattern, Schema schema,
+                                         BiConsumer<String, Integer> transformBuilder, String trimmedPart) {
+    Matcher matcher = transformPattern.matcher(trimmedPart);
+    if (matcher.find()) {
+      ValidationException.check(matcher.groupCount() == 2 && matcher.group(2).trim().matches(INTEGER_PATTERN),
+          "Cannot parse 2-arg partition transform from text part: %s", trimmedPart);
+
+      String columnName = matcher.group(1).trim();
+      ValidationException.check(schema.findField(columnName) != null,

Review comment:
       Yeah agree, these can always be caught by the partition spec builder, but I was thinking it might be better to fail fast. Let me think about it more for what is the best line to cut here.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org