chaoyli closed pull request #464: Make column's name be case insensitive in 
load stmt
URL: https://github.com/apache/incubator-doris/pull/464
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/fe/src/main/java/org/apache/doris/load/BrokerFileGroup.java 
b/fe/src/main/java/org/apache/doris/load/BrokerFileGroup.java
index abe71b3e..458b0544 100644
--- a/fe/src/main/java/org/apache/doris/load/BrokerFileGroup.java
+++ b/fe/src/main/java/org/apache/doris/load/BrokerFileGroup.java
@@ -33,6 +33,7 @@
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
+
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
@@ -62,7 +63,7 @@
     private String lineDelimiter;
     private boolean isNegative;
     private List<Long> partitionIds;
-    private List<String> valueNames;
+    private List<String> fileFieldNames;
     private List<String> filePathes;
 
     // This column need expression to get column
@@ -119,9 +120,9 @@ public void parse(Database db) throws DdlException {
             }
         }
 
-        // valueNames
+        // fileFieldNames
         if (dataDescription.getColumnNames() != null) {
-            valueNames = Lists.newArrayList(dataDescription.getColumnNames());
+            fileFieldNames = 
Lists.newArrayList(dataDescription.getColumnNames());
         }
 
         // column
@@ -155,8 +156,8 @@ public boolean isNegative() {
         return isNegative;
     }
 
