Skip to content

Commit 079dfaa

Browse files
author
Petr
committed
restore public getColumnNames method
1 parent 60f4f0c commit 079dfaa

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/main/java/ru/yandex/clickhouse/response/ClickHouseResultSet.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ private int asColNum(String column) {
641641
}
642642
}
643643
// TODO Java8
644-
throw new RuntimeException("no column " + column + " in columns list " + getColumnNames());
644+
throw new RuntimeException("no column " + column + " in columns list " + getColumnNamesString());
645645
}
646646

647647
private ByteFragment getValue(int colNum) {
@@ -695,6 +695,14 @@ public BigDecimal getBigDecimal(int columnIndex, int scale) {
695695
return result.setScale(scale, RoundingMode.HALF_UP);
696696
}
697697

698+
public String[] getColumnNames() {
699+
String[] columnNames = new String[columns.size()];
700+
for (int i = 0; i < columns.size(); ++i) {
701+
columnNames[i] = columns.get(i).getColumnName();
702+
}
703+
return columnNames;
704+
}
705+
698706
@Override
699707
public void setFetchDirection(int direction) throws SQLException {
700708
// ignore perfomance hint
@@ -714,7 +722,7 @@ public String toString() {
714722
", bis=" + bis +
715723
", db='" + db + '\'' +
716724
", table='" + table + '\'' +
717-
", columns=" + getColumnNames() +
725+
", columns=" + getColumnNamesString() +
718726
", maxRows=" + maxRows +
719727
", values=" + Arrays.toString(values) +
720728
", lastReadColumn=" + lastReadColumn +
@@ -724,7 +732,7 @@ public String toString() {
724732
'}';
725733
}
726734

727-
private String getColumnNames() {
735+
private String getColumnNamesString() {
728736
StringBuilder sb = new StringBuilder();
729737
for (ClickHouseColumnInfo info : columns) {
730738
sb.append(info.getColumnName()).append(' ');

src/test/java/ru/yandex/clickhouse/response/ClickHouseResultSetTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,25 @@ public void testClassNamesObjects() throws Exception {
448448
}
449449
}
450450

451+
@Test
452+
public void testGetColumnNames() throws Exception {
453+
String response = "SiteName\tCountry\n" +
454+
"String\tString\n" +
455+
"hello.com\tPoland\n" +
456+
"there.com\tUSA\n" +
457+
"\t\n" +
458+
"other.com\t\n" +
459+
"\n" +
460+
"\t\n";
461+
462+
ByteArrayInputStream is = new ByteArrayInputStream(response.getBytes("UTF-8"));
463+
464+
ClickHouseResultSet rs = buildResultSet(is, 1024, "db", "table", false, null, null, props);
465+
String[] columnNames = rs.getColumnNames();
466+
assertEquals(2, columnNames.length);
467+
assertEquals("SiteName", columnNames[0]);
468+
assertEquals("Country", columnNames[1]);
469+
}
451470

452471
/**
453472
* By jdbc specification

0 commit comments

Comments
 (0)