ColumnTypeDetector { public ColumnType[] detectColumnTypes(Iterator<String[]> rows, ReadOptions options) { boolean useSampling = options.sample(); List<ColumnType> columnTypes = new ArrayList<>(); List<List<String>> columnData = new ArrayList<>(); int rowCount = 0; int nextRow = 0; while (rows.hasNext()) { String[] nextLine = rows.next(); if (rowCount == 0) { for (int i = 0; i < nextLine.length; i++) { columnData.add(new ArrayList<>()); } } int columnNumber = 0; if (rowCount == nextRow) { for (String field : nextLine) { columnData.get(columnNumber).add(field); columnNumber++; } if (useSampling) { nextRow = nextRow(nextRow); } else { nextRow = nextRowWithoutSampling(nextRow); } } rowCount++; } for (List<String> valuesList : columnData) { ColumnType detectedType = detectType(valuesList, options); if (detectedType.equals(StringColumnType.STRING) && rowCount > STRING_COLUMN_ROW_COUNT_CUTOFF) { HashSet<String> unique = new HashSet<>(valuesList); double uniquePct = unique.size() / (valuesList.size() * 1.0); if (uniquePct > STRING_COLUMN_CUTOFF) { detectedType = TEXT; } } columnTypes.add(detectedType); } return columnTypes.toArray(new ColumnType[0]); } ColumnTypeDetector(List<ColumnType> typeArray); ColumnType[] detectColumnTypes(Iterator<String[]> rows, ReadOptions options);  }
@Test void detectColumnTypes() { String[][] val = {{"", "2010-05-03", "x"}, {"", "", ""}}; ArrayList<String[]> dates = Lists.newArrayList(val); ColumnTypeDetector detector = new ColumnTypeDetector( Lists.newArrayList( LOCAL_DATE_TIME, LOCAL_TIME, LOCAL_DATE, BOOLEAN, SHORT, INTEGER, LONG, FLOAT, DOUBLE, STRING, TEXT)); ColumnType[] types = detector.detectColumnTypes(dates.iterator(), new ReadOptions.Builder().build()); assertEquals(TextColumnType.instance(), types[0]); assertEquals(DateColumnType.instance(), types[1]); assertEquals(StringColumnType.instance(), types[2]); }