File tree Expand file tree Collapse file tree 3 files changed +25
-13
lines changed
client-v2/src/main/java/com/clickhouse/client/api Expand file tree Collapse file tree 3 files changed +25
-13
lines changed Original file line number Diff line number Diff line change @@ -577,11 +577,7 @@ public boolean hasValue(int colIndex) {
577577
578578 @ Override
579579 public boolean hasValue (String colName ) {
580- try {
581- return hasValue (schema .nameToColumnIndex (colName ));
582- } catch (NoSuchColumnException e ) {
583- return false ;
584- }
580+ return hasValue (schema .findColumnIndex (colName ));
585581 }
586582
587583 @ Override
Original file line number Diff line number Diff line change 1212import com .clickhouse .data .value .ClickHouseGeoPointValue ;
1313import com .clickhouse .data .value .ClickHouseGeoPolygonValue ;
1414import com .clickhouse .data .value .ClickHouseGeoRingValue ;
15+ import com .google .common .collect .ImmutableList ;
1516
1617import java .math .BigDecimal ;
1718import java .math .BigInteger ;
@@ -311,11 +312,8 @@ public String[] getStringArray(String colName) {
311312
312313 @ Override
313314 public boolean hasValue (int colIndex ) {
314- try {
315- return hasValue (schema .columnIndexToName (colIndex ));
316- } catch (NoSuchColumnException e ) {
317- return false ;
318- }
315+ String columnName = schema .findColumnName (colIndex );
316+ return columnName != null && hasValue (columnName );
319317 }
320318
321319 @ Override
Original file line number Diff line number Diff line change @@ -86,11 +86,10 @@ public ClickHouseColumn getColumnByIndex(int colIndex) {
8686 * @return - column name
8787 */
8888 public String indexToName (int index ) {
89- try {
90- return columns .get (index ).getColumnName ();
91- } catch (IndexOutOfBoundsException e ) {
89+ if (index < 0 || index >= columns .size ()) {
9290 throw new NoSuchColumnException ("Result has no column with index = " + index );
9391 }
92+ return columns .get (index ).getColumnName ();
9493 }
9594
9695 /**
@@ -129,6 +128,25 @@ public int nameToIndex(String name) {
129128 return index ;
130129 }
131130
131+ /**
132+ * Looks up for column 1-based index for a column name.
133+ * @param columnName - name of column to search
134+ * @return column 1-based index of column or -1 if not found
135+ */
136+ public int findColumnIndex (String columnName ) {
137+ Integer index = colIndex .get (columnName );
138+ return index == null ? -1 : index + 1 ;
139+ }
140+
141+ public String findColumnName (int colIndex ) {
142+ int lookupIndex = colIndex - 1 ;
143+ if (lookupIndex < 0 || lookupIndex >= columns .size ()) {
144+ return null ;
145+ }
146+
147+ return columns .get (lookupIndex ).getColumnName ();
148+ }
149+
132150 @ Override
133151 public String toString () {
134152 return "TableSchema{" +
You can’t perform that action at this time.
0 commit comments