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/05/24 06:33:18 UTC

[GitHub] [incubator-doris] dujl opened a new pull request, #9752: support query hudi external table

dujl opened a new pull request, #9752:
URL: https://github.com/apache/incubator-doris/pull/9752

   # Proposed changes
   
   Issue Number: https://github.com/apache/incubator-doris/issues/9557
   
   Support query hudi external table in Doris.
   This pr support query cow and mor hudi table.
   When hudi table is a mor table, only support read optimized query mode.
   
   This is the second pr to support hudi external table.
   
   ## Problem Summary:
   
   Describe the overview of changes.
   
   
   The propose of the pr is:
   support query cow and mor hudi table.
   
   ### Design
   
   1. generate scan range in Fe.
    Create a HudiScanNode to generate scan range parameters.
   HudiScanNode use HoodieParquetInputFormat to get all scan splits and assemble brokerRangeDesc
   2. Scan hudi data in Be.
   we use broker_scan_node to scan parquet files that send by fe.
   3. test case
   query mor table
   ```sql
   mysql> select * from t_hudi_mor;
   +---------------------+-----------------------+--------------------+------------------------+-----------------------------------------------------------------------------+------------+---------+-----------------------+----------------+
   | _hoodie_commit_time | _hoodie_commit_seqno  | _hoodie_record_key | _hoodie_partition_path | _hoodie_file_name                                                           | id         | name    | price                 | ts             |
   +---------------------+-----------------------+--------------------+------------------------+-----------------------------------------------------------------------------+------------+---------+-----------------------+----------------+
   | 20220522100249363   | 20220522100249363_0_1 | id:2               |                        | e9f6a051-2cfd-4cdd-94de-9d2d917dffb8-0_0-29-2007_20220522100249363.parquet  | -729382776 | b1      | 4.63779796443726e-310 | 93870075838632 |
   | 20220522100310109   | 20220522100310109_0_2 | id:3               |                        | e9f6a051-2cfd-4cdd-94de-9d2d917dffb8-0_0-77-4028_20220522100310109.parquet  | -729382456 | b1      | 4.63779796445307e-310 | 93870075838952 |
   | 20220522100324753   | 20220522100324753_0_3 | id:4               |                        | e9f6a051-2cfd-4cdd-94de-9d2d917dffb8-0_0-125-6049_20220522100324753.parquet | -729382136 | b1      | 4.63779796446888e-310 | 93870075839272 |
   | 20220522100339091   | 20220522100339091_0_4 | id:5               |                        | e9f6a051-2cfd-4cdd-94de-9d2d917dffb8-0_0-173-8070_20220522100339091.parquet | -729381816 | b1      | 4.63779796448469e-310 | 93870075839592 |
   | 20220522101838691   | 20220522101838691_0_1 | id:7               |                        | 018a955f-f1aa-4404-b997-e3abe72623fb-0_0-29-2009_20220522101838691.parquet  | -729382776 | insert1 | 4.63779796443726e-310 | 93870075838632 |
   | 20220522101838691   | 20220522101838691_0_2 | id:6               |                        | 018a955f-f1aa-4404-b997-e3abe72623fb-0_0-29-2009_20220522101838691.parquet  | -729382456 | insert2 | 4.63779796445307e-310 | 93870075838952 |
   | 20220520205326437   | 20220520205326437_0_2 | id:1               |                        | bbee0b74-9a04-45ae-b95d-12b448d82813-0_0-98-2079_20220520205326437.parquet  | -729382776 | a1      | 4.63779796443726e-310 | 93870075838632 |
   +---------------------+-----------------------+--------------------+------------------------+-----------------------------------------------------------------------------+------------+---------+-----------------------+----------------+
   ```
   query cow partition table
   ```sql
   mysql> select * from t_hudi_cow_partition;
   +---------------------+-----------------------+--------------------+------------------------+-----------------------------------------------------------------------------+------------+--------+------------+------------+
   | _hoodie_commit_time | _hoodie_commit_seqno  | _hoodie_record_key | _hoodie_partition_path | _hoodie_file_name                                                           | id         | name   | price      | ts         |
   +---------------------+-----------------------+--------------------+------------------------+-----------------------------------------------------------------------------+------------+--------+------------+------------+
   |                     | 20220520205249267_0_1 | id:1               | dt=2021-12-01          | b337c9d8-2088-4bfe-a30b-7923daa80958-0_0-3-0_20220520205249267.parquet      | 1827790992 | a1     | 1827791008 | 1878892656 |
   |                     | 20220522192232625_0_1 | id:2               | dt=2022-5-20           | c70f8bd0-7871-4fe6-95c4-6fb80ca83a5d-0_0-30-2008_20220522192232625.parquet  | -813514600 | name2  | -813514584 | -764204240 |
   |                     | 20220522192350827_0_2 | id:3               | dt=2022-5-21           | 27e3edf3-900f-45e9-adbc-b09d6b065aaf-0_0-82-4036_20220522192350827.parquet  | 1878843544 | name3  | 1878843560 | 1878892752 |
   |                     | 20220522192429630_0_3 | id:31              | dt=2022-5-21           | 27e3edf3-900f-45e9-adbc-b09d6b065aaf-0_0-137-6071_20220522192429630.parquet | 1878843856 | name31 | 1878843872 | 1878892752 |
   |                     | 20220522192557945_0_4 | id:41              | dt=2022-5-22           | 60c2d68c-3318-4896-9af1-54f63324bd48-0_0-193-8109_20220522192557945.parquet | -815062888 | name41 | -815062872 | -764204144 |
   |                     | 20220522192557945_1_5 | id:51              | dt=2022-5-23           | 913fe002-b5ba-4106-8894-34a25fe2dbb3-0_1-199-8110_20220522192557945.parquet | 1827791000 | name51 | 1827791016 | 1878892848 |
   +---------------------+-----------------------+--------------------+------------------------+-----------------------------------------------------------------------------+------------+--------+------------+------------+
   6 rows in set (0.83 sec)
   ```
   
   
   
   
   ## Checklist(Required)
   
   1. Does it affect the original behavior: (Yes/No/I Don't know)No
   5. Has unit tests been added: (Yes/No/No Need)No Need
   6. Has document been added or modified: (Yes/No/No Need)No Need
   7. Does it need to update dependencies: (Yes/No)Yes
   8. Are there any changes that cannot be rolled back: (Yes/No)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] [incubator-doris] Jibing-Li commented on a diff in pull request #9752: [feature](hudi) Step2: Support query hudi external table(include cow and mor table) #9559

Posted by GitBox <gi...@apache.org>.
Jibing-Li commented on code in PR #9752:
URL: https://github.com/apache/incubator-doris/pull/9752#discussion_r882739754


##########
fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java:
##########
@@ -626,6 +628,11 @@ public TableRef resolveTableRef(TableRef tableRef) throws AnalysisException {
             }
         }
 
+        if (table.getType() == TableType.HUDI && table.getFullSchema().isEmpty()) {
+            // resolve hudi table's schema when table schema is empty from doris meta

Review Comment:
   For case 2, the schema will be cached in HudiTable after the first time calling resolveHudiTable, but I didn't see the code to update the schema. So I feel when the schema in HMS changed, we are still using the old cached schema in the Doris Catalog. Correct me if I missed some details. 



-- 
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] [incubator-doris] morningman merged pull request #9752: [feature](hudi) Step2: Support query hudi external table(include cow and mor table)

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


-- 
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] [incubator-doris] Jibing-Li commented on a diff in pull request #9752: [feature](hudi) Step2: Support query hudi external table(include cow and mor table) #9559

Posted by GitBox <gi...@apache.org>.
Jibing-Li commented on code in PR #9752:
URL: https://github.com/apache/incubator-doris/pull/9752#discussion_r882424723


##########
fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java:
##########
@@ -626,6 +628,11 @@ public TableRef resolveTableRef(TableRef tableRef) throws AnalysisException {
             }
         }
 
+        if (table.getType() == TableType.HUDI && table.getFullSchema().isEmpty()) {
+            // resolve hudi table's schema when table schema is empty from doris meta

Review Comment:
   What if the schema changed in HMS? Can we keep the schema in Doris up to date?



-- 
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] [incubator-doris] dujl commented on a diff in pull request #9752: [feature](hudi) Step2: Support query hudi external table(include cow and mor table) #9559

Posted by GitBox <gi...@apache.org>.
dujl commented on code in PR #9752:
URL: https://github.com/apache/incubator-doris/pull/9752#discussion_r882594727


