4646import org .slf4j .Logger ;
4747import org .slf4j .LoggerFactory ;
4848
49+ import it .unimi .dsi .fastutil .objects .Object2IntMap ;
50+ import it .unimi .dsi .fastutil .objects .Object2IntOpenHashMap ;
4951import tech .tablesaw .api .ColumnType ;
5052import tech .tablesaw .io .ReadOptions ;
5153
@@ -71,6 +73,7 @@ public enum UnnanotatedBinaryAs {
7173 private final boolean floatColumnTypeUsed ;
7274 private final ManageGroupsAs manageGroupsAs ;
7375 private final List <String > columns ;
76+ private final Object2IntMap <String > columnIndex ;
7477 private final URI inputURI ;
7578 private final FileDecryptionProperties fileDecryptionProperties ;
7679 private final Filter recordFilter ;
@@ -81,6 +84,11 @@ protected TablesawParquetReadOptions(final Builder builder) {
8184 unnanotatedBinaryAs = builder .unnanotatedBinaryAs ;
8285 manageGroupsAs = builder .manageGroupsAs ;
8386 columns = Collections .unmodifiableList (Arrays .asList (builder .columns ));
87+ final int nbCols = columns .size ();
88+ columnIndex = new Object2IntOpenHashMap <>(nbCols );
89+ for (int i = nbCols ; --i >= 0 ; ) {
90+ columnIndex .put (columns .get (i ), i );
91+ }
8492 inputURI = builder .inputURI ;
8593 shortColumnTypeUsed = this .columnTypesToDetect .contains (ColumnType .SHORT );
8694 floatColumnTypeUsed = this .columnTypesToDetect .contains (ColumnType .FLOAT );
@@ -124,7 +132,16 @@ public List<String> getColumns() {
124132 */
125133 public boolean hasColumn (final String columnName ) {
126134 if (columns .isEmpty ()) return true ;
127- return columns .contains (columnName );
135+ return columnIndex .containsKey (columnName );
136+ }
137+
138+ /**
139+ * Returns the index of the given column name or -1 if not in the column list
140+ * @param columnName the column name to get the index for
141+ * @return the column index or -1 if not in the list
142+ */
143+ public int indexOfColumn (final String columnName ) {
144+ return columnIndex .getOrDefault (columnName , -1 );
128145 }
129146
130147 public URI getInputURI () {
0 commit comments