morningman commented on code in PR #50225: URL: https://github.com/apache/doris/pull/50225#discussion_r2056813471
########## fe/fe-core/src/main/java/org/apache/doris/datasource/property/fileformat/AvroFileFormatProperties.java: ########## @@ -0,0 +1,56 @@ +// 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.datasource.property.fileformat; + +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.proto.InternalService.PFetchTableSchemaRequest; +import org.apache.doris.thrift.TFileAttributes; +import org.apache.doris.thrift.TFileFormatType; +import org.apache.doris.thrift.TFileTextScanRangeParams; +import org.apache.doris.thrift.TResultFileSinkOptions; + +import java.util.Map; + +public class AvroFileFormatProperties extends FileFormatProperties { + public AvroFileFormatProperties(TFileFormatType fileFormatType) { + super(fileFormatType); + } + + @Override + public void analyzeFileFormatProperties(Map<String, String> formatProperties, boolean isRemoveOriginProperty) + throws AnalysisException { + } + + @Override + public PFetchTableSchemaRequest toPFetchTableSchemaRequest() { Review Comment: All the implements of `toPFetchTableSchemaRequest` and `toTResultFileSinkOptions` are return null? What is these methods for? ########## fe/fe-core/src/main/java/org/apache/doris/datasource/property/fileformat/FileFormatProperties.java: ########## @@ -0,0 +1,116 @@ +// 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.datasource.property.fileformat; + +import org.apache.doris.datasource.property.constants.CsvProperties; +import org.apache.doris.datasource.property.constants.FileFormatBaseProperties; +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.proto.InternalService.PFetchTableSchemaRequest; +import org.apache.doris.thrift.TFileAttributes; +import org.apache.doris.thrift.TFileCompressType; +import org.apache.doris.thrift.TFileFormatType; +import org.apache.doris.thrift.TResultFileSinkOptions; +import org.apache.doris.thrift.TTextSerdeType; + +import java.util.Map; + +public abstract class FileFormatProperties { + protected TFileFormatType fileFormatType; + + protected TFileCompressType compressionType; + + public FileFormatProperties(TFileFormatType fileFormatType) { + this.fileFormatType = fileFormatType; + } + + /** + * + * @param formatProperties + * @return properties needed by Doris + * @throws AnalysisException + */ + + /** + * Analyze user properties + * @param formatProperties properties specified by user + * @param isRemoveOriginProperty if this param is set to true, then this method would remove the origin property + * @throws AnalysisException + */ + public abstract void analyzeFileFormatProperties( + Map<String, String> formatProperties, boolean isRemoveOriginProperty) + throws AnalysisException; + + public abstract PFetchTableSchemaRequest toPFetchTableSchemaRequest(); Review Comment: Add comment for all abstract methods ########## fe/fe-core/src/main/java/org/apache/doris/datasource/property/fileformat/FileFormatProperties.java: ########## @@ -0,0 +1,116 @@ +// 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.datasource.property.fileformat; + +import org.apache.doris.datasource.property.constants.CsvProperties; +import org.apache.doris.datasource.property.constants.FileFormatBaseProperties; +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.proto.InternalService.PFetchTableSchemaRequest; +import org.apache.doris.thrift.TFileAttributes; +import org.apache.doris.thrift.TFileCompressType; +import org.apache.doris.thrift.TFileFormatType; +import org.apache.doris.thrift.TResultFileSinkOptions; +import org.apache.doris.thrift.TTextSerdeType; + +import java.util.Map; + +public abstract class FileFormatProperties { + protected TFileFormatType fileFormatType; + + protected TFileCompressType compressionType; + + public FileFormatProperties(TFileFormatType fileFormatType) { + this.fileFormatType = fileFormatType; + } + + /** + * + * @param formatProperties + * @return properties needed by Doris + * @throws AnalysisException + */ + + /** + * Analyze user properties + * @param formatProperties properties specified by user + * @param isRemoveOriginProperty if this param is set to true, then this method would remove the origin property + * @throws AnalysisException + */ + public abstract void analyzeFileFormatProperties( + Map<String, String> formatProperties, boolean isRemoveOriginProperty) + throws AnalysisException; + + public abstract PFetchTableSchemaRequest toPFetchTableSchemaRequest(); + + public abstract TResultFileSinkOptions toTResultFileSinkOptions(); + + public abstract TFileAttributes toTFileAttributes(); + + public static FileFormatProperties createFileFormatProperties(String formatString) { Review Comment: Sometimes we may use the suffix of a file to guess its format. For example, the file path is `/path/to/1.parquet`, so we know that this is a parquet format, even if user does not specify the "file_format" property. We should handle this. And I think without the suffix and user specified "file_format" property, we should provide a "default" format file, eg, csv. But it depends because I am not sure what the previous logic is ########## fe/fe-core/src/main/java/org/apache/doris/datasource/property/fileformat/CsvFileFormatProperties.java: ########## @@ -0,0 +1,195 @@ +// 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.datasource.property.fileformat; + +import org.apache.doris.analysis.Separator; +import org.apache.doris.catalog.Column; +import org.apache.doris.common.util.FileFormatUtils; +import org.apache.doris.common.util.Util; +import org.apache.doris.datasource.property.constants.CsvProperties; +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.proto.InternalService.PFetchTableSchemaRequest; +import org.apache.doris.qe.ConnectContext; +import org.apache.doris.thrift.TFileAttributes; +import org.apache.doris.thrift.TFileFormatType; +import org.apache.doris.thrift.TFileTextScanRangeParams; +import org.apache.doris.thrift.TResultFileSinkOptions; +import org.apache.doris.thrift.TTextSerdeType; + +import com.google.common.base.Strings; +import com.google.common.collect.Lists; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.List; +import java.util.Map; + +public class CsvFileFormatProperties extends FileFormatProperties { + public static final Logger LOG = LogManager.getLogger( + org.apache.doris.datasource.property.fileformat.CsvFileFormatProperties.class); + + private String headerType = ""; + private TTextSerdeType textSerdeType = TTextSerdeType.JSON_TEXT_SERDE; + private String columnSeparator = CsvProperties.DEFAULT_COLUMN_SEPARATOR; + private String lineDelimiter = CsvProperties.DEFAULT_LINE_DELIMITER; + private boolean trimDoubleQuotes; + private int skipLines; + private byte enclose; + + // used by tvf + // User specified csv columns, it will override columns got from file + private final List<Column> csvSchema = Lists.newArrayList(); + + String defaultColumnSeparator = CsvProperties.DEFAULT_COLUMN_SEPARATOR; + + public CsvFileFormatProperties(TFileFormatType fileFormatType) { + super(fileFormatType); + } + + public CsvFileFormatProperties(TFileFormatType fileFormatType, String defaultColumnSeparator, + TTextSerdeType textSerdeType) { + super(fileFormatType); + this.defaultColumnSeparator = defaultColumnSeparator; + this.textSerdeType = textSerdeType; + } + + public CsvFileFormatProperties(TFileFormatType fileFormatType, String headerType) { + super(fileFormatType); + this.headerType = headerType; + } + + + @Override + public void analyzeFileFormatProperties(Map<String, String> formatProperties, boolean isRemoveOriginProperty) + throws AnalysisException { + try { + // check properties specified by user -- formatProperties + columnSeparator = getOrDefaultAndRemove(formatProperties, CsvProperties.PROP_COLUMN_SEPARATOR, + defaultColumnSeparator, isRemoveOriginProperty); + if (Strings.isNullOrEmpty(columnSeparator)) { Review Comment: It's unnecessary, because you already give a default value. So the column separator won't be empty. ########## fe/fe-core/src/main/java/org/apache/doris/datasource/property/fileformat/OrcFileFormatProperties.java: ########## @@ -0,0 +1,63 @@ +// 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.datasource.property.fileformat; + +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.proto.InternalService.PFetchTableSchemaRequest; +import org.apache.doris.thrift.TFileAttributes; +import org.apache.doris.thrift.TFileCompressType; +import org.apache.doris.thrift.TFileFormatType; +import org.apache.doris.thrift.TFileTextScanRangeParams; +import org.apache.doris.thrift.TResultFileSinkOptions; + +import java.util.Map; + +public class OrcFileFormatProperties extends FileFormatProperties { + private TFileCompressType orcCompressionType = TFileCompressType.ZLIB; + + public OrcFileFormatProperties(TFileFormatType fileFormatType) { Review Comment: There is only one type of `TFileFormatType` for orc, which is `FORMAT_ORC`. So the constructor of this class should be ``` public OrcFileFormatProperties() { super(TFileFormatType.FORMAT_ORC); } ``` Same suggestion for other class' constructors ########## fe/fe-core/src/main/java/org/apache/doris/datasource/property/fileformat/CsvFileFormatProperties.java: ########## @@ -0,0 +1,195 @@ +// 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.datasource.property.fileformat; + +import org.apache.doris.analysis.Separator; +import org.apache.doris.catalog.Column; +import org.apache.doris.common.util.FileFormatUtils; +import org.apache.doris.common.util.Util; +import org.apache.doris.datasource.property.constants.CsvProperties; +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.proto.InternalService.PFetchTableSchemaRequest; +import org.apache.doris.qe.ConnectContext; +import org.apache.doris.thrift.TFileAttributes; +import org.apache.doris.thrift.TFileFormatType; +import org.apache.doris.thrift.TFileTextScanRangeParams; +import org.apache.doris.thrift.TResultFileSinkOptions; +import org.apache.doris.thrift.TTextSerdeType; + +import com.google.common.base.Strings; +import com.google.common.collect.Lists; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.List; +import java.util.Map; + +public class CsvFileFormatProperties extends FileFormatProperties { + public static final Logger LOG = LogManager.getLogger( + org.apache.doris.datasource.property.fileformat.CsvFileFormatProperties.class); + + private String headerType = ""; + private TTextSerdeType textSerdeType = TTextSerdeType.JSON_TEXT_SERDE; + private String columnSeparator = CsvProperties.DEFAULT_COLUMN_SEPARATOR; + private String lineDelimiter = CsvProperties.DEFAULT_LINE_DELIMITER; + private boolean trimDoubleQuotes; + private int skipLines; + private byte enclose; + + // used by tvf + // User specified csv columns, it will override columns got from file + private final List<Column> csvSchema = Lists.newArrayList(); + + String defaultColumnSeparator = CsvProperties.DEFAULT_COLUMN_SEPARATOR; + + public CsvFileFormatProperties(TFileFormatType fileFormatType) { + super(fileFormatType); + } + + public CsvFileFormatProperties(TFileFormatType fileFormatType, String defaultColumnSeparator, + TTextSerdeType textSerdeType) { + super(fileFormatType); + this.defaultColumnSeparator = defaultColumnSeparator; + this.textSerdeType = textSerdeType; + } + + public CsvFileFormatProperties(TFileFormatType fileFormatType, String headerType) { + super(fileFormatType); + this.headerType = headerType; + } + + + @Override + public void analyzeFileFormatProperties(Map<String, String> formatProperties, boolean isRemoveOriginProperty) + throws AnalysisException { + try { + // check properties specified by user -- formatProperties + columnSeparator = getOrDefaultAndRemove(formatProperties, CsvProperties.PROP_COLUMN_SEPARATOR, + defaultColumnSeparator, isRemoveOriginProperty); + if (Strings.isNullOrEmpty(columnSeparator)) { + throw new AnalysisException("column_separator can not be empty."); + } + columnSeparator = Separator.convertSeparator(columnSeparator); + + lineDelimiter = getOrDefaultAndRemove(formatProperties, CsvProperties.PROP_LINE_DELIMITER, + CsvProperties.DEFAULT_LINE_DELIMITER, isRemoveOriginProperty); + if (Strings.isNullOrEmpty(lineDelimiter)) { + throw new AnalysisException("line_delimiter can not be empty."); + } + lineDelimiter = Separator.convertSeparator(lineDelimiter); + + String enclosedString = getOrDefaultAndRemove(formatProperties, CsvProperties.PROP_ENCLOSE, + "", isRemoveOriginProperty); + if (!Strings.isNullOrEmpty(enclosedString)) { + if (enclosedString.length() > 1) { + throw new AnalysisException("enclose should not be longer than one byte."); + } + enclose = (byte) enclosedString.charAt(0); + if (enclose == 0) { + throw new AnalysisException("enclose should not be byte [0]."); + } + } + + trimDoubleQuotes = Boolean.valueOf(getOrDefaultAndRemove(formatProperties, + CsvProperties.PROP_TRIM_DOUBLE_QUOTES, "", isRemoveOriginProperty)) + .booleanValue(); + skipLines = Integer.valueOf(getOrDefaultAndRemove(formatProperties, + CsvProperties.PROP_SKIP_LINES, "0", isRemoveOriginProperty)).intValue(); + if (skipLines < 0) { + throw new AnalysisException("skipLines should not be less than 0."); + } + + String compressTypeStr = getOrDefaultAndRemove(formatProperties, + CsvProperties.PROP_COMPRESS_TYPE, "UNKNOWN", isRemoveOriginProperty); + try { + compressionType = Util.getFileCompressType(compressTypeStr); + } catch (IllegalArgumentException e) { + throw new AnalysisException("Compress type : " + compressTypeStr + " is not supported."); + } + + FileFormatUtils.parseCsvSchema(csvSchema, getOrDefaultAndRemove(formatProperties, + CsvProperties.PROP_CSV_SCHEMA, "", isRemoveOriginProperty)); + if (LOG.isDebugEnabled()) { + LOG.debug("get csv schema: {}", csvSchema); + } + } catch (org.apache.doris.common.AnalysisException e) { Review Comment: which method will throw this exception? ########## fe/fe-core/src/main/java/org/apache/doris/datasource/property/fileformat/CsvFileFormatProperties.java: ########## @@ -0,0 +1,195 @@ +// 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.datasource.property.fileformat; + +import org.apache.doris.analysis.Separator; +import org.apache.doris.catalog.Column; +import org.apache.doris.common.util.FileFormatUtils; +import org.apache.doris.common.util.Util; +import org.apache.doris.datasource.property.constants.CsvProperties; +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.proto.InternalService.PFetchTableSchemaRequest; +import org.apache.doris.qe.ConnectContext; +import org.apache.doris.thrift.TFileAttributes; +import org.apache.doris.thrift.TFileFormatType; +import org.apache.doris.thrift.TFileTextScanRangeParams; +import org.apache.doris.thrift.TResultFileSinkOptions; +import org.apache.doris.thrift.TTextSerdeType; + +import com.google.common.base.Strings; +import com.google.common.collect.Lists; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.List; +import java.util.Map; + +public class CsvFileFormatProperties extends FileFormatProperties { + public static final Logger LOG = LogManager.getLogger( + org.apache.doris.datasource.property.fileformat.CsvFileFormatProperties.class); + + private String headerType = ""; + private TTextSerdeType textSerdeType = TTextSerdeType.JSON_TEXT_SERDE; + private String columnSeparator = CsvProperties.DEFAULT_COLUMN_SEPARATOR; + private String lineDelimiter = CsvProperties.DEFAULT_LINE_DELIMITER; + private boolean trimDoubleQuotes; + private int skipLines; + private byte enclose; + + // used by tvf + // User specified csv columns, it will override columns got from file + private final List<Column> csvSchema = Lists.newArrayList(); + + String defaultColumnSeparator = CsvProperties.DEFAULT_COLUMN_SEPARATOR; + + public CsvFileFormatProperties(TFileFormatType fileFormatType) { + super(fileFormatType); + } + + public CsvFileFormatProperties(TFileFormatType fileFormatType, String defaultColumnSeparator, + TTextSerdeType textSerdeType) { + super(fileFormatType); + this.defaultColumnSeparator = defaultColumnSeparator; + this.textSerdeType = textSerdeType; + } + + public CsvFileFormatProperties(TFileFormatType fileFormatType, String headerType) { + super(fileFormatType); + this.headerType = headerType; + } + + + @Override + public void analyzeFileFormatProperties(Map<String, String> formatProperties, boolean isRemoveOriginProperty) + throws AnalysisException { + try { + // check properties specified by user -- formatProperties + columnSeparator = getOrDefaultAndRemove(formatProperties, CsvProperties.PROP_COLUMN_SEPARATOR, + defaultColumnSeparator, isRemoveOriginProperty); + if (Strings.isNullOrEmpty(columnSeparator)) { + throw new AnalysisException("column_separator can not be empty."); + } + columnSeparator = Separator.convertSeparator(columnSeparator); + + lineDelimiter = getOrDefaultAndRemove(formatProperties, CsvProperties.PROP_LINE_DELIMITER, + CsvProperties.DEFAULT_LINE_DELIMITER, isRemoveOriginProperty); + if (Strings.isNullOrEmpty(lineDelimiter)) { + throw new AnalysisException("line_delimiter can not be empty."); + } + lineDelimiter = Separator.convertSeparator(lineDelimiter); + + String enclosedString = getOrDefaultAndRemove(formatProperties, CsvProperties.PROP_ENCLOSE, + "", isRemoveOriginProperty); + if (!Strings.isNullOrEmpty(enclosedString)) { + if (enclosedString.length() > 1) { + throw new AnalysisException("enclose should not be longer than one byte."); + } + enclose = (byte) enclosedString.charAt(0); + if (enclose == 0) { + throw new AnalysisException("enclose should not be byte [0]."); + } + } + + trimDoubleQuotes = Boolean.valueOf(getOrDefaultAndRemove(formatProperties, + CsvProperties.PROP_TRIM_DOUBLE_QUOTES, "", isRemoveOriginProperty)) + .booleanValue(); + skipLines = Integer.valueOf(getOrDefaultAndRemove(formatProperties, + CsvProperties.PROP_SKIP_LINES, "0", isRemoveOriginProperty)).intValue(); + if (skipLines < 0) { + throw new AnalysisException("skipLines should not be less than 0."); + } + + String compressTypeStr = getOrDefaultAndRemove(formatProperties, + CsvProperties.PROP_COMPRESS_TYPE, "UNKNOWN", isRemoveOriginProperty); + try { + compressionType = Util.getFileCompressType(compressTypeStr); + } catch (IllegalArgumentException e) { + throw new AnalysisException("Compress type : " + compressTypeStr + " is not supported."); + } + + FileFormatUtils.parseCsvSchema(csvSchema, getOrDefaultAndRemove(formatProperties, Review Comment: I think `csv_schema` is not part of `CsvFileFormatProperties`. It is part of `tvf` properties. ########## fe/fe-core/src/main/java/org/apache/doris/datasource/property/fileformat/AvroFileFormatProperties.java: ########## @@ -0,0 +1,56 @@ +// 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.datasource.property.fileformat; + +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.proto.InternalService.PFetchTableSchemaRequest; +import org.apache.doris.thrift.TFileAttributes; +import org.apache.doris.thrift.TFileFormatType; +import org.apache.doris.thrift.TFileTextScanRangeParams; +import org.apache.doris.thrift.TResultFileSinkOptions; + +import java.util.Map; + +public class AvroFileFormatProperties extends FileFormatProperties { + public AvroFileFormatProperties(TFileFormatType fileFormatType) { + super(fileFormatType); + } + + @Override + public void analyzeFileFormatProperties(Map<String, String> formatProperties, boolean isRemoveOriginProperty) + throws AnalysisException { + } + + @Override + public PFetchTableSchemaRequest toPFetchTableSchemaRequest() { Review Comment: I don't think it is suitable to let a "Properties" class to generate a "fetch schema request" ########## fe/fe-core/src/main/java/org/apache/doris/datasource/property/fileformat/JsonFileFormatProperties.java: ########## @@ -0,0 +1,122 @@ +// 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.datasource.property.fileformat; + +import org.apache.doris.common.util.FileFormatConstants; +import org.apache.doris.common.util.Util; +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.proto.InternalService.PFetchTableSchemaRequest; +import org.apache.doris.thrift.TFileAttributes; +import org.apache.doris.thrift.TFileFormatType; +import org.apache.doris.thrift.TFileTextScanRangeParams; +import org.apache.doris.thrift.TResultFileSinkOptions; + +import java.util.Map; + +public class JsonFileFormatProperties extends FileFormatProperties { + // from ExternalFileTableValuedFunction: + private String jsonRoot = ""; + private String jsonPaths = ""; + private boolean stripOuterArray; + private boolean readJsonByLine; + private boolean numAsString; + private boolean fuzzyParse; + + + public JsonFileFormatProperties(TFileFormatType fileFormatType) { + super(fileFormatType); + } + + @Override + public void analyzeFileFormatProperties(Map<String, String> formatProperties, boolean isRemoveOriginProperty) + throws AnalysisException { + // 这几个json应该移到json checker中 Review Comment: English ########## fe/fe-core/src/main/java/org/apache/doris/datasource/property/fileformat/FileFormatProperties.java: ########## @@ -0,0 +1,116 @@ +// 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.datasource.property.fileformat; + +import org.apache.doris.datasource.property.constants.CsvProperties; +import org.apache.doris.datasource.property.constants.FileFormatBaseProperties; +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.proto.InternalService.PFetchTableSchemaRequest; +import org.apache.doris.thrift.TFileAttributes; +import org.apache.doris.thrift.TFileCompressType; +import org.apache.doris.thrift.TFileFormatType; +import org.apache.doris.thrift.TResultFileSinkOptions; +import org.apache.doris.thrift.TTextSerdeType; + +import java.util.Map; + +public abstract class FileFormatProperties { + protected TFileFormatType fileFormatType; + + protected TFileCompressType compressionType; + + public FileFormatProperties(TFileFormatType fileFormatType) { + this.fileFormatType = fileFormatType; + } + + /** + * + * @param formatProperties + * @return properties needed by Doris + * @throws AnalysisException + */ + + /** + * Analyze user properties + * @param formatProperties properties specified by user + * @param isRemoveOriginProperty if this param is set to true, then this method would remove the origin property + * @throws AnalysisException + */ + public abstract void analyzeFileFormatProperties( + Map<String, String> formatProperties, boolean isRemoveOriginProperty) + throws AnalysisException; + + public abstract PFetchTableSchemaRequest toPFetchTableSchemaRequest(); + + public abstract TResultFileSinkOptions toTResultFileSinkOptions(); + + public abstract TFileAttributes toTFileAttributes(); + + public static FileFormatProperties createFileFormatProperties(String formatString) { + switch (formatString) { + case FileFormatBaseProperties.FORMAT_CSV: + return new CsvFileFormatProperties(TFileFormatType.FORMAT_CSV_PLAIN); + case FileFormatBaseProperties.FORMAT_HIVE_TEXT: + return new CsvFileFormatProperties(TFileFormatType.FORMAT_CSV_PLAIN, + CsvProperties.DEFAULT_HIVE_TEXT_COLUMN_SEPARATOR, + TTextSerdeType.HIVE_TEXT_SERDE); + case FileFormatBaseProperties.FORMAT_CSV_WITH_NAMES: + return new CsvFileFormatProperties(TFileFormatType.FORMAT_CSV_PLAIN, + FileFormatBaseProperties.FORMAT_CSV_WITH_NAMES); + case FileFormatBaseProperties.FORMAT_CSV_WITH_NAMES_AND_TYPES: + return new CsvFileFormatProperties(TFileFormatType.FORMAT_CSV_PLAIN, + FileFormatBaseProperties.FORMAT_CSV_WITH_NAMES_AND_TYPES); + case FileFormatBaseProperties.FORMAT_PARQUET: + return new ParquetFileFormatProperties(TFileFormatType.FORMAT_PARQUET); + case FileFormatBaseProperties.FORMAT_ORC: + return new OrcFileFormatProperties(TFileFormatType.FORMAT_ORC); + case FileFormatBaseProperties.FORMAT_JSON: + return new JsonFileFormatProperties(TFileFormatType.FORMAT_JSON); + case FileFormatBaseProperties.FORMAT_AVRO: + return new AvroFileFormatProperties(TFileFormatType.FORMAT_AVRO); + case FileFormatBaseProperties.FORMAT_WAL: + return new WalFileFormatProperties(TFileFormatType.FORMAT_WAL); + default: + throw new AnalysisException("format:" + formatString + " is not supported."); + } + } + + public static FileFormatProperties createFileFormatProperties(Map<String, String> formatProperties) + throws AnalysisException { + String formatString = formatProperties.getOrDefault(FileFormatBaseProperties.PROP_FORMAT, "") + .toLowerCase(); + return createFileFormatProperties(formatString); + } + + protected String getOrDefaultAndRemove(Map<String, String> props, String key, String defaultValue, Review Comment: Better name it as `getOrDefault()`, whether remove or not depends on the parameter `isRemove`, not the method's name. ########## fe/fe-core/src/main/java/org/apache/doris/datasource/property/fileformat/JsonFileFormatProperties.java: ########## @@ -0,0 +1,122 @@ +// 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.datasource.property.fileformat; + +import org.apache.doris.common.util.FileFormatConstants; +import org.apache.doris.common.util.Util; +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.proto.InternalService.PFetchTableSchemaRequest; +import org.apache.doris.thrift.TFileAttributes; +import org.apache.doris.thrift.TFileFormatType; +import org.apache.doris.thrift.TFileTextScanRangeParams; +import org.apache.doris.thrift.TResultFileSinkOptions; + +import java.util.Map; + +public class JsonFileFormatProperties extends FileFormatProperties { + // from ExternalFileTableValuedFunction: + private String jsonRoot = ""; + private String jsonPaths = ""; + private boolean stripOuterArray; + private boolean readJsonByLine; + private boolean numAsString; + private boolean fuzzyParse; + + + public JsonFileFormatProperties(TFileFormatType fileFormatType) { + super(fileFormatType); + } + + @Override + public void analyzeFileFormatProperties(Map<String, String> formatProperties, boolean isRemoveOriginProperty) + throws AnalysisException { + // 这几个json应该移到json checker中 + jsonRoot = getOrDefaultAndRemove(formatProperties, FileFormatConstants.PROP_JSON_ROOT, + "", isRemoveOriginProperty); + jsonPaths = getOrDefaultAndRemove(formatProperties, FileFormatConstants.PROP_JSON_PATHS, + "", isRemoveOriginProperty); + readJsonByLine = Boolean.valueOf( + getOrDefaultAndRemove(formatProperties, FileFormatConstants.PROP_READ_JSON_BY_LINE, + "", isRemoveOriginProperty)).booleanValue(); + stripOuterArray = Boolean.valueOf( + getOrDefaultAndRemove(formatProperties, FileFormatConstants.PROP_STRIP_OUTER_ARRAY, + "", isRemoveOriginProperty)).booleanValue(); + numAsString = Boolean.valueOf( + getOrDefaultAndRemove(formatProperties, FileFormatConstants.PROP_NUM_AS_STRING, + "", isRemoveOriginProperty)).booleanValue(); + fuzzyParse = Boolean.valueOf( + getOrDefaultAndRemove(formatProperties, FileFormatConstants.PROP_FUZZY_PARSE, + "", isRemoveOriginProperty)).booleanValue(); + + String compressTypeStr = getOrDefaultAndRemove(formatProperties, FileFormatConstants.PROP_COMPRESS_TYPE, + "UNKNOWN", isRemoveOriginProperty); + try { + compressionType = Util.getFileCompressType(compressTypeStr); + } catch (IllegalArgumentException e) { + throw new AnalysisException("Compress type : " + compressTypeStr + " is not supported."); Review Comment: I think we should let `Util.getFileCompressType` to handle the exception. If exception occurred, just return `TFileCompressType.UNKNOWN` ########## fe/fe-core/src/main/java/org/apache/doris/datasource/property/fileformat/CsvFileFormatProperties.java: ########## @@ -0,0 +1,195 @@ +// 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.datasource.property.fileformat; + +import org.apache.doris.analysis.Separator; +import org.apache.doris.catalog.Column; +import org.apache.doris.common.util.FileFormatUtils; +import org.apache.doris.common.util.Util; +import org.apache.doris.datasource.property.constants.CsvProperties; +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.proto.InternalService.PFetchTableSchemaRequest; +import org.apache.doris.qe.ConnectContext; +import org.apache.doris.thrift.TFileAttributes; +import org.apache.doris.thrift.TFileFormatType; +import org.apache.doris.thrift.TFileTextScanRangeParams; +import org.apache.doris.thrift.TResultFileSinkOptions; +import org.apache.doris.thrift.TTextSerdeType; + +import com.google.common.base.Strings; +import com.google.common.collect.Lists; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.List; +import java.util.Map; + +public class CsvFileFormatProperties extends FileFormatProperties { + public static final Logger LOG = LogManager.getLogger( + org.apache.doris.datasource.property.fileformat.CsvFileFormatProperties.class); + + private String headerType = ""; + private TTextSerdeType textSerdeType = TTextSerdeType.JSON_TEXT_SERDE; + private String columnSeparator = CsvProperties.DEFAULT_COLUMN_SEPARATOR; + private String lineDelimiter = CsvProperties.DEFAULT_LINE_DELIMITER; + private boolean trimDoubleQuotes; + private int skipLines; + private byte enclose; + + // used by tvf + // User specified csv columns, it will override columns got from file + private final List<Column> csvSchema = Lists.newArrayList(); + + String defaultColumnSeparator = CsvProperties.DEFAULT_COLUMN_SEPARATOR; + + public CsvFileFormatProperties(TFileFormatType fileFormatType) { + super(fileFormatType); + } + + public CsvFileFormatProperties(TFileFormatType fileFormatType, String defaultColumnSeparator, + TTextSerdeType textSerdeType) { + super(fileFormatType); + this.defaultColumnSeparator = defaultColumnSeparator; + this.textSerdeType = textSerdeType; + } + + public CsvFileFormatProperties(TFileFormatType fileFormatType, String headerType) { + super(fileFormatType); + this.headerType = headerType; + } + + + @Override + public void analyzeFileFormatProperties(Map<String, String> formatProperties, boolean isRemoveOriginProperty) + throws AnalysisException { + try { + // check properties specified by user -- formatProperties + columnSeparator = getOrDefaultAndRemove(formatProperties, CsvProperties.PROP_COLUMN_SEPARATOR, + defaultColumnSeparator, isRemoveOriginProperty); + if (Strings.isNullOrEmpty(columnSeparator)) { Review Comment: Same for other properties with default values ########## fe/fe-core/src/main/java/org/apache/doris/datasource/property/fileformat/FileFormatProperties.java: ########## @@ -0,0 +1,116 @@ +// 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.datasource.property.fileformat; + +import org.apache.doris.datasource.property.constants.CsvProperties; +import org.apache.doris.datasource.property.constants.FileFormatBaseProperties; +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.proto.InternalService.PFetchTableSchemaRequest; +import org.apache.doris.thrift.TFileAttributes; +import org.apache.doris.thrift.TFileCompressType; +import org.apache.doris.thrift.TFileFormatType; +import org.apache.doris.thrift.TResultFileSinkOptions; +import org.apache.doris.thrift.TTextSerdeType; + +import java.util.Map; + +public abstract class FileFormatProperties { + protected TFileFormatType fileFormatType; + + protected TFileCompressType compressionType; + + public FileFormatProperties(TFileFormatType fileFormatType) { + this.fileFormatType = fileFormatType; + } + + /** + * + * @param formatProperties + * @return properties needed by Doris + * @throws AnalysisException + */ + + /** + * Analyze user properties + * @param formatProperties properties specified by user + * @param isRemoveOriginProperty if this param is set to true, then this method would remove the origin property + * @throws AnalysisException + */ + public abstract void analyzeFileFormatProperties( + Map<String, String> formatProperties, boolean isRemoveOriginProperty) + throws AnalysisException; + + public abstract PFetchTableSchemaRequest toPFetchTableSchemaRequest(); + + public abstract TResultFileSinkOptions toTResultFileSinkOptions(); + + public abstract TFileAttributes toTFileAttributes(); + + public static FileFormatProperties createFileFormatProperties(String formatString) { + switch (formatString) { + case FileFormatBaseProperties.FORMAT_CSV: + return new CsvFileFormatProperties(TFileFormatType.FORMAT_CSV_PLAIN); + case FileFormatBaseProperties.FORMAT_HIVE_TEXT: + return new CsvFileFormatProperties(TFileFormatType.FORMAT_CSV_PLAIN, + CsvProperties.DEFAULT_HIVE_TEXT_COLUMN_SEPARATOR, + TTextSerdeType.HIVE_TEXT_SERDE); + case FileFormatBaseProperties.FORMAT_CSV_WITH_NAMES: + return new CsvFileFormatProperties(TFileFormatType.FORMAT_CSV_PLAIN, + FileFormatBaseProperties.FORMAT_CSV_WITH_NAMES); + case FileFormatBaseProperties.FORMAT_CSV_WITH_NAMES_AND_TYPES: + return new CsvFileFormatProperties(TFileFormatType.FORMAT_CSV_PLAIN, + FileFormatBaseProperties.FORMAT_CSV_WITH_NAMES_AND_TYPES); + case FileFormatBaseProperties.FORMAT_PARQUET: + return new ParquetFileFormatProperties(TFileFormatType.FORMAT_PARQUET); + case FileFormatBaseProperties.FORMAT_ORC: + return new OrcFileFormatProperties(TFileFormatType.FORMAT_ORC); + case FileFormatBaseProperties.FORMAT_JSON: + return new JsonFileFormatProperties(TFileFormatType.FORMAT_JSON); + case FileFormatBaseProperties.FORMAT_AVRO: + return new AvroFileFormatProperties(TFileFormatType.FORMAT_AVRO); + case FileFormatBaseProperties.FORMAT_WAL: + return new WalFileFormatProperties(TFileFormatType.FORMAT_WAL); + default: + throw new AnalysisException("format:" + formatString + " is not supported."); + } + } + + public static FileFormatProperties createFileFormatProperties(Map<String, String> formatProperties) Review Comment: Sometimes we may use the suffix of a file to guess its format. For example, the file path is /path/to/1.parquet, so we know that this is a parquet format, even if user does not specify the "file_format" property. We should handle this. 1. create a tool method to infer the file format from path. 2. change the signature of this `createFileFormatProperties` to `createFileFormatProperties(TFileFormatType fileFormat, properties)` And I think without the suffix and user specified "file_format" property, we should provide a "default" format file, eg, csv. But it depends because I am not sure what the previous logic is ########## fe/fe-core/src/main/java/org/apache/doris/datasource/property/constants/JsonProperties.java: ########## @@ -0,0 +1,27 @@ +// 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.datasource.property.constants; + +public class JsonProperties { Review Comment: I think we can merge these class under `constants` package into classes under `fileformat` package. For example, `JsonProperties` only defines some constants string, which can be placed in `JsonFileFormatProperties`? -- 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