##########
fe/fe-core/src/main/java/org/apache/doris/planner/HudiScanNode.java:
##########
@@ -0,0 +1,372 @@
+// 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.planner;
+
+import org.apache.doris.analysis.Analyzer;
+import org.apache.doris.analysis.BrokerDesc;
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.analysis.ImportColumnDesc;
+import org.apache.doris.analysis.SlotDescriptor;
+import org.apache.doris.analysis.StorageBackend;
+import org.apache.doris.analysis.TupleDescriptor;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.HiveMetaStoreClientHelper;
+import org.apache.doris.catalog.PrimitiveType;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.BrokerUtil;
+import org.apache.doris.external.hive.util.HiveUtil;
+import org.apache.doris.external.hudi.HudiProperty;
+import org.apache.doris.external.hudi.HudiTable;
+import org.apache.doris.load.BrokerFileGroup;
+import org.apache.doris.thrift.TBrokerFileStatus;
+import org.apache.doris.thrift.TBrokerRangeDesc;
+import org.apache.doris.thrift.TBrokerScanRangeParams;
+import org.apache.doris.thrift.TExplainLevel;
+import org.apache.doris.thrift.TFileFormatType;
+import org.apache.doris.thrift.THdfsParams;
+import org.apache.doris.thrift.TScanRangeLocations;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.Partition;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
+import org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
+import org.apache.hadoop.mapred.FileInputFormat;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.InputFormat;
+import org.apache.hadoop.mapred.InputSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.mortbay.log.Log;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * Hudi scan node to query hudi table.
+ */
+public class HudiScanNode extends BrokerScanNode {
+    private static final Logger LOG = LogManager.getLogger(HudiScanNode.class);
+
+    private HudiTable hudiTable;
+    // partition column predicates of hive table
+    private List<ExprNodeDesc> hivePredicates = new ArrayList<>();
+    private ExprNodeGenericFuncDesc hivePartitionPredicate;
+    private List<ImportColumnDesc> parsedColumnExprList = new ArrayList<>();
+    private String hdfsUri;
+
+    private Table remoteHiveTable;
+
+    /* hudi table properties */
+    private String fileFormat;
+    private String inputFormatName;
+    private String basePath;
+    private List<String> partitionKeys = new ArrayList<>();
+    /* hudi table properties */
+
+    private List<TScanRangeLocations> scanRangeLocations;
+
+    public HudiScanNode(PlanNodeId id, TupleDescriptor destTupleDesc, String planNodeName,
+                        List<List<TBrokerFileStatus>> fileStatusesList, int filesAdded) {
+        super(id, destTupleDesc, planNodeName, fileStatusesList, filesAdded);
+        this.hudiTable = (HudiTable) destTupleDesc.getTable();
+    }
+
+    public String getHdfsUri() {
+        return hdfsUri;
+    }
+
+    public List<ImportColumnDesc> getParsedColumnExprList() {
+        return parsedColumnExprList;
+    }
+
+    public String getFileFormat() {
+        return fileFormat;
+    }
+
+    public String getBasePath() {
+        return basePath;
+    }
+
+    public List<String> getPartitionKeys() {
+        return partitionKeys;
+    }
+
+    /**
+     *  super init will invoke initFileGroup, In initFileGroup will do
+     *  1, get hudi table from hive metastore
+     *  2, resolve hudi table type, query mode, table base path, partition columns information.
+     *  3. generate fileGroup
+     *
+     * @param analyzer analyzer
+     * @throws UserException when init failed.
+     */
+    @Override
+    public void init(Analyzer analyzer) throws UserException {
+        super.init(analyzer);
+        // init scan range params
+        initParams(analyzer);
+    }
+
+    @Override
+    public int getNumInstances() {
+        return scanRangeLocations.size();
+    }
+
+    @Override
+    protected void initFileGroup() throws UserException {
+        resolvHiveTable();
+        analyzeColumnFromPath();
+
+        HudiTable hudiTable = (HudiTable) desc.getTable();
+        fileGroups = Lists.newArrayList(
+                new BrokerFileGroup(hudiTable.getId(),
+                        "\t",
+                        "\n",
+                        getBasePath(),
+                        getFileFormat(),
+                        getPartitionKeys(),
+                        getParsedColumnExprList()));
+        brokerDesc = new BrokerDesc("HudiTableDesc", StorageBackend.StorageType.HDFS, hudiTable.getTableProperties());
+
+    }
+
+    /**
+     * Override this function just for skip parent's getFileStatus.
+     */
+    @Override
+    protected void getFileStatus() throws DdlException {
+        if (partitionKeys.size() > 0) {
+            extractHivePartitionPredicate();
+        }
+        // set fileStatusesList as empty, we do not need fileStatusesList
+        fileStatusesList = Lists.newArrayList();
+        filesAdded = 0;
+    }
+
+    @Override
+    public void finalize(Analyzer analyzer) throws UserException {
+        try {
+            ParamCreateContext context = getParamCreateContexts().get(0);
+            finalizeParams(context.slotDescByName, context.exprMap, context.params,
+                    context.srcTupleDescriptor, false, context.fileGroup.isNegative(), analyzer);
+        } catch (AnalysisException e) {
+            throw new UserException(e.getMessage());
+        }
+        try {
+            buildScanRange();
+        } catch (IOException e) {
+            LOG.error("Build scan range failed.", e);
+            throw new UserException("Build scan range failed.", e);
+        }
+    }
+
+    @Override
+    public List<TScanRangeLocations> getScanRangeLocations(long maxScanRangeLength) {
+        return scanRangeLocations;
+    }
+
+    private void resolvHiveTable() throws DdlException {
+        this.remoteHiveTable = HiveMetaStoreClientHelper.getTable(
+                hudiTable.getHmsDatabaseName(),
+                hudiTable.getHmsTableName(),
+                hudiTable.getTableProperties().get(HudiProperty.HUDI_HIVE_METASTORE_URIS));
+
+        this.inputFormatName = remoteHiveTable.getSd().getInputFormat();
+        this.fileFormat = HiveMetaStoreClientHelper.HiveFileFormat.getFormat(this.inputFormatName);
+        this.basePath = remoteHiveTable.getSd().getLocation();
+        for (FieldSchema fieldSchema : remoteHiveTable.getPartitionKeys()) {
+            this.partitionKeys.add(fieldSchema.getName());
+        }
+        Log.info("Hudi inputFileFormat is " + inputFormatName + ", basePath is " + this.basePath);
+    }
+
+    private void initParams(Analyzer analyzer) {
+        ParamCreateContext context = getParamCreateContexts().get(0);
+        TBrokerScanRangeParams params = context.params;
+
+        Map<String, SlotDescriptor> slotDescByName = Maps.newHashMap();
+
+        List<Column> columns = hudiTable.getBaseSchema(false);
+        // init slot desc add expr map, also transform hadoop functions
+        for (Column column : columns) {
+            SlotDescriptor slotDesc = analyzer.getDescTbl().addSlotDescriptor(context.srcTupleDescriptor);
+            slotDesc.setType(ScalarType.createType(PrimitiveType.VARCHAR));
+            slotDesc.setIsMaterialized(true);
+            slotDesc.setIsNullable(true);
+            slotDesc.setColumn(new Column(column.getName(), PrimitiveType.VARCHAR));
+            params.addToSrcSlotIds(slotDesc.getId().asInt());
+            slotDescByName.put(column.getName(), slotDesc);
+        }
+        context.slotDescByName = slotDescByName;
+    }
+
+
+    /**
+     * Extracts partition predicate from SelectStmt.whereClause that can be pushed down to Hive.
+     */
+    private void extractHivePartitionPredicate() throws DdlException {
+        ListIterator<Expr> it = conjuncts.listIterator();
+        while (it.hasNext()) {
+            ExprNodeGenericFuncDesc hiveExpr = HiveMetaStoreClientHelper.convertToHivePartitionExpr(
+                    it.next(), partitionKeys, hudiTable.getName());
+            if (hiveExpr != null) {
+                hivePredicates.add(hiveExpr);
+            }
+        }
+        int count = hivePredicates.size();
+        // combine all predicate by `and`
+        // compoundExprs must have at least 2 predicates
+        if (count >= 2) {
+            hivePartitionPredicate = HiveMetaStoreClientHelper.getCompoundExpr(hivePredicates, "and");
+        } else if (count == 1) {
+            // only one predicate
+            hivePartitionPredicate = (ExprNodeGenericFuncDesc) hivePredicates.get(0);
+        } else {
+            // have no predicate, make a dummy predicate "1=1" to get all partitions
+            HiveMetaStoreClientHelper.ExprBuilder exprBuilder =
+                    new HiveMetaStoreClientHelper.ExprBuilder(hudiTable.getName());
+            hivePartitionPredicate = exprBuilder.val(TypeInfoFactory.intTypeInfo, 1)
+                    .val(TypeInfoFactory.intTypeInfo, 1)
+                    .pred("=", 2).build();
+        }
+    }
+
+    private InputSplit[] getSplits() throws UserException, IOException {
+        String splitsPath = basePath;
+        if (partitionKeys.size() > 0) {
+            extractHivePartitionPredicate();
+
+            String metaStoreUris = hudiTable.getTableProperties().get(HudiProperty.HUDI_HIVE_METASTORE_URIS);
+            List<Partition> hivePartitions =
+                    HiveMetaStoreClientHelper.getHivePartitions(metaStoreUris, remoteHiveTable, hivePartitionPredicate);
+            splitsPath = hivePartitions.stream()
+                    .map(x -> x.getSd().getLocation()).collect(Collectors.joining(","));
+        }
+
+
+        Configuration configuration = new Configuration();
+        InputFormat<?, ?> inputFormat = HiveUtil.getInputFormat(configuration, inputFormatName, false);
+        // alway get fileSplits from inputformat,
+        // because all hoodie input format have UseFileSplitsFromInputFormat annotation
+        JobConf jobConf = new JobConf(configuration);
+        FileInputFormat.setInputPaths(jobConf, splitsPath);
+        InputSplit[] inputSplits = inputFormat.getSplits(jobConf, 0);
+        return inputSplits;
+
+    }
+
+    // If fileFormat is not null, we use fileFormat instead of check file's suffix
+    protected void buildScanRange() throws UserException, IOException {
+        scanRangeLocations = Lists.newArrayList();
+        InputSplit[] inputSplits = getSplits();
+        if (inputSplits.length == 0) {
+            return;
+        }
+
+        THdfsParams hdfsParams = new THdfsParams();
+        String fullPath = ((FileSplit) inputSplits[0]).getPath().toUri().toString();
+        String filePath = ((FileSplit) inputSplits[0]).getPath().toUri().getPath();
+        String fsName = fullPath.replace(filePath, "");
+        hdfsParams.setFsName(fsName);
+        Log.info("Hudi  path's host is  " + fsName);
+
+        TFileFormatType formatType = TFileFormatType.FORMAT_PARQUET;

Review Comment:
   hudi have two type files:  base file and log file, base file is parquet type and log file is avro type.
   anyway, formattype will decided by inputformat className, current it will only be parquet.



-- 
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] [incubator-doris] github-actions[bot] commented on pull request #9752: [feature](hudi) Step2: Support query hudi external table(include cow and mor table)

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

   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


[GitHub] [incubator-doris] github-actions[bot] commented on pull request #9752: [feature](hudi) Step2: Support query hudi external table(include cow and mor table) #9559

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

   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] [incubator-doris] dujl commented on a diff in pull request #9752: [feature](hudi) Step2: Support query hudi external table(include cow and mor table) #9559

