swaminathanmanish commented on code in PR #10856:
URL: https://github.com/apache/pinot/pull/10856#discussion_r1220186303


##########
pinot-plugins/pinot-input-format/pinot-csv/src/main/java/org/apache/pinot/plugin/inputformat/csv/CSVDefaultHeaderUtil.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.pinot.plugin.inputformat.csv;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVParser;
+import org.apache.commons.csv.CSVRecord;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.math.NumberUtils;
+import org.apache.pinot.spi.data.readers.RecordReaderUtils;
+
+
+public class CSVDefaultHeaderUtil {
+
+  private CSVDefaultHeaderUtil() {
+  }
+
+  private static final String DEFAULT_CSV_COLUMN_PREFIX = "col_";
+  private static final int MAX_CSV_SAMPLE_ROWS = 100;
+
+  static class ColumnValueAttributes {
+    private Type _dataType;
+    private int _length;
+
+    enum Type {
+      STRING, NUMBER, ARRAY
+    }
+
+    ColumnValueAttributes(Object value, Character multiValueDelimiter) {
+      _dataType = Type.STRING;
+      if (multiValueDelimiter != null && 
value.toString().contains(String.valueOf(multiValueDelimiter))) {
+        _dataType = Type.ARRAY;
+        return;
+      } else if (NumberUtils.isParsable(value.toString())) {
+        _dataType = Type.NUMBER;
+      }
+      _length = value.toString().length();
+    }
+
+    public Type getDataType() {
+      return _dataType;
+    }
+
+    public int getLength() {
+      return _length;
+    }
+  }
+
+  /**
+   * Detects the types for each column based on the row values. If any column 
is of a single type (e.g. number), except
+   * for the first row, then the first row is presumed to be a header. If the 
type of the column is assumed to
+   * be a string, the length of the strings within the body is the determining 
factor. Specifically, if all the rows
+   * except the first are the same length, it's a header.

Review Comment:
   Can this go wrong in detecting the header (especially when using strings to 
detect) ? if so what happens?
   



-- 
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...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to