JingsongLi commented on code in PR #6093: URL: https://github.com/apache/paimon/pull/6093#discussion_r2284436091
########## paimon-format/src/main/java/org/apache/paimon/format/csv/CsvFileReader.java: ########## @@ -0,0 +1,238 @@ +/* + * 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.paimon.format.csv; + +import org.apache.paimon.casting.CastExecutor; +import org.apache.paimon.casting.CastExecutors; +import org.apache.paimon.data.BinaryString; +import org.apache.paimon.data.GenericRow; +import org.apache.paimon.data.InternalRow; +import org.apache.paimon.format.FormatReaderFactory; +import org.apache.paimon.fs.FileIO; +import org.apache.paimon.fs.Path; +import org.apache.paimon.fs.SeekableInputStream; +import org.apache.paimon.options.FormatOptions; +import org.apache.paimon.options.Options; +import org.apache.paimon.reader.FileRecordIterator; +import org.apache.paimon.reader.FileRecordReader; +import org.apache.paimon.types.DataType; +import org.apache.paimon.types.DataTypeRoot; +import org.apache.paimon.types.DataTypes; +import org.apache.paimon.types.RowType; + +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.dataformat.csv.CsvMapper; +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.dataformat.csv.CsvSchema; + +import javax.annotation.Nullable; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** CSV file reader implementation. */ +public class CsvFileReader implements FileRecordReader<InternalRow> { + + private static final CsvMapper CSV_MAPPER = new CsvMapper(); + private static final Base64.Decoder BASE64_DECODER = Base64.getDecoder(); + + // Performance optimization: Cache frequently used cast executors + private static final Map<String, CastExecutor<?, ?>> CAST_EXECUTOR_CACHE = + new ConcurrentHashMap<>(32); + + private final RowType rowType; + private final String fieldDelimiter; + private final String nullLiteral; + private final boolean includeHeader; + private final String quoteCharacter; + private final String escapeCharacter; + private final Path filePath; + private final CsvSchema schema; + + private BufferedReader bufferedReader; + private boolean headerSkipped = false; + private boolean readerClosed = false; + private CsvRecordIterator reader; + + public CsvFileReader(FormatReaderFactory.Context context, RowType rowType, Options options) + throws IOException { + this.rowType = rowType; + this.filePath = context.filePath(); + this.fieldDelimiter = options.get(FormatOptions.FIELD_DELIMITER); Review Comment: Create a class `CsvOptions` to contains all options: ``` CsvOptions { All static options here. private final String fieldDelimiter; private final String nullLiteral; private final boolean includeHeader; private final String quoteCharacter; private final String escapeCharacter; public CsvOptions(Options options) } ``` -- 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: issues-unsubscr...@paimon.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org