Posted by GitBox <gi...@apache.org>.
dujl commented on code in PR #9752:
URL: https://github.com/apache/incubator-doris/pull/9752#discussion_r883303313


##########
fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java:
##########
@@ -626,6 +628,11 @@ public TableRef resolveTableRef(TableRef tableRef) throws AnalysisException {
             }
         }
 
+        if (table.getType() == TableType.HUDI && table.getFullSchema().isEmpty()) {
+            // resolve hudi table's schema when table schema is empty from doris meta

Review Comment:
   @Jibing-Li fix it, please check again.
   resolve table from hms didn't change table cache in database



-- 
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] [incubator-doris] dujl commented on a diff in pull request #9752: [feature](hudi) Step2: Support query hudi external table(include cow and mor table) #9559

Posted by GitBox <gi...@apache.org>.
dujl commented on code in PR #9752:
URL: https://github.com/apache/incubator-doris/pull/9752#discussion_r883303313


##########
fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java:
##########
@@ -626,6 +628,11 @@ public TableRef resolveTableRef(TableRef tableRef) throws AnalysisException {
             }
         }
 
+        if (table.getType() == TableType.HUDI && table.getFullSchema().isEmpty()) {
+            // resolve hudi table's schema when table schema is empty from doris meta

Review Comment:
   @Jibing-Li fix it, please check again



-- 
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] [incubator-doris] dujl commented on a diff in pull request #9752: [feature](hudi) Step2: Support query hudi external table(include cow and mor table) #9559

Posted by GitBox <gi...@apache.org>.
dujl commented on code in PR #9752:
URL: https://github.com/apache/incubator-doris/pull/9752#discussion_r882576583


##########
fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java:
##########
@@ -626,6 +628,11 @@ public TableRef resolveTableRef(TableRef tableRef) throws AnalysisException {
             }
         }
 
+        if (table.getType() == TableType.HUDI && table.getFullSchema().isEmpty()) {
+            // resolve hudi table's schema when table schema is empty from doris meta

Review Comment:
   two case:
   1. create hudi table with schema. when table schema has been changed in HMS,all hudi table's schema are not lost in HMS,query successful. if some field has been renamed or drop in HMS, query failed.
   2. create a hudi table without schema. when table schema has been changed in HMS, it will resolve schema from hms when query. 



-- 
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] [incubator-doris] Jibing-Li commented on a diff in pull request #9752: [feature](hudi) Step2: Support query hudi external table(include cow and mor table) #9559

Posted by GitBox <gi...@apache.org>.
Jibing-Li commented on code in PR #9752:
URL: https://github.com/apache/incubator-doris/pull/9752#discussion_r884061876


##########
fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java:
##########
@@ -626,6 +628,11 @@ public TableRef resolveTableRef(TableRef tableRef) throws AnalysisException {
             }
         }
 
+        if (table.getType() == TableType.HUDI && table.getFullSchema().isEmpty()) {
+            // resolve hudi table's schema when table schema is empty from doris meta

Review Comment:
   LGTM. We can find a better cache mechanism later.



-- 
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] [incubator-doris] morningman commented on a diff in pull request #9752: [feature](hudi) Step2: Support query hudi external table(include cow and mor table) #9559

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


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java:
##########
@@ -4142,6 +4142,15 @@ private void createHudiTable(Database db, CreateTableStmt stmt) throws DdlExcept
         if (!hudiTable.getFullSchema().isEmpty()) {
             HudiUtils.validateColumns(hudiTable, hiveTable);
         }