-    public List<String> getValueNames() {
-        return valueNames;
+    public List<String> getFileFieldNames() {
+        return fileFieldNames;
     }
 
     public List<Long> getPartitionIds() {
@@ -186,10 +187,10 @@ public String toString() {
             }
             sb.append("]");
         }
-        if (valueNames != null) {
-            sb.append(",valueNames=[");
+        if (fileFieldNames != null) {
+            sb.append(",fileFieldNames=[");
             int idx = 0;
-            for (String name : valueNames) {
+            for (String name : fileFieldNames) {
                 if (idx++ != 0) {
                     sb.append(",");
                 }
@@ -234,12 +235,12 @@ public void write(DataOutput out) throws IOException {
                 out.writeLong(id);
             }
         }
-        // valueNames
-        if (valueNames == null) {
+        // fileFieldNames
+        if (fileFieldNames == null) {
             out.writeInt(0);
         } else {
-            out.writeInt(valueNames.size());
-            for (String name : valueNames) {
+            out.writeInt(fileFieldNames.size());
+            for (String name : fileFieldNames) {
                 Text.writeString(out, name);
             }
         }
@@ -277,13 +278,13 @@ public void readFields(DataInput in) throws IOException {
                 }
             }
         }
-        // valueNames
+        // fileFieldName
         {
-            int valueNameSize = in.readInt();
-            if (valueNameSize > 0) {
-                valueNames = Lists.newArrayList();
-                for (int i = 0; i < valueNameSize; ++i) {
-                    valueNames.add(Text.readString(in));
+            int fileFieldNameSize = in.readInt();
+            if (fileFieldNameSize > 0) {
+                fileFieldNames = Lists.newArrayList();
+                for (int i = 0; i < fileFieldNameSize; ++i) {
+                    fileFieldNames.add(Text.readString(in));
                 }
             }
         }
diff --git a/fe/src/main/java/org/apache/doris/planner/BrokerScanNode.java 
b/fe/src/main/java/org/apache/doris/planner/BrokerScanNode.java
index 02fa6c2b..e3d236bc 100644
--- a/fe/src/main/java/org/apache/doris/planner/BrokerScanNode.java
+++ b/fe/src/main/java/org/apache/doris/planner/BrokerScanNode.java
@@ -74,6 +74,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Random;
+import java.util.stream.Collectors;
 
 // Broker scan node
 public class BrokerScanNode extends ScanNode {
@@ -319,12 +320,17 @@ private void initParams(ParamCreateContext context) 
throws AnalysisException, Us
         parseExprMap(context.exprMap);
 
         // Generate expr
-        List<String> valueNames = fileGroup.getValueNames();
-        if (valueNames == null) {
-            valueNames = Lists.newArrayList();
+        List<String> fileFieldNames = fileGroup.getFileFieldNames();
+        if (fileFieldNames == null) {
+            fileFieldNames = Lists.newArrayList();
             for (Column column : targetTable.getBaseSchema()) {
-                valueNames.add(column.getName());
+                fileFieldNames.add(column.getName());
             }
+        } else {
+            // change fileFiledName to real column name(case match)
+            fileFieldNames = fileFieldNames.stream().map(
+                    f -> targetTable.getColumn(f) == null ? f : 
targetTable.getColumn(f).getName()).collect(
+                            Collectors.toList());
         }
 
         // This tuple descriptor is used for file of
@@ -333,12 +339,12 @@ private void initParams(ParamCreateContext context) 
throws AnalysisException, Us
 
         Map<String, SlotDescriptor> slotDescByName = Maps.newHashMap();
         context.slotDescByName = slotDescByName;
-        for (String value : valueNames) {
+        for (String fieldName : fileFieldNames) {
             SlotDescriptor slotDesc = 
analyzer.getDescTbl().addSlotDescriptor(srcTupleDesc);
             slotDesc.setType(ScalarType.createType(PrimitiveType.VARCHAR));
             slotDesc.setIsMaterialized(true);
             slotDesc.setIsNullable(false);
-            slotDescByName.put(value, slotDesc);
+            slotDescByName.put(fieldName, slotDesc);
 
             params.addToSrc_slot_ids(slotDesc.getId().asInt());
         }
diff --git a/fe/src/main/java/org/apache/doris/planner/StreamLoadScanNode.java 
b/fe/src/main/java/org/apache/doris/planner/StreamLoadScanNode.java
index 08cfaef4..1d9f86e8 100644
--- a/fe/src/main/java/org/apache/doris/planner/StreamLoadScanNode.java
+++ b/fe/src/main/java/org/apache/doris/planner/StreamLoadScanNode.java
@@ -18,7 +18,6 @@
 package org.apache.doris.planner;
 
 import org.apache.doris.analysis.Analyzer;
-import org.apache.doris.analysis.CastExpr;
 import org.apache.doris.analysis.ColumnSeparator;
 import org.apache.doris.analysis.Expr;
 import org.apache.doris.analysis.ExprSubstitutionMap;
@@ -148,15 +147,18 @@ public void init(Analyzer analyzer) throws UserException {
             }
 
             for (ImportColumnDesc columnDesc : columnsStmt.getColumns()) {
+                // make column name case match with real column name
+                String realColName = 
dstTable.getColumn(columnDesc.getColumn()) == null ? columnDesc.getColumn()
+                        : dstTable.getColumn(columnDesc.getColumn()).getName();
                 if (columnDesc.getExpr() != null) {
-                    exprsByName.put(columnDesc.getColumn(), 
columnDesc.getExpr());
+                    exprsByName.put(realColName, columnDesc.getExpr());
                 } else {
                     SlotDescriptor slotDesc = 
analyzer.getDescTbl().addSlotDescriptor(srcTupleDesc);
                     
slotDesc.setType(ScalarType.createType(PrimitiveType.VARCHAR));
                     slotDesc.setIsMaterialized(true);
                     slotDesc.setIsNullable(false);
                     params.addToSrc_slot_ids(slotDesc.getId().asInt());
-                    slotDescByName.put(columnDesc.getColumn(), slotDesc);
+                    slotDescByName.put(realColName, slotDesc);
                 }
             }
 
@@ -202,7 +204,7 @@ public void init(Analyzer analyzer) throws UserException {
 
         // analyze where statement
         if (request.isSetWhere()) {
-            Map<String, SlotDescriptor> dstDescMap = Maps.newHashMap();
+            Map<String, SlotDescriptor> dstDescMap = 
Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER);
             for (SlotDescriptor slotDescriptor : desc.getSlots()) {
                 dstDescMap.put(slotDescriptor.getColumn().getName(), 
slotDescriptor);
             }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to