stalary commented on code in PR #16806:
URL: https://github.com/apache/doris/pull/16806#discussion_r1108262190


##########
fe/fe-core/src/main/java/org/apache/doris/external/elasticsearch/EsUtil.java:
##########
@@ -419,6 +421,69 @@ public static List<Column> genColumnsFromEs(EsRestClient 
client, String indexNam
         return columns;
     }
 
+
+    /**
+     * Generate columns from ES Cluster.
+     * Add mappingEsId config in es external catalog.
+     **/
+    public static List<Column> genColumnsFromEs(EsRestClient client, String 
indexName, String mappingType,
+            boolean mappingEsId) {
+        String mapping = client.getMapping(indexName);
+        JSONObject mappingProps = getMappingProps(indexName, mapping, 
mappingType);
+        List<String> arrayFields = getArrayFields(mapping);
+        return genColumnsFromEs(mappingProps, arrayFields, mappingEsId);
+    }
+
+    private static final List<String> ALLOW_DATE_FORMATS = 
Lists.newArrayList("yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd",
+            "epoch_millis");
+
+    /**
+     * Parse es date to doris type by format
+     **/
+    private static Type parseEsDateType(Column column, JSONObject field) {
+        if (!field.containsKey("format")) {
+            // default format
+            column.setComment("Elasticsearch type is date, no format");
+            return ScalarType.createDatetimeV2Type(0);
+        } else {
+            String originFormat = field.get("format").toString();
+            String[] formats = originFormat.split("\\|\\|");
+            boolean dateTimeFlag = false;
+            boolean dateFlag = false;
+            boolean bigIntFlag = false;
+            for (String format : formats) {
+                // pre-check format
+                if (!ALLOW_DATE_FORMATS.contains(format)) {
+                    column.setComment(
+                            "Elasticsearch type is date, format is " + format 
+ " not support, use String type");
+                    return ScalarType.createStringType();
+                }
+                switch (format) {
+                    case "yyyy-MM-dd HH:mm:ss":
+                        dateTimeFlag = true;
+                        break;
+                    case "yyyy-MM-dd":
+                        dateFlag = true;
+                        break;
+                    case "epoch_millis":
+                    default:
+                        bigIntFlag = true;
+                }
+            }
+            column.setComment("Elasticsearch type is date, format is " + 
originFormat);
+            if (dateTimeFlag) {
+                return ScalarType.createDatetimeV2Type(0);
+            }
+            if (dateFlag) {
+                return ScalarType.createDateV2Type();
+            }
+            if (bigIntFlag) {
+                return Type.BIGINT;

Review Comment:
   in es epoch_millis format use long



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to