+        switch (hiveTable.getTableType()) {
+            case "VIRTUAL_VIEW":

Review Comment:
   This case can be merged into `default`?



##########
fe/fe-core/src/main/java/org/apache/doris/planner/HudiScanNode.java:
##########
@@ -0,0 +1,372 @@
+// 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.planner;
+
+import org.apache.doris.analysis.Analyzer;
+import org.apache.doris.analysis.BrokerDesc;
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.analysis.ImportColumnDesc;
+import org.apache.doris.analysis.SlotDescriptor;
+import org.apache.doris.analysis.StorageBackend;
+import org.apache.doris.analysis.TupleDescriptor;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.HiveMetaStoreClientHelper;
+import org.apache.doris.catalog.PrimitiveType;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.BrokerUtil;
+import org.apache.doris.external.hive.util.HiveUtil;
+import org.apache.doris.external.hudi.HudiProperty;
+import org.apache.doris.external.hudi.HudiTable;
+import org.apache.doris.load.BrokerFileGroup;
+import org.apache.doris.thrift.TBrokerFileStatus;
+import org.apache.doris.thrift.TBrokerRangeDesc;
+import org.apache.doris.thrift.TBrokerScanRangeParams;
+import org.apache.doris.thrift.TExplainLevel;
+import org.apache.doris.thrift.TFileFormatType;
+import org.apache.doris.thrift.THdfsParams;
+import org.apache.doris.thrift.TScanRangeLocations;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.Partition;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
+import org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
+import org.apache.hadoop.mapred.FileInputFormat;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.InputFormat;
+import org.apache.hadoop.mapred.InputSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.mortbay.log.Log;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * Hudi scan node to query hudi table.
+ */
+public class HudiScanNode extends BrokerScanNode {
+    private static final Logger LOG = LogManager.getLogger(HudiScanNode.class);
+
+    private HudiTable hudiTable;
+    // partition column predicates of hive table
+    private List<ExprNodeDesc> hivePredicates = new ArrayList<>();
+    private ExprNodeGenericFuncDesc hivePartitionPredicate;
+    private List<ImportColumnDesc> parsedColumnExprList = new ArrayList<>();
+    private String hdfsUri;
+
+    private Table remoteHiveTable;
+
+    /* hudi table properties */
+    private String fileFormat;
+    private String inputFormatName;
+    private String basePath;
+    private List<String> partitionKeys = new ArrayList<>();
+    /* hudi table properties */
+
+    private List<TScanRangeLocations> scanRangeLocations;
+
+    public HudiScanNode(PlanNodeId id, TupleDescriptor destTupleDesc, String planNodeName,
+                        List<List<TBrokerFileStatus>> fileStatusesList, int filesAdded) {
+        super(id, destTupleDesc, planNodeName, fileStatusesList, filesAdded);
+        this.hudiTable = (HudiTable) destTupleDesc.getTable();
+    }
+
+    public String getHdfsUri() {
+        return hdfsUri;
+    }
+
+    public List<ImportColumnDesc> getParsedColumnExprList() {
+        return parsedColumnExprList;
+    }
+
+    public String getFileFormat() {
+        return fileFormat;
+    }
+
+    public String getBasePath() {
+        return basePath;
+    }
+
+    public List<String> getPartitionKeys() {
+        return partitionKeys;
+    }
+
+    /**
+     *  super init will invoke initFileGroup, In initFileGroup will do
+     *  1, get hudi table from hive metastore
+     *  2, resolve hudi table type, query mode, table base path, partition columns information.
+     *  3. generate fileGroup
+     *
+     * @param analyzer analyzer
+     * @throws UserException when init failed.
+     */
+    @Override
+    public void init(Analyzer analyzer) throws UserException {
+        super.init(analyzer);
+        // init scan range params
+        initParams(analyzer);
+    }
+
+    @Override
+    public int getNumInstances() {
+        return scanRangeLocations.size();
+    }
+
+    @Override
+    protected void initFileGroup() throws UserException {
+        resolvHiveTable();
+        analyzeColumnFromPath();
+
+        HudiTable hudiTable = (HudiTable) desc.getTable();
+        fileGroups = Lists.newArrayList(
+                new BrokerFileGroup(hudiTable.getId(),
+                        "\t",
+                        "\n",
+                        getBasePath(),
+                        getFileFormat(),
+                        getPartitionKeys(),
+                        getParsedColumnExprList()));
+        brokerDesc = new BrokerDesc("HudiTableDesc", StorageBackend.StorageType.HDFS, hudiTable.getTableProperties());
+
+    }
+
+    /**
+     * Override this function just for skip parent's getFileStatus.
+     */
+    @Override
+    protected void getFileStatus() throws DdlException {
+        if (partitionKeys.size() > 0) {
+            extractHivePartitionPredicate();
+        }
+        // set fileStatusesList as empty, we do not need fileStatusesList
+        fileStatusesList = Lists.newArrayList();
+        filesAdded = 0;
+    }
+
+    @Override
+    public void finalize(Analyzer analyzer) throws UserException {
+        try {
+            ParamCreateContext context = getParamCreateContexts().get(0);
+            finalizeParams(context.slotDescByName, context.exprMap, context.params,
+                    context.srcTupleDescriptor, false, context.fileGroup.isNegative(), analyzer);
+        } catch (AnalysisException e) {
+            throw new UserException(e.getMessage());
+        }
+        try {
+            buildScanRange();
+        } catch (IOException e) {
+            LOG.error("Build scan range failed.", e);
+            throw new UserException("Build scan range failed.", e);
+        }
+    }
+
+    @Override
+    public List<TScanRangeLocations> getScanRangeLocations(long maxScanRangeLength) {
+        return scanRangeLocations;
+    }
+
+    private void resolvHiveTable() throws DdlException {
+        this.remoteHiveTable = HiveMetaStoreClientHelper.getTable(
+                hudiTable.getHmsDatabaseName(),
+                hudiTable.getHmsTableName(),
+                hudiTable.getTableProperties().get(HudiProperty.HUDI_HIVE_METASTORE_URIS));
+
+        this.inputFormatName = remoteHiveTable.getSd().getInputFormat();
+        this.fileFormat = HiveMetaStoreClientHelper.HiveFileFormat.getFormat(this.inputFormatName);
+        this.basePath = remoteHiveTable.getSd().getLocation();
+        for (FieldSchema fieldSchema : remoteHiveTable.getPartitionKeys()) {
+            this.partitionKeys.add(fieldSchema.getName());
+        }
+        Log.info("Hudi inputFileFormat is " + inputFormatName + ", basePath is " + this.basePath);
+    }
+
+    private void initParams(Analyzer analyzer) {
+        ParamCreateContext context = getParamCreateContexts().get(0);
+        TBrokerScanRangeParams params = context.params;
+
+        Map<String, SlotDescriptor> slotDescByName = Maps.newHashMap();
+
+        List<Column> columns = hudiTable.getBaseSchema(false);
+        // init slot desc add expr map, also transform hadoop functions
+        for (Column column : columns) {
+            SlotDescriptor slotDesc = analyzer.getDescTbl().addSlotDescriptor(context.srcTupleDescriptor);
+            slotDesc.setType(ScalarType.createType(PrimitiveType.VARCHAR));
+            slotDesc.setIsMaterialized(true);
+            slotDesc.setIsNullable(true);
+            slotDesc.setColumn(new Column(column.getName(), PrimitiveType.VARCHAR));
+            params.addToSrcSlotIds(slotDesc.getId().asInt());
+            slotDescByName.put(column.getName(), slotDesc);
+        }
+        context.slotDescByName = slotDescByName;
+    }
+
+
+    /**
+     * Extracts partition predicate from SelectStmt.whereClause that can be pushed down to Hive.
+     */
+    private void extractHivePartitionPredicate() throws DdlException {
+        ListIterator<Expr> it = conjuncts.listIterator();
+        while (it.hasNext()) {
+            ExprNodeGenericFuncDesc hiveExpr = HiveMetaStoreClientHelper.convertToHivePartitionExpr(
+                    it.next(), partitionKeys, hudiTable.getName());
+            if (hiveExpr != null) {
+                hivePredicates.add(hiveExpr);
+            }
+        }
+        int count = hivePredicates.size();
+        // combine all predicate by `and`
+        // compoundExprs must have at least 2 predicates
+        if (count >= 2) {
+            hivePartitionPredicate = HiveMetaStoreClientHelper.getCompoundExpr(hivePredicates, "and");
+        } else if (count == 1) {
+            // only one predicate
+            hivePartitionPredicate = (ExprNodeGenericFuncDesc) hivePredicates.get(0);
+        } else {
+            // have no predicate, make a dummy predicate "1=1" to get all partitions
+            HiveMetaStoreClientHelper.ExprBuilder exprBuilder =
+                    new HiveMetaStoreClientHelper.ExprBuilder(hudiTable.getName());
+            hivePartitionPredicate = exprBuilder.val(TypeInfoFactory.intTypeInfo, 1)
+                    .val(TypeInfoFactory.intTypeInfo, 1)
+                    .pred("=", 2).build();
+        }
+    }
+
+    private InputSplit[] getSplits() throws UserException, IOException {
+        String splitsPath = basePath;
+        if (partitionKeys.size() > 0) {
+            extractHivePartitionPredicate();
+
+            String metaStoreUris = hudiTable.getTableProperties().get(HudiProperty.HUDI_HIVE_METASTORE_URIS);
+            List<Partition> hivePartitions =
+                    HiveMetaStoreClientHelper.getHivePartitions(metaStoreUris, remoteHiveTable, hivePartitionPredicate);
+            splitsPath = hivePartitions.stream()
+                    .map(x -> x.getSd().getLocation()).collect(Collectors.joining(","));
+        }
+
+
+        Configuration configuration = new Configuration();
+        InputFormat<?, ?> inputFormat = HiveUtil.getInputFormat(configuration, inputFormatName, false);
+        // alway get fileSplits from inputformat,
+        // because all hoodie input format have UseFileSplitsFromInputFormat annotation
+        JobConf jobConf = new JobConf(configuration);
+        FileInputFormat.setInputPaths(jobConf, splitsPath);
+        InputSplit[] inputSplits = inputFormat.getSplits(jobConf, 0);
+        return inputSplits;
+
+    }
+
+    // If fileFormat is not null, we use fileFormat instead of check file's suffix
+    protected void buildScanRange() throws UserException, IOException {
+        scanRangeLocations = Lists.newArrayList();
+        InputSplit[] inputSplits = getSplits();
+        if (inputSplits.length == 0) {
+            return;
+        }
+
+        THdfsParams hdfsParams = new THdfsParams();
+        String fullPath = ((FileSplit) inputSplits[0]).getPath().toUri().toString();
+        String filePath = ((FileSplit) inputSplits[0]).getPath().toUri().getPath();
+        String fsName = fullPath.replace(filePath, "");
+        hdfsParams.setFsName(fsName);
+        Log.info("Hudi  path's host is  " + fsName);
+
+        TFileFormatType formatType = TFileFormatType.FORMAT_PARQUET;

Review Comment:
   Only support parquet?
   And I think the file type should be got from HMS?



##########
fe/fe-core/src/main/java/org/apache/doris/planner/HudiScanNode.java:
##########
@@ -0,0 +1,372 @@
+// 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.planner;
+
+import org.apache.doris.analysis.Analyzer;
+import org.apache.doris.analysis.BrokerDesc;
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.analysis.ImportColumnDesc;
+import org.apache.doris.analysis.SlotDescriptor;
+import org.apache.doris.analysis.StorageBackend;
+import org.apache.doris.analysis.TupleDescriptor;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.HiveMetaStoreClientHelper;
+import org.apache.doris.catalog.PrimitiveType;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.BrokerUtil;
+import org.apache.doris.external.hive.util.HiveUtil;
+import org.apache.doris.external.hudi.HudiProperty;
+import org.apache.doris.external.hudi.HudiTable;
+import org.apache.doris.load.BrokerFileGroup;
+import org.apache.doris.thrift.TBrokerFileStatus;
+import org.apache.doris.thrift.TBrokerRangeDesc;
+import org.apache.doris.thrift.TBrokerScanRangeParams;
+import org.apache.doris.thrift.TExplainLevel;
+import org.apache.doris.thrift.TFileFormatType;
+import org.apache.doris.thrift.THdfsParams;
+import org.apache.doris.thrift.TScanRangeLocations;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.Partition;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
+import org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
+import org.apache.hadoop.mapred.FileInputFormat;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.InputFormat;
+import org.apache.hadoop.mapred.InputSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.mortbay.log.Log;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * Hudi scan node to query hudi table.
+ */
+public class HudiScanNode extends BrokerScanNode {
+    private static final Logger LOG = LogManager.getLogger(HudiScanNode.class);
+
+    private HudiTable hudiTable;
+    // partition column predicates of hive table
+    private List<ExprNodeDesc> hivePredicates = new ArrayList<>();
+    private ExprNodeGenericFuncDesc hivePartitionPredicate;
+    private List<ImportColumnDesc> parsedColumnExprList = new ArrayList<>();
+    private String hdfsUri;
+
+    private Table remoteHiveTable;
+
+    /* hudi table properties */
+    private String fileFormat;
+    private String inputFormatName;
+    private String basePath;
+    private List<String> partitionKeys = new ArrayList<>();
+    /* hudi table properties */
+
+    private List<TScanRangeLocations> scanRangeLocations;
+
+    public HudiScanNode(PlanNodeId id, TupleDescriptor destTupleDesc, String planNodeName,
+                        List<List<TBrokerFileStatus>> fileStatusesList, int filesAdded) {
+        super(id, destTupleDesc, planNodeName, fileStatusesList, filesAdded);
+        this.hudiTable = (HudiTable) destTupleDesc.getTable();
+    }
+
+    public String getHdfsUri() {
+        return hdfsUri;
+    }
+
+    public List<ImportColumnDesc> getParsedColumnExprList() {
+        return parsedColumnExprList;
+    }
+
+    public String getFileFormat() {
+        return fileFormat;
+    }
+
+    public String getBasePath() {
+        return basePath;
+    }
+
+    public List<String> getPartitionKeys() {
+        return partitionKeys;
+    }
+
+    /**
+     *  super init will invoke initFileGroup, In initFileGroup will do
+     *  1, get hudi table from hive metastore
+     *  2, resolve hudi table type, query mode, table base path, partition columns information.
+     *  3. generate fileGroup
+     *
+     * @param analyzer analyzer
+     * @throws UserException when init failed.
+     */
+    @Override
+    public void init(Analyzer analyzer) throws UserException {
+        super.init(analyzer);
+        // init scan range params
+        initParams(analyzer);
+    }
+
+    @Override
+    public int getNumInstances() {
+        return scanRangeLocations.size();
+    }
+
+    @Override
+    protected void initFileGroup() throws UserException {
+        resolvHiveTable();
+        analyzeColumnFromPath();
+
+        HudiTable hudiTable = (HudiTable) desc.getTable();
+        fileGroups = Lists.newArrayList(
+                new BrokerFileGroup(hudiTable.getId(),
+                        "\t",
+                        "\n",
+                        getBasePath(),
+                        getFileFormat(),
+                        getPartitionKeys(),
+                        getParsedColumnExprList()));
+        brokerDesc = new BrokerDesc("HudiTableDesc", StorageBackend.StorageType.HDFS, hudiTable.getTableProperties());
+
+    }
+
+    /**
+     * Override this function just for skip parent's getFileStatus.
+     */
+    @Override
+    protected void getFileStatus() throws DdlException {
+        if (partitionKeys.size() > 0) {
+            extractHivePartitionPredicate();
+        }
+        // set fileStatusesList as empty, we do not need fileStatusesList
+        fileStatusesList = Lists.newArrayList();
+        filesAdded = 0;
+    }
+
+    @Override
+    public void finalize(Analyzer analyzer) throws UserException {
+        try {
+            ParamCreateContext context = getParamCreateContexts().get(0);
+            finalizeParams(context.slotDescByName, context.exprMap, context.params,
+                    context.srcTupleDescriptor, false, context.fileGroup.isNegative(), analyzer);
+        } catch (AnalysisException e) {
+            throw new UserException(e.getMessage());
+        }
+        try {
+            buildScanRange();
+        } catch (IOException e) {
+            LOG.error("Build scan range failed.", e);
+            throw new UserException("Build scan range failed.", e);
+        }
+    }
+
+    @Override
+    public List<TScanRangeLocations> getScanRangeLocations(long maxScanRangeLength) {
+        return scanRangeLocations;
+    }
+
+    private void resolvHiveTable() throws DdlException {
+        this.remoteHiveTable = HiveMetaStoreClientHelper.getTable(
+                hudiTable.getHmsDatabaseName(),
+                hudiTable.getHmsTableName(),
+                hudiTable.getTableProperties().get(HudiProperty.HUDI_HIVE_METASTORE_URIS));
+
+        this.inputFormatName = remoteHiveTable.getSd().getInputFormat();
+        this.fileFormat = HiveMetaStoreClientHelper.HiveFileFormat.getFormat(this.inputFormatName);
+        this.basePath = remoteHiveTable.getSd().getLocation();
+        for (FieldSchema fieldSchema : remoteHiveTable.getPartitionKeys()) {
+            this.partitionKeys.add(fieldSchema.getName());
+        }
+        Log.info("Hudi inputFileFormat is " + inputFormatName + ", basePath is " + this.basePath);
+    }
+
+    private void initParams(Analyzer analyzer) {
+        ParamCreateContext context = getParamCreateContexts().get(0);
+        TBrokerScanRangeParams params = context.params;
+
+        Map<String, SlotDescriptor> slotDescByName = Maps.newHashMap();
+
+        List<Column> columns = hudiTable.getBaseSchema(false);
+        // init slot desc add expr map, also transform hadoop functions
+        for (Column column : columns) {
+            SlotDescriptor slotDesc = analyzer.getDescTbl().addSlotDescriptor(context.srcTupleDescriptor);
+            slotDesc.setType(ScalarType.createType(PrimitiveType.VARCHAR));
+            slotDesc.setIsMaterialized(true);
+            slotDesc.setIsNullable(true);
+            slotDesc.setColumn(new Column(column.getName(), PrimitiveType.VARCHAR));
+            params.addToSrcSlotIds(slotDesc.getId().asInt());
+            slotDescByName.put(column.getName(), slotDesc);
+        }
+        context.slotDescByName = slotDescByName;
+    }
+
+
+    /**
+     * Extracts partition predicate from SelectStmt.whereClause that can be pushed down to Hive.
+     */
+    private void extractHivePartitionPredicate() throws DdlException {
+        ListIterator<Expr> it = conjuncts.listIterator();
+        while (it.hasNext()) {
+            ExprNodeGenericFuncDesc hiveExpr = HiveMetaStoreClientHelper.convertToHivePartitionExpr(
+                    it.next(), partitionKeys, hudiTable.getName());
+            if (hiveExpr != null) {
+                hivePredicates.add(hiveExpr);
+            }
+        }
+        int count = hivePredicates.size();
+        // combine all predicate by `and`
+        // compoundExprs must have at least 2 predicates
+        if (count >= 2) {
+            hivePartitionPredicate = HiveMetaStoreClientHelper.getCompoundExpr(hivePredicates, "and");
+        } else if (count == 1) {
+            // only one predicate
+            hivePartitionPredicate = (ExprNodeGenericFuncDesc) hivePredicates.get(0);
+        } else {
+            // have no predicate, make a dummy predicate "1=1" to get all partitions
+            HiveMetaStoreClientHelper.ExprBuilder exprBuilder =
+                    new HiveMetaStoreClientHelper.ExprBuilder(hudiTable.getName());
+            hivePartitionPredicate = exprBuilder.val(TypeInfoFactory.intTypeInfo, 1)
+                    .val(TypeInfoFactory.intTypeInfo, 1)
+                    .pred("=", 2).build();
+        }
+    }
+
+    private InputSplit[] getSplits() throws UserException, IOException {
+        String splitsPath = basePath;
+        if (partitionKeys.size() > 0) {
+            extractHivePartitionPredicate();
+
+            String metaStoreUris = hudiTable.getTableProperties().get(HudiProperty.HUDI_HIVE_METASTORE_URIS);
+            List<Partition> hivePartitions =
+                    HiveMetaStoreClientHelper.getHivePartitions(metaStoreUris, remoteHiveTable, hivePartitionPredicate);
+            splitsPath = hivePartitions.stream()
+                    .map(x -> x.getSd().getLocation()).collect(Collectors.joining(","));
+        }
+
+
+        Configuration configuration = new Configuration();
+        InputFormat<?, ?> inputFormat = HiveUtil.getInputFormat(configuration, inputFormatName, false);
+        // alway get fileSplits from inputformat,
+        // because all hoodie input format have UseFileSplitsFromInputFormat annotation
+        JobConf jobConf = new JobConf(configuration);
+        FileInputFormat.setInputPaths(jobConf, splitsPath);
+        InputSplit[] inputSplits = inputFormat.getSplits(jobConf, 0);
+        return inputSplits;
+
+    }
+
+    // If fileFormat is not null, we use fileFormat instead of check file's suffix
+    protected void buildScanRange() throws UserException, IOException {
+        scanRangeLocations = Lists.newArrayList();
+        InputSplit[] inputSplits = getSplits();
+        if (inputSplits.length == 0) {
+            return;
+        }
+
+        THdfsParams hdfsParams = new THdfsParams();
+        String fullPath = ((FileSplit) inputSplits[0]).getPath().toUri().toString();
+        String filePath = ((FileSplit) inputSplits[0]).getPath().toUri().getPath();
+        String fsName = fullPath.replace(filePath, "");
+        hdfsParams.setFsName(fsName);
+        Log.info("Hudi  path's host is  " + fsName);

Review Comment:
   ```
   Log.debug("Hudi path's host is " + fsName);
   ```
   



##########
fe/fe-core/src/main/java/org/apache/doris/planner/HudiScanNode.java:
##########
@@ -0,0 +1,372 @@
+// 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.planner;
+
+import org.apache.doris.analysis.Analyzer;
+import org.apache.doris.analysis.BrokerDesc;
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.analysis.ImportColumnDesc;
+import org.apache.doris.analysis.SlotDescriptor;
+import org.apache.doris.analysis.StorageBackend;
+import org.apache.doris.analysis.TupleDescriptor;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.HiveMetaStoreClientHelper;
+import org.apache.doris.catalog.PrimitiveType;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.BrokerUtil;
+import org.apache.doris.external.hive.util.HiveUtil;
+import org.apache.doris.external.hudi.HudiProperty;
+import org.apache.doris.external.hudi.HudiTable;
+import org.apache.doris.load.BrokerFileGroup;
+import org.apache.doris.thrift.TBrokerFileStatus;
+import org.apache.doris.thrift.TBrokerRangeDesc;
+import org.apache.doris.thrift.TBrokerScanRangeParams;
+import org.apache.doris.thrift.TExplainLevel;
+import org.apache.doris.thrift.TFileFormatType;
+import org.apache.doris.thrift.THdfsParams;
+import org.apache.doris.thrift.TScanRangeLocations;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.Partition;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
+import org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
+import org.apache.hadoop.mapred.FileInputFormat;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.InputFormat;
+import org.apache.hadoop.mapred.InputSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.mortbay.log.Log;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * Hudi scan node to query hudi table.
+ */
+public class HudiScanNode extends BrokerScanNode {
+    private static final Logger LOG = LogManager.getLogger(HudiScanNode.class);
+
+    private HudiTable hudiTable;
+    // partition column predicates of hive table
+    private List<ExprNodeDesc> hivePredicates = new ArrayList<>();
+    private ExprNodeGenericFuncDesc hivePartitionPredicate;
+    private List<ImportColumnDesc> parsedColumnExprList = new ArrayList<>();
+    private String hdfsUri;
+
+    private Table remoteHiveTable;
+
+    /* hudi table properties */
+    private String fileFormat;
+    private String inputFormatName;
+    private String basePath;
+    private List<String> partitionKeys = new ArrayList<>();
+    /* hudi table properties */
+
+    private List<TScanRangeLocations> scanRangeLocations;
+
+    public HudiScanNode(PlanNodeId id, TupleDescriptor destTupleDesc, String planNodeName,
+                        List<List<TBrokerFileStatus>> fileStatusesList, int filesAdded) {
+        super(id, destTupleDesc, planNodeName, fileStatusesList, filesAdded);
+        this.hudiTable = (HudiTable) destTupleDesc.getTable();
+    }
+
+    public String getHdfsUri() {
+        return hdfsUri;
+    }
+
+    public List<ImportColumnDesc> getParsedColumnExprList() {
+        return parsedColumnExprList;
+    }
+
+    public String getFileFormat() {
+        return fileFormat;
+    }
+
+    public String getBasePath() {
+        return basePath;
+    }
+
+    public List<String> getPartitionKeys() {
+        return partitionKeys;
+    }
+
+    /**
+     *  super init will invoke initFileGroup, In initFileGroup will do
+     *  1, get hudi table from hive metastore
+     *  2, resolve hudi table type, query mode, table base path, partition columns information.
+     *  3. generate fileGroup
+     *
+     * @param analyzer analyzer
+     * @throws UserException when init failed.
+     */
+    @Override
+    public void init(Analyzer analyzer) throws UserException {
+        super.init(analyzer);
+        // init scan range params
+        initParams(analyzer);
+    }
+
+    @Override
+    public int getNumInstances() {
+        return scanRangeLocations.size();
+    }
+
+    @Override
+    protected void initFileGroup() throws UserException {
+        resolvHiveTable();
+        analyzeColumnFromPath();
+
+        HudiTable hudiTable = (HudiTable) desc.getTable();
+        fileGroups = Lists.newArrayList(
+                new BrokerFileGroup(hudiTable.getId(),
+                        "\t",
+                        "\n",
+                        getBasePath(),
+                        getFileFormat(),
+                        getPartitionKeys(),
+                        getParsedColumnExprList()));
+        brokerDesc = new BrokerDesc("HudiTableDesc", StorageBackend.StorageType.HDFS, hudiTable.getTableProperties());
+
+    }
+
+    /**
+     * Override this function just for skip parent's getFileStatus.
+     */
+    @Override
+    protected void getFileStatus() throws DdlException {
+        if (partitionKeys.size() > 0) {
+            extractHivePartitionPredicate();
+        }
+        // set fileStatusesList as empty, we do not need fileStatusesList
+        fileStatusesList = Lists.newArrayList();
+        filesAdded = 0;
+    }
+
+    @Override
+    public void finalize(Analyzer analyzer) throws UserException {
+        try {
+            ParamCreateContext context = getParamCreateContexts().get(0);
+            finalizeParams(context.slotDescByName, context.exprMap, context.params,
+                    context.srcTupleDescriptor, false, context.fileGroup.isNegative(), analyzer);
+        } catch (AnalysisException e) {
+            throw new UserException(e.getMessage());
+        }
+        try {
+            buildScanRange();
+        } catch (IOException e) {
+            LOG.error("Build scan range failed.", e);
+            throw new UserException("Build scan range failed.", e);
+        }
+    }
+
+    @Override
+    public List<TScanRangeLocations> getScanRangeLocations(long maxScanRangeLength) {
+        return scanRangeLocations;
+    }
+
+    private void resolvHiveTable() throws DdlException {
+        this.remoteHiveTable = HiveMetaStoreClientHelper.getTable(
+                hudiTable.getHmsDatabaseName(),
+                hudiTable.getHmsTableName(),
+                hudiTable.getTableProperties().get(HudiProperty.HUDI_HIVE_METASTORE_URIS));
+
+        this.inputFormatName = remoteHiveTable.getSd().getInputFormat();
+        this.fileFormat = HiveMetaStoreClientHelper.HiveFileFormat.getFormat(this.inputFormatName);
+        this.basePath = remoteHiveTable.getSd().getLocation();
+        for (FieldSchema fieldSchema : remoteHiveTable.getPartitionKeys()) {
+            this.partitionKeys.add(fieldSchema.getName());
+        }
+        Log.info("Hudi inputFileFormat is " + inputFormatName + ", basePath is " + this.basePath);
+    }
+
+    private void initParams(Analyzer analyzer) {
+        ParamCreateContext context = getParamCreateContexts().get(0);
+        TBrokerScanRangeParams params = context.params;
+
+        Map<String, SlotDescriptor> slotDescByName = Maps.newHashMap();
+
+        List<Column> columns = hudiTable.getBaseSchema(false);
+        // init slot desc add expr map, also transform hadoop functions
+        for (Column column : columns) {
+            SlotDescriptor slotDesc = analyzer.getDescTbl().addSlotDescriptor(context.srcTupleDescriptor);
+            slotDesc.setType(ScalarType.createType(PrimitiveType.VARCHAR));
+            slotDesc.setIsMaterialized(true);
+            slotDesc.setIsNullable(true);
+            slotDesc.setColumn(new Column(column.getName(), PrimitiveType.VARCHAR));
+            params.addToSrcSlotIds(slotDesc.getId().asInt());
+            slotDescByName.put(column.getName(), slotDesc);
+        }
+        context.slotDescByName = slotDescByName;
+    }
+
+
+    /**
+     * Extracts partition predicate from SelectStmt.whereClause that can be pushed down to Hive.
+     */
+    private void extractHivePartitionPredicate() throws DdlException {
+        ListIterator<Expr> it = conjuncts.listIterator();
+        while (it.hasNext()) {
+            ExprNodeGenericFuncDesc hiveExpr = HiveMetaStoreClientHelper.convertToHivePartitionExpr(
+                    it.next(), partitionKeys, hudiTable.getName());
+            if (hiveExpr != null) {
+                hivePredicates.add(hiveExpr);
+            }
+        }
+        int count = hivePredicates.size();
+        // combine all predicate by `and`
+        // compoundExprs must have at least 2 predicates
+        if (count >= 2) {
+            hivePartitionPredicate = HiveMetaStoreClientHelper.getCompoundExpr(hivePredicates, "and");
+        } else if (count == 1) {
+            // only one predicate
+            hivePartitionPredicate = (ExprNodeGenericFuncDesc) hivePredicates.get(0);
+        } else {
+            // have no predicate, make a dummy predicate "1=1" to get all partitions
+            HiveMetaStoreClientHelper.ExprBuilder exprBuilder =
+                    new HiveMetaStoreClientHelper.ExprBuilder(hudiTable.getName());
+            hivePartitionPredicate = exprBuilder.val(TypeInfoFactory.intTypeInfo, 1)
+                    .val(TypeInfoFactory.intTypeInfo, 1)
+                    .pred("=", 2).build();
+        }
+    }
+
+    private InputSplit[] getSplits() throws UserException, IOException {
+        String splitsPath = basePath;
+        if (partitionKeys.size() > 0) {
+            extractHivePartitionPredicate();
+
+            String metaStoreUris = hudiTable.getTableProperties().get(HudiProperty.HUDI_HIVE_METASTORE_URIS);
+            List<Partition> hivePartitions =
+                    HiveMetaStoreClientHelper.getHivePartitions(metaStoreUris, remoteHiveTable, hivePartitionPredicate);
+            splitsPath = hivePartitions.stream()
+                    .map(x -> x.getSd().getLocation()).collect(Collectors.joining(","));
+        }
+
+
+        Configuration configuration = new Configuration();
+        InputFormat<?, ?> inputFormat = HiveUtil.getInputFormat(configuration, inputFormatName, false);
+        // alway get fileSplits from inputformat,
+        // because all hoodie input format have UseFileSplitsFromInputFormat annotation
+        JobConf jobConf = new JobConf(configuration);
+        FileInputFormat.setInputPaths(jobConf, splitsPath);
+        InputSplit[] inputSplits = inputFormat.getSplits(jobConf, 0);
+        return inputSplits;
+
+    }
+
+    // If fileFormat is not null, we use fileFormat instead of check file's suffix
+    protected void buildScanRange() throws UserException, IOException {
+        scanRangeLocations = Lists.newArrayList();
+        InputSplit[] inputSplits = getSplits();
+        if (inputSplits.length == 0) {
+            return;
+        }
+
+        THdfsParams hdfsParams = new THdfsParams();
+        String fullPath = ((FileSplit) inputSplits[0]).getPath().toUri().toString();
+        String filePath = ((FileSplit) inputSplits[0]).getPath().toUri().getPath();
+        String fsName = fullPath.replace(filePath, "");
+        hdfsParams.setFsName(fsName);
+        Log.info("Hudi  path's host is  " + fsName);
+
+        TFileFormatType formatType = TFileFormatType.FORMAT_PARQUET;
+        ParamCreateContext context = getParamCreateContexts().get(0);
+        for (InputSplit split : inputSplits) {
+            FileSplit fileSplit = (FileSplit) split;
+
+            TScanRangeLocations curLocations = newLocations(context.params, brokerDesc);
+            List<String> partitionValuesFromPath = BrokerUtil.parseColumnsFromPath(fileSplit.getPath().toString(),
+                    getPartitionKeys());
+            int numberOfColumnsFromFile = context.slotDescByName.size() - partitionValuesFromPath.size();
+
+            TBrokerRangeDesc rangeDesc = createBrokerRangeDesc(fileSplit, formatType,
+                    partitionValuesFromPath, numberOfColumnsFromFile, brokerDesc);
+            rangeDesc.setHdfsParams(hdfsParams);
+            rangeDesc.setReadByColumnDef(true);
+
+            curLocations.getScanRange().getBrokerScanRange().addToRanges(rangeDesc);
+            Log.info("Assign to backend " + curLocations.getLocations().get(0).getBackendId()

Review Comment:
   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] [incubator-doris] dujl commented on a diff in pull request #9752: [feature](hudi) Step2: Support query hudi external table(include cow and mor table) #9559

Posted by GitBox <gi...@apache.org>.
dujl commented on code in PR #9752:
URL: https://github.com/apache/incubator-doris/pull/9752#discussion_r882594727


##########
fe/fe-core/src/main/java/org/apache/doris/planner/HudiScanNode.java:
##########
@@ -0,0 +1,372 @@
+// 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.planner;
+
+import org.apache.doris.analysis.Analyzer;
+import org.apache.doris.analysis.BrokerDesc;
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.analysis.ImportColumnDesc;
+import org.apache.doris.analysis.SlotDescriptor;
+import org.apache.doris.analysis.StorageBackend;
+import org.apache.doris.analysis.TupleDescriptor;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.HiveMetaStoreClientHelper;
+import org.apache.doris.catalog.PrimitiveType;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.BrokerUtil;
+import org.apache.doris.external.hive.util.HiveUtil;
+import org.apache.doris.external.hudi.HudiProperty;
+import org.apache.doris.external.hudi.HudiTable;
+import org.apache.doris.load.BrokerFileGroup;
+import org.apache.doris.thrift.TBrokerFileStatus;
+import org.apache.doris.thrift.TBrokerRangeDesc;
+import org.apache.doris.thrift.TBrokerScanRangeParams;
+import org.apache.doris.thrift.TExplainLevel;
+import org.apache.doris.thrift.TFileFormatType;
+import org.apache.doris.thrift.THdfsParams;
+import org.apache.doris.thrift.TScanRangeLocations;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.Partition;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
+import org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
+import org.apache.hadoop.mapred.FileInputFormat;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.InputFormat;
+import org.apache.hadoop.mapred.InputSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.mortbay.log.Log;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * Hudi scan node to query hudi table.
+ */
+public class HudiScanNode extends BrokerScanNode {
+    private static final Logger LOG = LogManager.getLogger(HudiScanNode.class);
+
+    private HudiTable hudiTable;
+    // partition column predicates of hive table
+    private List<ExprNodeDesc> hivePredicates = new ArrayList<>();
+    private ExprNodeGenericFuncDesc hivePartitionPredicate;
+    private List<ImportColumnDesc> parsedColumnExprList = new ArrayList<>();
+    private String hdfsUri;
+
+    private Table remoteHiveTable;
+
+    /* hudi table properties */
+    private String fileFormat;
+    private String inputFormatName;
+    private String basePath;
+    private List<String> partitionKeys = new ArrayList<>();
+    /* hudi table properties */
+
+    private List<TScanRangeLocations> scanRangeLocations;
+
+    public HudiScanNode(PlanNodeId id, TupleDescriptor destTupleDesc, String planNodeName,
+                        List<List<TBrokerFileStatus>> fileStatusesList, int filesAdded) {
+        super(id, destTupleDesc, planNodeName, fileStatusesList, filesAdded);
+        this.hudiTable = (HudiTable) destTupleDesc.getTable();
+    }
+
+    public String getHdfsUri() {
+        return hdfsUri;
+    }
+
+    public List<ImportColumnDesc> getParsedColumnExprList() {
+        return parsedColumnExprList;
+    }
+
+    public String getFileFormat() {
+        return fileFormat;
+    }
+
+    public String getBasePath() {
+        return basePath;
+    }
+
+    public List<String> getPartitionKeys() {
+        return partitionKeys;
+    }
+
+    /**
+     *  super init will invoke initFileGroup, In initFileGroup will do
+     *  1, get hudi table from hive metastore
+     *  2, resolve hudi table type, query mode, table base path, partition columns information.
+     *  3. generate fileGroup
+     *
+     * @param analyzer analyzer
+     * @throws UserException when init failed.
+     */
+    @Override
+    public void init(Analyzer analyzer) throws UserException {
+        super.init(analyzer);
+        // init scan range params
+        initParams(analyzer);
+    }
+
+    @Override
+    public int getNumInstances() {
+        return scanRangeLocations.size();
+    }
+
+    @Override
+    protected void initFileGroup() throws UserException {
+        resolvHiveTable();
+        analyzeColumnFromPath();
+
+        HudiTable hudiTable = (HudiTable) desc.getTable();
+        fileGroups = Lists.newArrayList(
+                new BrokerFileGroup(hudiTable.getId(),
+                        "\t",
+                        "\n",
+                        getBasePath(),
+                        getFileFormat(),
+                        getPartitionKeys(),
+                        getParsedColumnExprList()));
+        brokerDesc = new BrokerDesc("HudiTableDesc", StorageBackend.StorageType.HDFS, hudiTable.getTableProperties());
+
+    }
+
+    /**
+     * Override this function just for skip parent's getFileStatus.
+     */
+    @Override
+    protected void getFileStatus() throws DdlException {
+        if (partitionKeys.size() > 0) {
+            extractHivePartitionPredicate();
+        }
+        // set fileStatusesList as empty, we do not need fileStatusesList
+        fileStatusesList = Lists.newArrayList();
+        filesAdded = 0;
+    }
+
+    @Override
+    public void finalize(Analyzer analyzer) throws UserException {
+        try {
+            ParamCreateContext context = getParamCreateContexts().get(0);
+            finalizeParams(context.slotDescByName, context.exprMap, context.params,
+                    context.srcTupleDescriptor, false, context.fileGroup.isNegative(), analyzer);
+        } catch (AnalysisException e) {
+            throw new UserException(e.getMessage());
+        }
+        try {
+            buildScanRange();
+        } catch (IOException e) {
+            LOG.error("Build scan range failed.", e);
+            throw new UserException("Build scan range failed.", e);
+        }
+    }
+
+    @Override
+    public List<TScanRangeLocations> getScanRangeLocations(long maxScanRangeLength) {
+        return scanRangeLocations;
+    }
+
+    private void resolvHiveTable() throws DdlException {
+        this.remoteHiveTable = HiveMetaStoreClientHelper.getTable(
+                hudiTable.getHmsDatabaseName(),
+                hudiTable.getHmsTableName(),
+                hudiTable.getTableProperties().get(HudiProperty.HUDI_HIVE_METASTORE_URIS));
+
+        this.inputFormatName = remoteHiveTable.getSd().getInputFormat();
+        this.fileFormat = HiveMetaStoreClientHelper.HiveFileFormat.getFormat(this.inputFormatName);
+        this.basePath = remoteHiveTable.getSd().getLocation();
+        for (FieldSchema fieldSchema : remoteHiveTable.getPartitionKeys()) {
+            this.partitionKeys.add(fieldSchema.getName());
+        }
+        Log.info("Hudi inputFileFormat is " + inputFormatName + ", basePath is " + this.basePath);
+    }
+
+    private void initParams(Analyzer analyzer) {
+        ParamCreateContext context = getParamCreateContexts().get(0);
+        TBrokerScanRangeParams params = context.params;
+
+        Map<String, SlotDescriptor> slotDescByName = Maps.newHashMap();
+
+        List<Column> columns = hudiTable.getBaseSchema(false);
+        // init slot desc add expr map, also transform hadoop functions
+        for (Column column : columns) {
+            SlotDescriptor slotDesc = analyzer.getDescTbl().addSlotDescriptor(context.srcTupleDescriptor);
+            slotDesc.setType(ScalarType.createType(PrimitiveType.VARCHAR));
+            slotDesc.setIsMaterialized(true);
+            slotDesc.setIsNullable(true);
+            slotDesc.setColumn(new Column(column.getName(), PrimitiveType.VARCHAR));
+            params.addToSrcSlotIds(slotDesc.getId().asInt());
+            slotDescByName.put(column.getName(), slotDesc);
+        }
+        context.slotDescByName = slotDescByName;
+    }
+
+
+    /**
+     * Extracts partition predicate from SelectStmt.whereClause that can be pushed down to Hive.
+     */
+    private void extractHivePartitionPredicate() throws DdlException {
+        ListIterator<Expr> it = conjuncts.listIterator();
+        while (it.hasNext()) {
+            ExprNodeGenericFuncDesc hiveExpr = HiveMetaStoreClientHelper.convertToHivePartitionExpr(
+                    it.next(), partitionKeys, hudiTable.getName());
+            if (hiveExpr != null) {
+                hivePredicates.add(hiveExpr);
+            }
+        }
+        int count = hivePredicates.size();
+        // combine all predicate by `and`
+        // compoundExprs must have at least 2 predicates
+        if (count >= 2) {
+            hivePartitionPredicate = HiveMetaStoreClientHelper.getCompoundExpr(hivePredicates, "and");
+        } else if (count == 1) {
+            // only one predicate
+            hivePartitionPredicate = (ExprNodeGenericFuncDesc) hivePredicates.get(0);
+        } else {
+            // have no predicate, make a dummy predicate "1=1" to get all partitions
+            HiveMetaStoreClientHelper.ExprBuilder exprBuilder =
+                    new HiveMetaStoreClientHelper.ExprBuilder(hudiTable.getName());
+            hivePartitionPredicate = exprBuilder.val(TypeInfoFactory.intTypeInfo, 1)
+                    .val(TypeInfoFactory.intTypeInfo, 1)
+                    .pred("=", 2).build();
+        }
+    }
+
+    private InputSplit[] getSplits() throws UserException, IOException {
+        String splitsPath = basePath;
+        if (partitionKeys.size() > 0) {
+            extractHivePartitionPredicate();
+
+            String metaStoreUris = hudiTable.getTableProperties().get(HudiProperty.HUDI_HIVE_METASTORE_URIS);
+            List<Partition> hivePartitions =
+                    HiveMetaStoreClientHelper.getHivePartitions(metaStoreUris, remoteHiveTable, hivePartitionPredicate);
+            splitsPath = hivePartitions.stream()
+                    .map(x -> x.getSd().getLocation()).collect(Collectors.joining(","));
+        }
+
+
+        Configuration configuration = new Configuration();
+        InputFormat<?, ?> inputFormat = HiveUtil.getInputFormat(configuration, inputFormatName, false);
+        // alway get fileSplits from inputformat,
+        // because all hoodie input format have UseFileSplitsFromInputFormat annotation
+        JobConf jobConf = new JobConf(configuration);
+        FileInputFormat.setInputPaths(jobConf, splitsPath);
+        InputSplit[] inputSplits = inputFormat.getSplits(jobConf, 0);
+        return inputSplits;
+
+    }
+
+    // If fileFormat is not null, we use fileFormat instead of check file's suffix
+    protected void buildScanRange() throws UserException, IOException {
+        scanRangeLocations = Lists.newArrayList();
+        InputSplit[] inputSplits = getSplits();
+        if (inputSplits.length == 0) {
+            return;
+        }
+
+        THdfsParams hdfsParams = new THdfsParams();
+        String fullPath = ((FileSplit) inputSplits[0]).getPath().toUri().toString();
+        String filePath = ((FileSplit) inputSplits[0]).getPath().toUri().getPath();
+        String fsName = fullPath.replace(filePath, "");
+        hdfsParams.setFsName(fsName);
+        Log.info("Hudi  path's host is  " + fsName);
+
+        TFileFormatType formatType = TFileFormatType.FORMAT_PARQUET;

Review Comment:
   hudi have two type files:  base file and log file, base file is parquet type and log file is avro type



-- 
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] [incubator-doris] github-actions[bot] commented on pull request #9752: [feature](hudi) Step2: Support query hudi external table(include cow and mor table) #9559

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

   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


[GitHub] [incubator-doris] dujl commented on a diff in pull request #9752: [feature](hudi) Step2: Support query hudi external table(include cow and mor table) #9559

Posted by GitBox <gi...@apache.org>.
dujl commented on code in PR #9752:
URL: https://github.com/apache/incubator-doris/pull/9752#discussion_r883303313


##########
fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java:
##########
@@ -626,6 +628,11 @@ public TableRef resolveTableRef(TableRef tableRef) throws AnalysisException {
             }
         }
 
+        if (table.getType() == TableType.HUDI && table.getFullSchema().isEmpty()) {
+            // resolve hudi table's schema when table schema is empty from doris meta

Review Comment:
   @Jibing-Li fix it, please check again.
   resolve table from hms didn't change table cache in database. 
   table cache in database is always the meta info in doris meta



-- 
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] [incubator-doris] dujl commented on pull request #9752: [feature](hudi) Step2: Support query hudi external table(include cow and mor table) #9559

Posted by GitBox <gi...@apache.org>.
dujl commented on PR #9752:
URL: https://github.com/apache/incubator-doris/pull/9752#issuecomment-1139416878

   @morningman @Jibing-Li please help to review


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