You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/07/24 18:59:28 UTC

[GitHub] [doris] AshinGau opened a new pull request, #11156: [feature-wip](multi-catalog) support pruning buckets for hive bucket table

AshinGau opened a new pull request, #11156:
URL: https://github.com/apache/doris/pull/11156

   # Proposed changes
   
   Support pruning buckets for hive bucket table.
    
   ## Notes
   1. Spark currently does not populate bucketed output which is compatible with Hive, so spark bucket table is not supported in current implementation.
   2. Hive 3.0 introduced bucket version 2, but doris still uses hive 2.3.7 which lacks the hash function of version 2, so I refer to the implementation of Trino and copy the hash function from hive.
   3. Current implementation doest not support the table with multiple bucketed columns, and only support `Equal` and `In` predicates.
   
   ## Profit
   Suppose `lineitem` table in tpch(sf=100) is bucketed by l_orderkey into 96 buekts, when query:
   ```
   select count(*) from lineitem where l_orderkey = 1;
   ```
   Splits scanning reduced from 144 to 6.
   
   ## Checklist(Required)
   
   1. Does it affect the original behavior: (No)
   4. Has unit tests been added: (No)
   5. Has document been added or modified: (No)
   6. Does it need to update dependencies: (No)
   7. Are there any changes that cannot be rolled back: (No)
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at [dev@doris.apache.org](mailto:dev@doris.apache.org) by explaining why you chose the solution you did and what alternatives you considered, etc...
   


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] morningman merged pull request #11156: [feature-wip](multi-catalog) support pruning buckets for hive bucket table

Posted by GitBox <gi...@apache.org>.
morningman merged PR #11156:
URL: https://github.com/apache/doris/pull/11156


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] morningman commented on a diff in pull request #11156: [feature-wip](multi-catalog) support pruning buckets for hive bucket table

