Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ private int asColNum(String column) {
}
}
// TODO Java8
throw new RuntimeException("no column " + column + " in columns list " + getColumnNames());
throw new RuntimeException("no column " + column + " in columns list " + getColumnNamesString());
}

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

public String[] getColumnNames() {
String[] columnNames = new String[columns.size()];
for (int i = 0; i < columns.size(); ++i) {
columnNames[i] = columns.get(i).getColumnName();
}
return columnNames;
}

@Override
public void setFetchDirection(int direction) throws SQLException {
// ignore perfomance hint
Expand All @@ -714,7 +722,7 @@ public String toString() {
", bis=" + bis +
", db='" + db + '\'' +
", table='" + table + '\'' +
", columns=" + getColumnNames() +
", columns=" + getColumnNamesString() +
", maxRows=" + maxRows +
", values=" + Arrays.toString(values) +
", lastReadColumn=" + lastReadColumn +
Expand All @@ -724,7 +732,7 @@ public String toString() {
'}';
}

private String getColumnNames() {
private String getColumnNamesString() {
StringBuilder sb = new StringBuilder();
for (ClickHouseColumnInfo info : columns) {
sb.append(info.getColumnName()).append(' ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,25 @@ public void testClassNamesObjects() throws Exception {
}
}

@Test
public void testGetColumnNames() throws Exception {
String response = "SiteName\tCountry\n" +
"String\tString\n" +
"hello.com\tPoland\n" +
"there.com\tUSA\n" +
"\t\n" +
"other.com\t\n" +
"\n" +
"\t\n";

ByteArrayInputStream is = new ByteArrayInputStream(response.getBytes("UTF-8"));

ClickHouseResultSet rs = buildResultSet(is, 1024, "db", "table", false, null, null, props);
String[] columnNames = rs.getColumnNames();
assertEquals(2, columnNames.length);
assertEquals("SiteName", columnNames[0]);
assertEquals("Country", columnNames[1]);
}

/**
* By jdbc specification
Expand Down