Skip to content
Open
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 @@ -349,7 +349,7 @@ public Binary getBlob(String columnName) throws StatementExecutionException {
return ioTDBRpcDataSet.getBinary(columnName);
}

public int findColumn(String columnName) {
public int findColumn(String columnName) throws StatementExecutionException {
return ioTDBRpcDataSet.findColumn(columnName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,12 @@ public void deleteRow() throws SQLException {
}

@Override
public int findColumn(String columnName) {
return ioTDBRpcDataSet.findColumn(columnName);
public int findColumn(String columnName) throws SQLException {
try {
return ioTDBRpcDataSet.findColumn(columnName);
} catch (StatementExecutionException e) {
throw new SQLException(e.getMessage());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.nio.ByteBuffer;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.sql.Types;
Expand Down Expand Up @@ -363,4 +364,41 @@ private List<ByteBuffer> FakedFirstFetchTsBlockResult() {

return Collections.singletonList(tsBlock);
}

@Test
public void findColumnUnknownColumnThrowsSQLExceptionNotNpe() throws Exception {
List<String> columns = new ArrayList<>();
columns.add("root.vehicle.d0.s0");
List<String> dataTypeList = new ArrayList<>();
dataTypeList.add("INT32");
when(execResp.isSetColumns()).thenReturn(true);
when(execResp.getColumns()).thenReturn(columns);
when(execResp.isSetDataTypeList()).thenReturn(true);
when(execResp.getDataTypeList()).thenReturn(dataTypeList);
when(execResp.isSetOperationType()).thenReturn(true);
when(execResp.getOperationType()).thenReturn("QUERY");
when(execResp.isSetQueryId()).thenReturn(true);
when(execResp.getQueryId()).thenReturn(queryId);
when(execResp.isSetTableModel()).thenReturn(false);
when(execResp.isIgnoreTimeStamp()).thenReturn(false);
List<Integer> columnIndex2TsBlockColumnIndexList = new ArrayList<>();
columnIndex2TsBlockColumnIndexList.add(0);
when(execResp.getColumnIndex2TsBlockColumnIndexList())
.thenReturn(columnIndex2TsBlockColumnIndexList);

Assert.assertTrue(statement.execute("select s0 from root.vehicle.d0"));
try (ResultSet resultSet = statement.getResultSet()) {
// a known column resolves to its 1-based index
Assert.assertEquals(1, resultSet.findColumn("Time"));
// an unknown column must throw a clear SQLException, not a NullPointerException
try {
resultSet.findColumn("no_such_column");
Assert.fail("findColumn on an unknown column must throw SQLException");
} catch (SQLException e) {
Assert.assertTrue(
"message should name the missing column, got: " + e.getMessage(),
e.getMessage() != null && e.getMessage().contains("no_such_column"));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,12 @@ public Timestamp getTimestamp(String columnName) throws StatementExecutionExcept
return getTimestamp(findColumn(columnName));
}

public int findColumn(String columnName) {
return columnOrdinalMap.get(columnName);
public int findColumn(String columnName) throws StatementExecutionException {
Integer ordinal = columnOrdinalMap.get(columnName);
if (ordinal == null) {
throw new StatementExecutionException(RpcMessages.UNKNOWN_COLUMN_NAME + columnName);
}
return ordinal;
}

public String getValueByName(String columnName) throws StatementExecutionException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,12 @@ private TSDataType getDataTypeByTsBlockColumnIndex(int tsBlockColumnIndex) {
: dataTypeForTsBlockColumn.get(tsBlockColumnIndex);
}

public int findColumn(String columnName) {
return columnOrdinalMap.get(columnName);
public int findColumn(String columnName) throws StatementExecutionException {
Integer ordinal = columnOrdinalMap.get(columnName);
if (ordinal == null) {
throw new StatementExecutionException(RpcMessages.UNKNOWN_COLUMN_NAME + columnName);
}
return ordinal;
}

public String findColumnNameByIndex(int columnIndex) throws StatementExecutionException {
Expand Down