Skip to content

Commit ebd0f06

Browse files
SNOW-1234216 Add checks for structured types for getMap, getObject and getArray … (#1694)
1 parent 846c7f9 commit ebd0f06

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

src/main/java/net/snowflake/client/jdbc/SnowflakeBaseResultSet.java

+26-14
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import net.snowflake.client.core.SFBaseSession;
4747
import net.snowflake.client.core.SFException;
4848
import net.snowflake.client.core.structs.SQLDataCreationHelper;
49+
import net.snowflake.client.core.structs.StructureTypeHelper;
4950
import net.snowflake.client.log.SFLogger;
5051
import net.snowflake.client.log.SFLoggerFactory;
5152
import net.snowflake.common.core.SqlState;
@@ -1352,21 +1353,24 @@ public void updateNClob(String columnLabel, Reader reader) throws SQLException {
13521353
@Override
13531354
public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
13541355
logger.debug("public <T> T getObject(int columnIndex,Class<T> type)", false);
1355-
if (SQLData.class.isAssignableFrom(type)) {
1356-
SQLData instance = (SQLData) SQLDataCreationHelper.create(type);
1357-
SQLInput sqlInput = (SQLInput) getObject(columnIndex);
1358-
instance.readSQL(sqlInput, null);
1359-
return (T) instance;
1360-
} else if (Map.class.isAssignableFrom(type)) {
1361-
Object object = getObject(columnIndex);
1362-
if (object instanceof JsonSqlInput) {
1363-
JsonNode jsonNode = ((JsonSqlInput) object).getInput();
1364-
return (T)
1365-
OBJECT_MAPPER.convertValue(jsonNode, new TypeReference<Map<String, Object>>() {});
1366-
} else {
1367-
return (T) ((ArrowSqlInput) object).getInput();
1356+
if (StructureTypeHelper.isStructureTypeEnabled()) {
1357+
if (SQLData.class.isAssignableFrom(type)) {
1358+
SQLData instance = (SQLData) SQLDataCreationHelper.create(type);
1359+
SQLInput sqlInput = (SQLInput) getObject(columnIndex);
1360+
instance.readSQL(sqlInput, null);
1361+
return (T) instance;
1362+
} else if (Map.class.isAssignableFrom(type)) {
1363+
Object object = getObject(columnIndex);
1364+
if (object instanceof JsonSqlInput) {
1365+
JsonNode jsonNode = ((JsonSqlInput) object).getInput();
1366+
return (T)
1367+
OBJECT_MAPPER.convertValue(jsonNode, new TypeReference<Map<String, Object>>() {});
1368+
} else {
1369+
return (T) ((ArrowSqlInput) object).getInput();
1370+
}
13681371
}
1369-
} else if (String.class.isAssignableFrom(type)) {
1372+
}
1373+
if (String.class.isAssignableFrom(type)) {
13701374
return (T) getString(columnIndex);
13711375
} else if (Boolean.class.isAssignableFrom(type)) {
13721376
return (T) (Boolean) getBoolean(columnIndex);
@@ -1405,6 +1409,10 @@ public <T> List<T> getList(int columnIndex, Class<T> type) throws SQLException {
14051409
}
14061410

14071411
public <T> T[] getArray(int columnIndex, Class<T> type) throws SQLException {
1412+
logger.debug("public <T> T[] getArray(int columnIndex, Class<T> type)", false);
1413+
if (!StructureTypeHelper.isStructureTypeEnabled()) {
1414+
throw new SnowflakeLoggedFeatureNotSupportedException(session);
1415+
}
14081416
FieldMetadata fieldMetadata =
14091417
sfBaseResultSet.getMetaData().getColumnMetadata().get(columnIndex - 1).getFields().get(0);
14101418
int columnSubType = fieldMetadata.getType();
@@ -1545,6 +1553,10 @@ public <T> T[] getArray(int columnIndex, Class<T> type) throws SQLException {
15451553
}
15461554

15471555
public <T> Map<String, T> getMap(int columnIndex, Class<T> type) throws SQLException {
1556+
logger.debug("public <T> Map<String, T> getMap(int columnIndex, Class<T> type)", false);
1557+
if (!StructureTypeHelper.isStructureTypeEnabled()) {
1558+
throw new SnowflakeLoggedFeatureNotSupportedException(session);
1559+
}
15481560
FieldMetadata valueFieldMetadata =
15491561
sfBaseResultSet.getMetaData().getColumnMetadata().get(columnIndex - 1).getFields().get(1);
15501562
int columnSubType = valueFieldMetadata.getType();

src/main/java/net/snowflake/client/jdbc/SnowflakeResultSetV1.java

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import net.snowflake.client.core.QueryStatus;
3232
import net.snowflake.client.core.SFBaseResultSet;
3333
import net.snowflake.client.core.SFException;
34+
import net.snowflake.client.core.structs.StructureTypeHelper;
3435

3536
/** Snowflake ResultSet implementation */
3637
public class SnowflakeResultSetV1 extends SnowflakeBaseResultSet
@@ -272,6 +273,9 @@ public Object getObject(int columnIndex) throws SQLException {
272273
}
273274

274275
public Array getArray(int columnIndex) throws SQLException {
276+
if (!StructureTypeHelper.isStructureTypeEnabled()) {
277+
throw new SnowflakeLoggedFeatureNotSupportedException(session);
278+
}
275279
raiseSQLExceptionIfResultSetIsClosed();
276280
try {
277281
return sfBaseResultSet.getArray(columnIndex);

0 commit comments

Comments
 (0)