blackfox1983 commented on a change in pull request #3454: URL: https://github.com/apache/incubator-doris/pull/3454#discussion_r442683806
########## File path: fe/src/main/java/org/apache/doris/external/elasticsearch/EsFieldInfos.java ########## @@ -0,0 +1,160 @@ +// 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.external.elasticsearch; + +import org.apache.doris.catalog.Column; +import org.apache.doris.catalog.EsTable; +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.json.JSONObject; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +public class EsFieldInfos { + + private static final Logger LOG = LogManager.getLogger(EsFieldInfos.class); + + private Map<String, String> fieldsContext; + + private Map<String, String> docValueContext; + + public EsFieldInfos(Map<String, String> fieldsContext, Map<String, String> docValueContext) { + this.fieldsContext = fieldsContext; + this.docValueContext = docValueContext; + } + + public Map<String, String> getFieldsContext() { + return fieldsContext; + } + + public Map<String, String> getDocValueContext() { + return docValueContext; + } + + /** + * Parse the required field information from the json + * @param colList table column + * @param indexName indexName(alias or really name) + * @param indexMapping the return value of _mapping + * @param mappingType indexType + * @return fieldsContext and docValueContext + * @throws Exception + */ + public static EsFieldInfos fromMapping(List<Column> colList, String indexName, String indexMapping, String mappingType) throws ExternalDataSourceException { + JSONObject jsonObject = new JSONObject(indexMapping); + // the indexName use alias takes the first mapping + Iterator<String> keys = jsonObject.keys(); + String docKey = keys.next(); + JSONObject docData = jsonObject.optJSONObject(docKey); + JSONObject mappings = docData.optJSONObject("mappings"); + JSONObject rootSchema = mappings.optJSONObject(mappingType); + JSONObject properties; Review comment: 这类代码,注释上最好写下mapping的结构举例。 比如大概是什么样的json格式 因为这个parser强依赖对mapping的处理。 ---------------------------------------------------------------- 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. 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