diff --git a/src/main/java/net/snowflake/client/core/SFArrowResultSet.java b/src/main/java/net/snowflake/client/core/SFArrowResultSet.java index 38dd77ab5..69195e8a4 100644 --- a/src/main/java/net/snowflake/client/core/SFArrowResultSet.java +++ b/src/main/java/net/snowflake/client/core/SFArrowResultSet.java @@ -576,7 +576,7 @@ public Object getObject(int columnIndex) throws SFException { converter.setSessionTimeZone(sessionTimeZone); Object obj = converter.toObject(index); boolean isStructuredType = resultSetMetaData.isStructuredTypeColumn(columnIndex); - if (type == Types.STRUCT && isStructuredType && converter instanceof VarCharConverter) { + if (isVarcharConvertedStruct(type, isStructuredType, converter)) { if (obj != null) { return new StructObjectWrapper((String) obj, createJsonSqlInput(columnIndex, obj)); } @@ -584,6 +584,11 @@ public Object getObject(int columnIndex) throws SFException { return obj; } + private boolean isVarcharConvertedStruct( + int type, boolean isStructuredType, ArrowVectorConverter converter) { + return type == Types.STRUCT && isStructuredType && converter instanceof VarCharConverter; + } + private Object createJsonSqlInput(int columnIndex, Object obj) throws SFException { try { if (obj == null) { diff --git a/src/main/java/net/snowflake/client/core/SfSqlArray.java b/src/main/java/net/snowflake/client/core/SfSqlArray.java index c98db4473..4966d7ab8 100644 --- a/src/main/java/net/snowflake/client/core/SfSqlArray.java +++ b/src/main/java/net/snowflake/client/core/SfSqlArray.java @@ -1,6 +1,7 @@ package net.snowflake.client.core; import static net.snowflake.client.core.FieldSchemaCreator.buildBindingSchemaForType; +import static net.snowflake.client.core.FieldSchemaCreator.logger; import com.fasterxml.jackson.core.JsonProcessingException; import java.sql.Array; @@ -19,6 +20,7 @@ public class SfSqlArray implements Array { private String text; private int baseType; private Object elements; + private String jsonStringFromElements; public SfSqlArray(String text, int baseType, Object elements) { this.text = text; @@ -87,13 +89,21 @@ public ResultSet getResultSet(long index, int count, Map> map) @Override public void free() throws SQLException {} - public String getJsonString() throws SQLException { + public String getText() { if (text == null) { - text = buildJsonStringFromElements(elements); + logger.warn("Text field wasn't initialized. Should never happen."); } return text; } + public String getJsonString() throws SQLException { + if (jsonStringFromElements == null) { + jsonStringFromElements = buildJsonStringFromElements(elements); + } + + return jsonStringFromElements; + } + private static String buildJsonStringFromElements(Object elements) throws SQLException { try { return SnowflakeUtil.mapJson(elements); diff --git a/src/main/java/net/snowflake/client/jdbc/SnowflakeResultSetV1.java b/src/main/java/net/snowflake/client/jdbc/SnowflakeResultSetV1.java index dfe8cbad6..e9db5ec71 100644 --- a/src/main/java/net/snowflake/client/jdbc/SnowflakeResultSetV1.java +++ b/src/main/java/net/snowflake/client/jdbc/SnowflakeResultSetV1.java @@ -279,7 +279,7 @@ public Object getObject(int columnIndex) throws SQLException { } else if (object instanceof StructObjectWrapper) { return ((StructObjectWrapper) object).getJsonString(); } else if (object instanceof SfSqlArray) { - return ((SfSqlArray) object).getJsonString(); + return ((SfSqlArray) object).getText(); } else if (object instanceof ArrowSqlInput) { throw new SQLException( "Arrow native struct couldn't be converted to String. To map to SqlData the method getObject(int columnIndex, Class type) should be used");