morningman commented on code in PR #20570:
URL: https://github.com/apache/doris/pull/20570#discussion_r1223231439


##########
be/src/vec/exec/jni_connector.cpp:
##########
@@ -276,6 +276,20 @@ void JniConnector::_generate_predicates(
     }
 }
 
+std::string JniConnector::join(const std::vector<std::string>& strings,

Review Comment:
   There is already a `join` method in `be/src/util/string_util.h`



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/external/HMSExternalTable.java:
##########
@@ -367,16 +374,13 @@ public List<Column> initSchema() {
         return columns;
     }
 
-
     public List<Column> getHudiSchema(List<FieldSchema> hmsSchema) {
-        org.apache.avro.Schema schema = 
HiveMetaStoreClientHelper.getHudiTableSchema(this);
+        org.apache.avro.Schema hudiSchema = 
HiveMetaStoreClientHelper.getHudiTableSchema(this);
         List<Column> tmpSchema = 
Lists.newArrayListWithCapacity(hmsSchema.size());
-        for (FieldSchema field : hmsSchema) {
-            tmpSchema.add(new Column(field.getName(),
-                    
HiveMetaStoreClientHelper.hiveTypeToDorisType(field.getType(),
-                            IcebergExternalTable.ICEBERG_DATETIME_SCALE_MS), 
true, null,
-                    true, null, field.getComment(), true, null,
-                    schema.getIndexNamed(field.getName()), null));
+        for (org.apache.avro.Schema.Field hudiField : hudiSchema.getFields()) {
+            String columnName = hudiField.name().toLowerCase(Locale.ROOT);
+            tmpSchema.add(new Column(columnName, 
HudiUtils.fromAvroHudiTypeToDorisType(hudiField.schema()),

Review Comment:
   Is there unique id for hudi column?



##########
fe/java-udf/pom.xml:
##########
@@ -125,7 +120,7 @@ under the License.
         </dependency>
         <dependency>
             <groupId>org.apache.hudi</groupId>
-            <artifactId>hudi-presto-bundle</artifactId>
+            <artifactId>hudi-hadoop-mr-bundle</artifactId>

Review Comment:
   which one should be use? hadoop or presto?



##########
fe/fe-core/src/main/java/org/apache/doris/planner/external/hudi/HudiScanNode.java:
##########
@@ -79,19 +76,24 @@ public class HudiScanNode extends HiveScanNode {
      */
     public HudiScanNode(PlanNodeId id, TupleDescriptor desc, boolean 
needCheckColumnPriv) {
         super(id, desc, "HUDI_SCAN_NODE", StatisticalType.HUDI_SCAN_NODE, 
needCheckColumnPriv);
+        isCowTable = hmsTable.isHoodieCowTable();
+        if (isCowTable) {
+            LOG.info("Hudi table {} can read as cow table", 
hmsTable.getName());

Review Comment:
   use debug level



##########
fe/java-udf/src/main/java/org/apache/doris/jni/utils/Utils.java:
##########
@@ -0,0 +1,113 @@
+// 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.jni.utils;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.security.UserGroupInformation;
+import sun.management.VMManagement;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.lang.management.ManagementFactory;
+import java.lang.management.RuntimeMXBean;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.LinkedList;
+import java.util.List;
+
+public class Utils {

Review Comment:
   How about move this class to `fe-common`?



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/HudiUtils.java:
##########
@@ -0,0 +1,166 @@
+// 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 com.google.common.base.Preconditions;
+import org.apache.avro.LogicalType;
+import org.apache.avro.LogicalTypes;
+import org.apache.avro.Schema;
+import org.apache.avro.Schema.Field;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class HudiUtils {
+    public static String fromAvroHudiTypeToHiveTypeString(Schema avroSchema) {
+        Schema.Type columnType = avroSchema.getType();
+        LogicalType logicalType = avroSchema.getLogicalType();
+        switch (columnType) {
+            case BOOLEAN:
+                return "boolean";
+            case INT:
+                if (logicalType instanceof LogicalTypes.Date) {
+                    return "date";
+                } else if (logicalType instanceof LogicalTypes.TimeMillis) {
+                    break;
+                } else {
+                    return "int";
+                }
+            case LONG:
+                if (logicalType instanceof LogicalTypes.TimeMicros) {
+                    break;
+                } else if (logicalType instanceof 
LogicalTypes.TimestampMillis) {
+                    return "timestamp(3)";
+                } else if (logicalType instanceof 
LogicalTypes.TimestampMicros) {
+                    return "timestamp(6)";
+                } else {
+                    return "bigint";
+                }
+            case FLOAT:
+                return "float";
+            case DOUBLE:
+                return "double";
+            case STRING:
+                return "string";
+            case FIXED:
+            case BYTES:
+                if (logicalType instanceof LogicalTypes.Decimal) {
+                    int precision = ((LogicalTypes.Decimal) 
logicalType).getPrecision();
+                    int scale = ((LogicalTypes.Decimal) 
logicalType).getScale();
+                    return String.format("decimal(%s,%s)", precision, scale);
+                } else {
+                    return "string";
+                }
+            case ARRAY:
+                String elementType = 
fromAvroHudiTypeToHiveTypeString(avroSchema.getElementType());
+                return String.format("array<%s>", elementType);
+            case RECORD:
+                List<Field> fields = avroSchema.getFields();
+                Preconditions.checkArgument(fields.size() > 0);
+                String nameToType = fields.stream()
+                        .map(f -> String.format("%s:%s", f.name(),
+                                fromAvroHudiTypeToHiveTypeString(f.schema())))
+                        .collect(Collectors.joining(","));
+                return String.format("struct<%s>", nameToType);
+            case MAP:
+                Schema value = avroSchema.getValueType();
+                String valueType = fromAvroHudiTypeToHiveTypeString(value);
+                return String.format("map<%s,%s>", "string", valueType);
+            case UNION:
+                List<Schema> nonNullMembers = avroSchema.getTypes().stream()
+                        .filter(schema -> 
!Schema.Type.NULL.equals(schema.getType()))
+                        .collect(Collectors.toList());
+                // The nullable column in hudi is the union type with schemas 
[null, real column type]
+                if (nonNullMembers.size() == 1) {
+                    return 
fromAvroHudiTypeToHiveTypeString(nonNullMembers.get(0));
+                }
+                break;
+            default:
+                break;
+        }
+        String errorMsg = String.format("Unsupported hudi %s type of column 
%s", avroSchema.getType().getName(),

Review Comment:
   For unsupported column, use `Type.UNSUPPORTED`



##########
fe/java-udf/pom.xml:
##########
@@ -179,6 +168,12 @@ under the License.
             </exclusions>
         </dependency>
 
+        <dependency>

Review Comment:
   Why move this to the last?
   If there is special reason, add comment in code.



##########
fe/java-udf/src/main/java/org/apache/doris/hudi/HudiJniScanner.java:
##########
@@ -31,32 +32,40 @@
 import org.apache.hadoop.mapred.JobConf;
 import org.apache.hadoop.mapred.RecordReader;
 import org.apache.hadoop.mapred.Reporter;
+import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hudi.common.model.HoodieLogFile;
 import org.apache.hudi.common.util.Option;
 import org.apache.hudi.hadoop.realtime.HoodieRealtimeFileSplit;
 import org.apache.log4j.Logger;
 
 import java.io.IOException;
+import java.security.PrivilegedExceptionAction;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
 
 /**
  * The hudi JniScanner
  */
 public class HudiJniScanner extends JniScanner {
     private static final Logger LOG = Logger.getLogger(HudiJniScanner.class);
-    private HudiScanParam hudiScanParam;
+    private final HudiScanParam hudiScanParam;
 
+    UserGroupInformation ugi = null;
     private RecordReader<NullWritable, ArrayWritable> reader;
     private StructObjectInspector rowInspector;
     private Deserializer deserializer;
     private final ClassLoader classLoader;
 
     public HudiJniScanner(int fetchSize, Map<String, String> params) {
-        LOG.debug("fetchSize:" + fetchSize + " , params: " + params);
+        LOG.info("Hudi JNI params:\n" + params.entrySet().stream().map(kv -> 
kv.getKey() + "=" + kv.getValue())

Review Comment:
   debug



##########
fe/fe-core/src/main/java/org/apache/doris/planner/external/hudi/HudiScanNode.java:
##########
@@ -79,19 +76,24 @@ public class HudiScanNode extends HiveScanNode {
      */
     public HudiScanNode(PlanNodeId id, TupleDescriptor desc, boolean 
needCheckColumnPriv) {
         super(id, desc, "HUDI_SCAN_NODE", StatisticalType.HUDI_SCAN_NODE, 
needCheckColumnPriv);
+        isCowTable = hmsTable.isHoodieCowTable();
+        if (isCowTable) {
+            LOG.info("Hudi table {} can read as cow table", 
hmsTable.getName());
+        } else {
+            LOG.info("Hudi table {} is a mor table, and will use JNI to read 
data in BE", hmsTable.getName());

Review Comment:
   ditto



##########
fe/java-udf/src/main/java/org/apache/doris/jni/vec/ColumnType.java:
##########
@@ -230,6 +238,7 @@ private static int findNextNestedField(String 
commaSplitFields) {
     }
 
     public static ColumnType parseType(String columnName, String hiveType) {
+        LOG.info("parse column " + columnName + " with type " + hiveType);

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-unsubscr...@doris.apache.org

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


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

Reply via email to