Posted by GitBox <gi...@apache.org>.
morningman commented on code in PR #11156:
URL: https://github.com/apache/doris/pull/11156#discussion_r928353577


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/HiveBucketUtil.java:
##########
@@ -0,0 +1,394 @@
+// 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.doris.catalog;
+
+import org.apache.doris.analysis.BinaryPredicate;
+import org.apache.doris.analysis.CompoundPredicate;
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.analysis.InPredicate;
+import org.apache.doris.analysis.LiteralExpr;
+import org.apache.doris.analysis.SlotRef;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.thrift.TExprOpcode;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.ByteObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.ShortObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector;
+import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.InputSplit;
+import org.apache.hive.common.util.Murmur3;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.OptionalInt;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class HiveBucketUtil {
+    private static final Logger LOG = LogManager.getLogger(HiveBucketUtil.class);
+
+    private static final Set<PrimitiveType> SUPPORTED_TYPES_FOR_BUCKET_FILTER = ImmutableSet.of(
+            PrimitiveType.BOOLEAN,
+            PrimitiveType.TINYINT,
+            PrimitiveType.SMALLINT,
+            PrimitiveType.INT,
+            PrimitiveType.BIGINT,
+            PrimitiveType.STRING);
+
+    private static PrimitiveTypeInfo convertToHiveColType(PrimitiveType dorisType) throws DdlException {
+        switch (dorisType) {
+            case BOOLEAN:
+                return TypeInfoFactory.booleanTypeInfo;
+            case TINYINT:
+                return TypeInfoFactory.byteTypeInfo;
+            case SMALLINT:
+                return TypeInfoFactory.shortTypeInfo;
+            case INT:
+                return TypeInfoFactory.intTypeInfo;
+            case BIGINT:
+                return TypeInfoFactory.longTypeInfo;
+            case STRING:
+                return TypeInfoFactory.stringTypeInfo;
+            default:
+                throw new DdlException("Unsupported pruning bucket column type: " + dorisType);
+        }
+    }
+
+    private static final Pattern BUCKET_WITH_OPTIONAL_ATTEMPT_ID_PATTERN =
+            Pattern.compile("bucket_(\\d+)(_\\d+)?$");
+
+    private static final Iterable<Pattern> BUCKET_PATTERNS = ImmutableList.of(
+            // legacy Presto naming pattern (current version matches Hive)
+            Pattern.compile("\\d{8}_\\d{6}_\\d{5}_[a-z0-9]{5}_bucket-(\\d+)(?:[-_.].*)?"),
+            // Hive naming pattern per `org.apache.hadoop.hive.ql.exec.Utilities#getBucketIdFromFile()`
+            Pattern.compile("(\\d+)_\\d+.*"),
+            // Hive ACID with optional direct insert attempt id
+            BUCKET_WITH_OPTIONAL_ATTEMPT_ID_PATTERN);
+
+    public static List<InputSplit> getPrunedSplitsByBuckets(
+            String tableName, List<InputSplit> splits, Set<Integer> buckets, int numBuckets) {
+        if (buckets == null) {
+            return splits;
+        }
+        if (buckets.size() == 0) {
+            return Collections.emptyList();
+        }
+        List<InputSplit> result = new LinkedList<>();
+        boolean valid = true;
+        for (InputSplit split : splits) {
+            String fileName = ((FileSplit) split).getPath().getName();
+            OptionalInt bucket = getBucketNumberFromPath(fileName);
+            if (bucket.isPresent()) {
+                int bucketId = bucket.getAsInt();
+                if (bucketId >= numBuckets) {
+                    valid = false;
+                    LOG.warn("Hive table {} is corrupt for file {}(bucketId={}), skip bucket pruning.",
+                            tableName, fileName, bucketId);
+                    break;
+                }
+                if (buckets.contains(bucketId)) {
+                    result.add(split);
+                }
+            } else {
+                valid = false;
+                LOG.warn("File {} is not a bucket file in hive table {}, skip bucket pruning.", fileName, tableName);
+                break;
+            }
+        }
+        if (valid) {
+            LOG.info("{} / {} input splits in hive table {} after bucket pruning.",

Review Comment:
   debug



##########
fe/fe-core/src/main/java/org/apache/doris/planner/external/ExternalHiveScanProvider.java:
##########
@@ -109,12 +112,22 @@ public List<InputSplit> getSplits(List<Expr> exprs)
 
         Configuration configuration = setConfiguration();
         InputFormat<?, ?> inputFormat = HiveUtil.getInputFormat(configuration, inputFormatName, false);
+        List<InputSplit> result;
         if (!hivePartitions.isEmpty()) {
-            return hivePartitions.parallelStream()
+            result = hivePartitions.parallelStream()
                     .flatMap(x -> getSplitsByPath(inputFormat, configuration, x.getSd().getLocation()).stream())
                     .collect(Collectors.toList());
         } else {
-            return getSplitsByPath(inputFormat, configuration, splitsPath);
+            result = getSplitsByPath(inputFormat, configuration, splitsPath);
+        }
+        Optional<Set<Integer>> prunedBuckets = HiveBucketUtil.getPrunedBuckets(

Review Comment:
   Looks like we can merge `getPrunedBuckets` and `getPrunedSplitsByBuckets` into one method.
   To make it simpler to use?



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/HiveBucketUtil.java:
##########
@@ -0,0 +1,394 @@
+// 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.doris.catalog;
+
+import org.apache.doris.analysis.BinaryPredicate;
+import org.apache.doris.analysis.CompoundPredicate;
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.analysis.InPredicate;
+import org.apache.doris.analysis.LiteralExpr;
+import org.apache.doris.analysis.SlotRef;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.thrift.TExprOpcode;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.ByteObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.ShortObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector;
+import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.InputSplit;
+import org.apache.hive.common.util.Murmur3;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.OptionalInt;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class HiveBucketUtil {
+    private static final Logger LOG = LogManager.getLogger(HiveBucketUtil.class);
+
+    private static final Set<PrimitiveType> SUPPORTED_TYPES_FOR_BUCKET_FILTER = ImmutableSet.of(
+            PrimitiveType.BOOLEAN,
+            PrimitiveType.TINYINT,
+            PrimitiveType.SMALLINT,
+            PrimitiveType.INT,
+            PrimitiveType.BIGINT,
+            PrimitiveType.STRING);
+
+    private static PrimitiveTypeInfo convertToHiveColType(PrimitiveType dorisType) throws DdlException {
+        switch (dorisType) {
+            case BOOLEAN:
+                return TypeInfoFactory.booleanTypeInfo;
+            case TINYINT:
+                return TypeInfoFactory.byteTypeInfo;
+            case SMALLINT:
+                return TypeInfoFactory.shortTypeInfo;
+            case INT:
+                return TypeInfoFactory.intTypeInfo;
+            case BIGINT:
+                return TypeInfoFactory.longTypeInfo;
+            case STRING:
+                return TypeInfoFactory.stringTypeInfo;
+            default:
+                throw new DdlException("Unsupported pruning bucket column type: " + dorisType);
+        }
+    }
+
+    private static final Pattern BUCKET_WITH_OPTIONAL_ATTEMPT_ID_PATTERN =
+            Pattern.compile("bucket_(\\d+)(_\\d+)?$");
+
+    private static final Iterable<Pattern> BUCKET_PATTERNS = ImmutableList.of(
+            // legacy Presto naming pattern (current version matches Hive)
+            Pattern.compile("\\d{8}_\\d{6}_\\d{5}_[a-z0-9]{5}_bucket-(\\d+)(?:[-_.].*)?"),
+            // Hive naming pattern per `org.apache.hadoop.hive.ql.exec.Utilities#getBucketIdFromFile()`
+            Pattern.compile("(\\d+)_\\d+.*"),
+            // Hive ACID with optional direct insert attempt id
+            BUCKET_WITH_OPTIONAL_ATTEMPT_ID_PATTERN);
+
+    public static List<InputSplit> getPrunedSplitsByBuckets(
+            String tableName, List<InputSplit> splits, Set<Integer> buckets, int numBuckets) {
+        if (buckets == null) {
+            return splits;
+        }
+        if (buckets.size() == 0) {
+            return Collections.emptyList();
+        }
+        List<InputSplit> result = new LinkedList<>();
+        boolean valid = true;
+        for (InputSplit split : splits) {
+            String fileName = ((FileSplit) split).getPath().getName();
+            OptionalInt bucket = getBucketNumberFromPath(fileName);
+            if (bucket.isPresent()) {
+                int bucketId = bucket.getAsInt();
+                if (bucketId >= numBuckets) {
+                    valid = false;
+                    LOG.warn("Hive table {} is corrupt for file {}(bucketId={}), skip bucket pruning.",
+                            tableName, fileName, bucketId);
+                    break;
+                }
+                if (buckets.contains(bucketId)) {
+                    result.add(split);
+                }
+            } else {
+                valid = false;
+                LOG.warn("File {} is not a bucket file in hive table {}, skip bucket pruning.", fileName, tableName);

Review Comment:
   use debug



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] github-actions[bot] commented on pull request #11156: [feature-wip](multi-catalog) support pruning buckets for hive bucket table

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #11156:
URL: https://github.com/apache/doris/pull/11156#issuecomment-1196200751

   PR approved by anyone and no changes requested.


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] AshinGau commented on a diff in pull request #11156: [feature-wip](multi-catalog) support pruning buckets for hive bucket table

Posted by GitBox <gi...@apache.org>.
AshinGau commented on code in PR #11156:
URL: https://github.com/apache/doris/pull/11156#discussion_r928515893


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/HiveBucketUtil.java:
##########
@@ -0,0 +1,394 @@
+// 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.doris.catalog;
+
+import org.apache.doris.analysis.BinaryPredicate;
+import org.apache.doris.analysis.CompoundPredicate;
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.analysis.InPredicate;
+import org.apache.doris.analysis.LiteralExpr;
+import org.apache.doris.analysis.SlotRef;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.thrift.TExprOpcode;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.ByteObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.ShortObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector;
+import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.InputSplit;
+import org.apache.hive.common.util.Murmur3;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.OptionalInt;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class HiveBucketUtil {
+    private static final Logger LOG = LogManager.getLogger(HiveBucketUtil.class);
+
+    private static final Set<PrimitiveType> SUPPORTED_TYPES_FOR_BUCKET_FILTER = ImmutableSet.of(
+            PrimitiveType.BOOLEAN,
+            PrimitiveType.TINYINT,
+            PrimitiveType.SMALLINT,
+            PrimitiveType.INT,
+            PrimitiveType.BIGINT,
+            PrimitiveType.STRING);
+
+    private static PrimitiveTypeInfo convertToHiveColType(PrimitiveType dorisType) throws DdlException {
+        switch (dorisType) {
+            case BOOLEAN:
+                return TypeInfoFactory.booleanTypeInfo;
+            case TINYINT:
+                return TypeInfoFactory.byteTypeInfo;
+            case SMALLINT:
+                return TypeInfoFactory.shortTypeInfo;
+            case INT:
+                return TypeInfoFactory.intTypeInfo;
+            case BIGINT:
+                return TypeInfoFactory.longTypeInfo;
+            case STRING:
+                return TypeInfoFactory.stringTypeInfo;
+            default:
+                throw new DdlException("Unsupported pruning bucket column type: " + dorisType);
+        }
+    }
+
+    private static final Pattern BUCKET_WITH_OPTIONAL_ATTEMPT_ID_PATTERN =
+            Pattern.compile("bucket_(\\d+)(_\\d+)?$");
+
+    private static final Iterable<Pattern> BUCKET_PATTERNS = ImmutableList.of(
+            // legacy Presto naming pattern (current version matches Hive)
+            Pattern.compile("\\d{8}_\\d{6}_\\d{5}_[a-z0-9]{5}_bucket-(\\d+)(?:[-_.].*)?"),
+            // Hive naming pattern per `org.apache.hadoop.hive.ql.exec.Utilities#getBucketIdFromFile()`
+            Pattern.compile("(\\d+)_\\d+.*"),
+            // Hive ACID with optional direct insert attempt id
+            BUCKET_WITH_OPTIONAL_ATTEMPT_ID_PATTERN);
+
+    public static List<InputSplit> getPrunedSplitsByBuckets(
+            String tableName, List<InputSplit> splits, Set<Integer> buckets, int numBuckets) {
+        if (buckets == null) {
+            return splits;
+        }
+        if (buckets.size() == 0) {
+            return Collections.emptyList();
+        }
+        List<InputSplit> result = new LinkedList<>();
+        boolean valid = true;
+        for (InputSplit split : splits) {
+            String fileName = ((FileSplit) split).getPath().getName();
+            OptionalInt bucket = getBucketNumberFromPath(fileName);
+            if (bucket.isPresent()) {
+                int bucketId = bucket.getAsInt();
+                if (bucketId >= numBuckets) {
+                    valid = false;
+                    LOG.warn("Hive table {} is corrupt for file {}(bucketId={}), skip bucket pruning.",
+                            tableName, fileName, bucketId);
+                    break;
+                }
+                if (buckets.contains(bucketId)) {
+                    result.add(split);
+                }
+            } else {
+                valid = false;
+                LOG.warn("File {} is not a bucket file in hive table {}, skip bucket pruning.", fileName, tableName);

Review Comment:
   done



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/HiveBucketUtil.java:
##########
@@ -0,0 +1,394 @@
+// 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.doris.catalog;
+
+import org.apache.doris.analysis.BinaryPredicate;
+import org.apache.doris.analysis.CompoundPredicate;
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.analysis.InPredicate;
+import org.apache.doris.analysis.LiteralExpr;
+import org.apache.doris.analysis.SlotRef;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.thrift.TExprOpcode;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.ByteObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.ShortObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector;
+import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.InputSplit;
+import org.apache.hive.common.util.Murmur3;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.OptionalInt;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class HiveBucketUtil {
+    private static final Logger LOG = LogManager.getLogger(HiveBucketUtil.class);
+
+    private static final Set<PrimitiveType> SUPPORTED_TYPES_FOR_BUCKET_FILTER = ImmutableSet.of(
+            PrimitiveType.BOOLEAN,
+            PrimitiveType.TINYINT,
+            PrimitiveType.SMALLINT,
+            PrimitiveType.INT,
+            PrimitiveType.BIGINT,
+            PrimitiveType.STRING);
+
+    private static PrimitiveTypeInfo convertToHiveColType(PrimitiveType dorisType) throws DdlException {
+        switch (dorisType) {
+            case BOOLEAN:
+                return TypeInfoFactory.booleanTypeInfo;
+            case TINYINT:
+                return TypeInfoFactory.byteTypeInfo;
+            case SMALLINT:
+                return TypeInfoFactory.shortTypeInfo;
+            case INT:
+                return TypeInfoFactory.intTypeInfo;
+            case BIGINT:
+                return TypeInfoFactory.longTypeInfo;
+            case STRING:
+                return TypeInfoFactory.stringTypeInfo;
+            default:
+                throw new DdlException("Unsupported pruning bucket column type: " + dorisType);
+        }
+    }
+
+    private static final Pattern BUCKET_WITH_OPTIONAL_ATTEMPT_ID_PATTERN =
+            Pattern.compile("bucket_(\\d+)(_\\d+)?$");
+
+    private static final Iterable<Pattern> BUCKET_PATTERNS = ImmutableList.of(
+            // legacy Presto naming pattern (current version matches Hive)
+            Pattern.compile("\\d{8}_\\d{6}_\\d{5}_[a-z0-9]{5}_bucket-(\\d+)(?:[-_.].*)?"),
+            // Hive naming pattern per `org.apache.hadoop.hive.ql.exec.Utilities#getBucketIdFromFile()`
+            Pattern.compile("(\\d+)_\\d+.*"),
+            // Hive ACID with optional direct insert attempt id
+            BUCKET_WITH_OPTIONAL_ATTEMPT_ID_PATTERN);
+
+    public static List<InputSplit> getPrunedSplitsByBuckets(
+            String tableName, List<InputSplit> splits, Set<Integer> buckets, int numBuckets) {
+        if (buckets == null) {
+            return splits;
+        }
+        if (buckets.size() == 0) {
+            return Collections.emptyList();
+        }
+        List<InputSplit> result = new LinkedList<>();
+        boolean valid = true;
+        for (InputSplit split : splits) {
+            String fileName = ((FileSplit) split).getPath().getName();
+            OptionalInt bucket = getBucketNumberFromPath(fileName);
+            if (bucket.isPresent()) {
+                int bucketId = bucket.getAsInt();
+                if (bucketId >= numBuckets) {
+                    valid = false;
+                    LOG.warn("Hive table {} is corrupt for file {}(bucketId={}), skip bucket pruning.",
+                            tableName, fileName, bucketId);
+                    break;
+                }
+                if (buckets.contains(bucketId)) {
+                    result.add(split);
+                }
+            } else {
+                valid = false;
+                LOG.warn("File {} is not a bucket file in hive table {}, skip bucket pruning.", fileName, tableName);
+                break;
+            }
+        }
+        if (valid) {
+            LOG.info("{} / {} input splits in hive table {} after bucket pruning.",

Review Comment:
   done



##########
fe/fe-core/src/main/java/org/apache/doris/planner/external/ExternalHiveScanProvider.java:
##########
@@ -109,12 +112,22 @@ public List<InputSplit> getSplits(List<Expr> exprs)
 
         Configuration configuration = setConfiguration();
         InputFormat<?, ?> inputFormat = HiveUtil.getInputFormat(configuration, inputFormatName, false);
+        List<InputSplit> result;
         if (!hivePartitions.isEmpty()) {
-            return hivePartitions.parallelStream()
+            result = hivePartitions.parallelStream()
                     .flatMap(x -> getSplitsByPath(inputFormat, configuration, x.getSd().getLocation()).stream())
                     .collect(Collectors.toList());
         } else {
-            return getSplitsByPath(inputFormat, configuration, splitsPath);
+            result = getSplitsByPath(inputFormat, configuration, splitsPath);
+        }
+        Optional<Set<Integer>> prunedBuckets = HiveBucketUtil.getPrunedBuckets(

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.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] github-actions[bot] commented on pull request #11156: [feature-wip](multi-catalog) support pruning buckets for hive bucket table

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #11156:
URL: https://github.com/apache/doris/pull/11156#issuecomment-1196200722

   PR approved by at least one committer and no changes requested.


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org