Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fir 32148 resultset getters case insensitive #382

Merged
merged 1 commit into from
Apr 14, 2024
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
15 changes: 15 additions & 0 deletions src/integrationTest/java/integration/tests/StatementTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,19 @@ void failingQuery(String query) throws SQLException {
assertThrows(SQLException.class, () -> statement.execute(query));
}
}

@Test
void caseInsensitiveGetter() throws SQLException {
try (Connection connection = createConnection(); Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("select table_schema, table_name as NAME from information_schema.tables")) {
while(rs.next()) {
assertEquals(rs.getString("table_schema"), rs.getString("TABLE_SCHEMA"));
assertEquals(rs.getString("table_schema"), rs.getString("Table_Schema"));
assertEquals(rs.getString("table_schema"), rs.getString("TaBlE_ScHeMa"));
assertEquals(rs.getString("name"), rs.getString("NAME"));
assertEquals(rs.getString("name"), rs.getString("NaMe"));
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static com.firebolt.jdbc.util.StringUtil.splitAll;
import static java.lang.String.CASE_INSENSITIVE_ORDER;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Optional.ofNullable;
Expand Down Expand Up @@ -100,7 +101,7 @@ public FireboltResultSet(InputStream is, String tableName, String dbName, Intege
private FireboltResultSet() {
reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream("".getBytes()), UTF_8)); // empty InputStream
resultSetMetaData = new FireboltResultSetMetaData(null, null, List.of());
columnNameToColumnNumber = new HashMap<>();
columnNameToColumnNumber = new TreeMap<>(CASE_INSENSITIVE_ORDER);
currentLine = null;
columns = new ArrayList<>();
statement = null;
Expand Down Expand Up @@ -534,7 +535,7 @@ private int getColumnIndex(int colNum) throws SQLException {
}

private Map<String, Integer> getColumnNamesToIndexes(String[] fields) {
Map<String, Integer> columnNameToFieldIndex = new HashMap<>();
Map<String, Integer> columnNameToFieldIndex = new TreeMap<>(CASE_INSENSITIVE_ORDER);
if (fields != null) {
for (int i = 0; i < fields.length; i++) {
columnNameToFieldIndex.put(fields[i], i + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.sql.Array;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
Expand Down Expand Up @@ -1242,6 +1243,28 @@ void shouldReturnUrl() throws SQLException, MalformedURLException {
assertNull(resultSet.getURL("url"));
}

@Test
void shouldBeCaseInsensitive() throws SQLException {
inputStream = getInputStreamWithCommonResponseExample();
resultSet = new FireboltResultSet(inputStream, "a_table", "a_db", 65535);
resultSet.next();
ResultSetMetaData rsmd = resultSet.getMetaData();
int n = rsmd.getColumnCount();
for (int i = 1; i <= n; i++) {
String columnName = rsmd.getColumnName(i);
Object value = resultSet.getObject(columnName);
Object upperCaseValue = resultSet.getObject(columnName.toUpperCase());
Object lowerCaseValue = resultSet.getObject(columnName.toLowerCase());
if (rsmd.getColumnType(i) == Types.ARRAY) {
assertArrayEquals((Object[])value, (Object[])upperCaseValue);
assertArrayEquals((Object[])value, (Object[])lowerCaseValue);
} else {
assertEquals(value, upperCaseValue);
assertEquals(value, lowerCaseValue);
}
}
}

private void assertStream(byte[] expected, InputStream stream) throws IOException {
assertArrayEquals(expected, stream == null ? null : stream.readAllBytes());
}
Expand Down
Loading