From 44f9c15a2fb66affd8b3ff071f0bf934592e817d Mon Sep 17 00:00:00 2001 From: sfc-gh-astachowski Date: Tue, 24 Sep 2024 13:45:43 +0200 Subject: [PATCH] Merge fixes and closing in finally blocks --- .../ArrowFullVectorConverterUtil.java | 55 +++++---- .../FixedSizeListVectorConverter.java | 46 ++++---- .../ListVectorConverter.java | 43 ++++--- .../MapVectorConverter.java | 4 +- .../StructVectorConverter.java | 59 ++++++---- .../TimeVectorConverter.java | 25 ++-- .../client/jdbc/ArrowResultChunk.java | 3 +- .../snowflake/client/jdbc/ArrowBatchesIT.java | 111 ++++++++++-------- 8 files changed, 192 insertions(+), 154 deletions(-) diff --git a/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/ArrowFullVectorConverterUtil.java b/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/ArrowFullVectorConverterUtil.java index 8a4b19e86..82826f0d4 100644 --- a/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/ArrowFullVectorConverterUtil.java +++ b/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/ArrowFullVectorConverterUtil.java @@ -4,7 +4,6 @@ import java.util.Map; import java.util.TimeZone; - import net.snowflake.client.core.DataConversionContext; import net.snowflake.client.core.SFBaseSession; import net.snowflake.client.core.SFException; @@ -21,7 +20,8 @@ public class ArrowFullVectorConverterUtil { private ArrowFullVectorConverterUtil() {} - static Types.MinorType deduceType(ValueVector vector, SFBaseSession session) throws SnowflakeSQLLoggedException { + static Types.MinorType deduceType(ValueVector vector, SFBaseSession session) + throws SnowflakeSQLLoggedException { Types.MinorType type = Types.getMinorTypeForArrowType(vector.getField().getType()); // each column's metadata Map customMeta = vector.getField().getMetadata(); @@ -42,22 +42,22 @@ static Types.MinorType deduceType(ValueVector vector, SFBaseSession session) thr case VECTOR: return Types.MinorType.FIXED_SIZE_LIST; case TIME: - { - String scaleStr = vector.getField().getMetadata().get("scale"); - int sfScale = Integer.parseInt(scaleStr); - if (sfScale == 0) { - return Types.MinorType.TIMESEC; - } - if (sfScale <= 3) { - return Types.MinorType.TIMEMILLI; - } - if (sfScale <= 6) { - return Types.MinorType.TIMEMICRO; - } - if (sfScale <= 9) { - return Types.MinorType.TIMENANO; + { + String scaleStr = vector.getField().getMetadata().get("scale"); + int sfScale = Integer.parseInt(scaleStr); + if (sfScale == 0) { + return Types.MinorType.TIMESEC; + } + if (sfScale <= 3) { + return Types.MinorType.TIMEMILLI; + } + if (sfScale <= 6) { + return Types.MinorType.TIMEMICRO; + } + if (sfScale <= 9) { + return Types.MinorType.TIMENANO; + } } - } case TIMESTAMP_NTZ: return Types.MinorType.TIMESTAMPNANO; case TIMESTAMP_LTZ: @@ -101,7 +101,7 @@ public static FieldVector convert( return new BinaryVectorConverter(allocator, vector, context, session, idx).convert(); case DATEDAY: return new DateVectorConverter(allocator, vector, context, session, idx, timeZoneToUse) - .convert(); + .convert(); case TIMESEC: return new TimeSecVectorConverter(allocator, vector).convert(); case TIMEMILLI: @@ -111,18 +111,23 @@ public static FieldVector convert( case TIMENANO: return new TimeNanoVectorConverter(allocator, vector).convert(); case STRUCT: - return new StructVectorConverter(allocator, vector, context, session, idx, null) - .convert(); + return new StructVectorConverter( + allocator, vector, context, session, timeZoneToUse, idx, null) + .convert(); case LIST: - return new ListVectorConverter(allocator, vector, context, session, idx, null) - .convert(); + return new ListVectorConverter( + allocator, vector, context, session, timeZoneToUse, idx, null) + .convert(); case VARCHAR: return new VarCharVectorConverter(allocator, vector, context, session, idx).convert(); case MAP: - return new MapVectorConverter(allocator, vector, context, session, idx, null).convert(); + return new MapVectorConverter( + allocator, vector, context, session, timeZoneToUse, idx, null) + .convert(); case FIXED_SIZE_LIST: - return new FixedSizeListVectorConverter(allocator, vector, context, session, idx, null) - .convert(); + return new FixedSizeListVectorConverter( + allocator, vector, context, session, timeZoneToUse, idx, null) + .convert(); default: throw new SnowflakeSQLLoggedException( session, diff --git a/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/FixedSizeListVectorConverter.java b/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/FixedSizeListVectorConverter.java index 8be5ba8d9..49e020e4a 100644 --- a/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/FixedSizeListVectorConverter.java +++ b/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/FixedSizeListVectorConverter.java @@ -1,6 +1,7 @@ package net.snowflake.client.core.arrow.fullvectorconverters; import java.util.ArrayList; +import java.util.TimeZone; import net.snowflake.client.core.DataConversionContext; import net.snowflake.client.core.SFBaseSession; import net.snowflake.client.core.SFException; @@ -21,43 +22,48 @@ public class FixedSizeListVectorConverter implements ArrowFullVectorConverter { protected SFBaseSession session; protected int idx; protected Object valueTargetType; + private TimeZone timeZoneToUse; FixedSizeListVectorConverter( RootAllocator allocator, ValueVector vector, DataConversionContext context, SFBaseSession session, + TimeZone timeZoneToUse, int idx, Object valueTargetType) { this.allocator = allocator; this.vector = vector; this.context = context; this.session = session; + this.timeZoneToUse = timeZoneToUse; this.idx = idx; this.valueTargetType = valueTargetType; } @Override public FieldVector convert() throws SFException, SnowflakeSQLException { - FixedSizeListVector listVector = (FixedSizeListVector) vector; - FieldVector dataVector = listVector.getDataVector(); - FieldVector convertedDataVector = - ArrowFullVectorConverterUtil.convert( - allocator, dataVector, context, session, 0, valueTargetType); - FixedSizeListVector convertedListVector = - FixedSizeListVector.empty(listVector.getName(), listVector.getListSize(), allocator); - ArrayList fields = new ArrayList<>(); - fields.add(convertedDataVector.getField()); - convertedListVector.initializeChildrenFromFields(fields); - convertedListVector.allocateNew(); - convertedListVector.setValueCount(listVector.getValueCount()); - ArrowBuf validityBuffer = listVector.getValidityBuffer(); - convertedListVector - .getValidityBuffer() - .setBytes(0L, validityBuffer, 0L, validityBuffer.capacity()); - convertedDataVector.makeTransferPair(convertedListVector.getDataVector()).transfer(); - - vector.close(); - return convertedListVector; + try { + FixedSizeListVector listVector = (FixedSizeListVector) vector; + FieldVector dataVector = listVector.getDataVector(); + FieldVector convertedDataVector = + ArrowFullVectorConverterUtil.convert( + allocator, dataVector, context, session, timeZoneToUse, 0, valueTargetType); + FixedSizeListVector convertedListVector = + FixedSizeListVector.empty(listVector.getName(), listVector.getListSize(), allocator); + ArrayList fields = new ArrayList<>(); + fields.add(convertedDataVector.getField()); + convertedListVector.initializeChildrenFromFields(fields); + convertedListVector.allocateNew(); + convertedListVector.setValueCount(listVector.getValueCount()); + ArrowBuf validityBuffer = listVector.getValidityBuffer(); + convertedListVector + .getValidityBuffer() + .setBytes(0L, validityBuffer, 0L, validityBuffer.capacity()); + convertedDataVector.makeTransferPair(convertedListVector.getDataVector()).transfer(); + return convertedListVector; + } finally { + vector.close(); + } } } diff --git a/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/ListVectorConverter.java b/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/ListVectorConverter.java index fff8cfa7f..75763762c 100644 --- a/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/ListVectorConverter.java +++ b/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/ListVectorConverter.java @@ -1,6 +1,7 @@ package net.snowflake.client.core.arrow.fullvectorconverters; import java.util.ArrayList; +import java.util.TimeZone; import net.snowflake.client.core.DataConversionContext; import net.snowflake.client.core.SFBaseSession; import net.snowflake.client.core.SFException; @@ -21,18 +22,21 @@ public class ListVectorConverter implements ArrowFullVectorConverter { protected SFBaseSession session; protected int idx; protected Object valueTargetType; + private TimeZone timeZoneToUse; ListVectorConverter( RootAllocator allocator, ValueVector vector, DataConversionContext context, SFBaseSession session, + TimeZone timeZoneToUse, int idx, Object valueTargetType) { this.allocator = allocator; this.vector = vector; this.context = context; this.session = session; + this.timeZoneToUse = timeZoneToUse; this.idx = idx; this.valueTargetType = valueTargetType; } @@ -47,23 +51,26 @@ protected ListVector initVector(String name, Field field) { @Override public FieldVector convert() throws SFException, SnowflakeSQLException { - ListVector listVector = (ListVector) vector; - FieldVector dataVector = listVector.getDataVector(); - FieldVector convertedDataVector = - ArrowFullVectorConverterUtil.convert( - allocator, dataVector, context, session, 0, valueTargetType); - ListVector convertedListVector = initVector(vector.getName(), dataVector.getField()); - convertedListVector.allocateNew(); - convertedListVector.setValueCount(listVector.getValueCount()); - convertedListVector.getOffsetBuffer().setBytes(0, listVector.getOffsetBuffer()); - ArrowBuf validityBuffer = listVector.getValidityBuffer(); - convertedListVector - .getValidityBuffer() - .setBytes(0L, validityBuffer, 0L, validityBuffer.capacity()); - convertedListVector.setLastSet(listVector.getLastSet()); - convertedDataVector.makeTransferPair(convertedListVector.getDataVector()).transfer(); - - vector.close(); - return convertedListVector; + try { + ListVector listVector = (ListVector) vector; + FieldVector dataVector = listVector.getDataVector(); + FieldVector convertedDataVector = + ArrowFullVectorConverterUtil.convert( + allocator, dataVector, context, session, timeZoneToUse, 0, valueTargetType); + // TODO: change to convertedDataVector and make all necessary changes to make it work + ListVector convertedListVector = initVector(vector.getName(), dataVector.getField()); + convertedListVector.allocateNew(); + convertedListVector.setValueCount(listVector.getValueCount()); + convertedListVector.getOffsetBuffer().setBytes(0, listVector.getOffsetBuffer()); + ArrowBuf validityBuffer = listVector.getValidityBuffer(); + convertedListVector + .getValidityBuffer() + .setBytes(0L, validityBuffer, 0L, validityBuffer.capacity()); + convertedListVector.setLastSet(listVector.getLastSet()); + convertedDataVector.makeTransferPair(convertedListVector.getDataVector()).transfer(); + return convertedListVector; + } finally { + vector.close(); + } } } diff --git a/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/MapVectorConverter.java b/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/MapVectorConverter.java index ea47b60bf..0b8ec963e 100644 --- a/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/MapVectorConverter.java +++ b/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/MapVectorConverter.java @@ -1,6 +1,7 @@ package net.snowflake.client.core.arrow.fullvectorconverters; import java.util.ArrayList; +import java.util.TimeZone; import net.snowflake.client.core.DataConversionContext; import net.snowflake.client.core.SFBaseSession; import net.snowflake.client.core.SnowflakeJdbcInternalApi; @@ -18,9 +19,10 @@ public class MapVectorConverter extends ListVectorConverter { ValueVector vector, DataConversionContext context, SFBaseSession session, + TimeZone timeZoneToUse, int idx, Object valueTargetType) { - super(allocator, vector, context, session, idx, valueTargetType); + super(allocator, vector, context, session, timeZoneToUse, idx, valueTargetType); } @Override diff --git a/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/StructVectorConverter.java b/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/StructVectorConverter.java index f140d6b3d..ce61a34f8 100644 --- a/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/StructVectorConverter.java +++ b/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/StructVectorConverter.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.TimeZone; import java.util.stream.Collectors; import net.snowflake.client.core.DataConversionContext; import net.snowflake.client.core.SFBaseSession; @@ -25,51 +26,57 @@ public class StructVectorConverter implements ArrowFullVectorConverter { protected SFBaseSession session; protected int idx; protected Map targetTypes; + private TimeZone timeZoneToUse; StructVectorConverter( RootAllocator allocator, ValueVector vector, DataConversionContext context, SFBaseSession session, + TimeZone timeZoneToUse, int idx, Map targetTypes) { this.allocator = allocator; this.vector = vector; this.context = context; this.session = session; + this.timeZoneToUse = timeZoneToUse; this.idx = idx; this.targetTypes = targetTypes; } public FieldVector convert() throws SFException, SnowflakeSQLException { - StructVector structVector = (StructVector) vector; - List childVectors = structVector.getChildrenFromFields(); - List convertedVectors = new ArrayList<>(); - for (FieldVector childVector : childVectors) { - Object targetType = null; - if (targetTypes != null) { - targetType = targetTypes.get(childVector.getName()); + try { + StructVector structVector = (StructVector) vector; + List childVectors = structVector.getChildrenFromFields(); + List convertedVectors = new ArrayList<>(); + for (FieldVector childVector : childVectors) { + Object targetType = null; + if (targetTypes != null) { + targetType = targetTypes.get(childVector.getName()); + } + convertedVectors.add( + ArrowFullVectorConverterUtil.convert( + allocator, childVector, context, session, timeZoneToUse, idx, targetType)); } - convertedVectors.add( - ArrowFullVectorConverterUtil.convert( - allocator, childVector, context, session, idx, targetType)); - } - List convertedFields = - convertedVectors.stream().map(ValueVector::getField).collect(Collectors.toList()); - StructVector converted = StructVector.empty(vector.getName(), allocator); - converted.allocateNew(); - converted.initializeChildrenFromFields(convertedFields); - for (FieldVector convertedVector : convertedVectors) { - TransferPair transferPair = - convertedVector.makeTransferPair(converted.getChild(convertedVector.getName())); - transferPair.transfer(); - } - ArrowBuf validityBuffer = structVector.getValidityBuffer(); - converted.getValidityBuffer().setBytes(0L, validityBuffer, 0L, validityBuffer.capacity()); - converted.setValueCount(vector.getValueCount()); + List convertedFields = + convertedVectors.stream().map(ValueVector::getField).collect(Collectors.toList()); + StructVector converted = StructVector.empty(vector.getName(), allocator); + converted.allocateNew(); + converted.initializeChildrenFromFields(convertedFields); + for (FieldVector convertedVector : convertedVectors) { + TransferPair transferPair = + convertedVector.makeTransferPair(converted.getChild(convertedVector.getName())); + transferPair.transfer(); + } + ArrowBuf validityBuffer = structVector.getValidityBuffer(); + converted.getValidityBuffer().setBytes(0L, validityBuffer, 0L, validityBuffer.capacity()); + converted.setValueCount(vector.getValueCount()); - vector.close(); - return converted; + return converted; + } finally { + vector.close(); + } } } diff --git a/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/TimeVectorConverter.java b/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/TimeVectorConverter.java index baba5931a..32d19f805 100644 --- a/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/TimeVectorConverter.java +++ b/src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/TimeVectorConverter.java @@ -29,17 +29,20 @@ public TimeVectorConverter(RootAllocator allocator, ValueVector vector) { @Override public FieldVector convert() throws SFException, SnowflakeSQLException { - int size = vector.getValueCount(); - T converted = initVector(); - converted.allocateNew(size); - BaseIntVector srcVector = (BaseIntVector) vector; - int scale = Integer.parseInt(vector.getField().getMetadata().get("scale")); - long scalingFactor = ArrowResultUtil.powerOfTen(targetScale() - scale); - for (int i = 0; i < size; i++) { - convertValue(converted, i, srcVector.getValueAsLong(i) * scalingFactor); + try { + int size = vector.getValueCount(); + T converted = initVector(); + converted.allocateNew(size); + BaseIntVector srcVector = (BaseIntVector) vector; + int scale = Integer.parseInt(vector.getField().getMetadata().get("scale")); + long scalingFactor = ArrowResultUtil.powerOfTen(targetScale() - scale); + for (int i = 0; i < size; i++) { + convertValue(converted, i, srcVector.getValueAsLong(i) * scalingFactor); + } + converted.setValueCount(size); + return converted; + } finally { + vector.close(); } - converted.setValueCount(size); - vector.close(); - return converted; } } diff --git a/src/main/java/net/snowflake/client/jdbc/ArrowResultChunk.java b/src/main/java/net/snowflake/client/jdbc/ArrowResultChunk.java index 1d66cb38e..57dcb38ae 100644 --- a/src/main/java/net/snowflake/client/jdbc/ArrowResultChunk.java +++ b/src/main/java/net/snowflake/client/jdbc/ArrowResultChunk.java @@ -546,7 +546,8 @@ public List fetch() throws SnowflakeSQLException { for (int i = 0; i < record.size(); i++) { ValueVector vector = record.get(i); convertedVectors.add( - ArrowFullVectorConverterUtil.convert(rootAllocator, vector, context, session, timeZoneToUse, i, null)); + ArrowFullVectorConverterUtil.convert( + rootAllocator, vector, context, session, timeZoneToUse, i, null)); } result.add(new VectorSchemaRoot(convertedVectors)); } diff --git a/src/test/java/net/snowflake/client/jdbc/ArrowBatchesIT.java b/src/test/java/net/snowflake/client/jdbc/ArrowBatchesIT.java index 87a73ceee..12bcc19e0 100644 --- a/src/test/java/net/snowflake/client/jdbc/ArrowBatchesIT.java +++ b/src/test/java/net/snowflake/client/jdbc/ArrowBatchesIT.java @@ -29,8 +29,8 @@ import org.apache.arrow.vector.TimeNanoVector; import org.apache.arrow.vector.TimeSecVector; import org.apache.arrow.vector.TinyIntVector; -import org.apache.arrow.vector.VarCharVector; import org.apache.arrow.vector.VarBinaryVector; +import org.apache.arrow.vector.VarCharVector; import org.apache.arrow.vector.VectorSchemaRoot; import org.apache.arrow.vector.complex.FixedSizeListVector; import org.apache.arrow.vector.complex.ListVector; @@ -75,12 +75,14 @@ private static void assertNoMemoryLeaks(ResultSet rs) throws SQLException { public void testMultipleBatches() throws Exception { int totalRows = 0; ArrayList allRoots = new ArrayList<>(); - // Result set is not in the try-with-resources statement, as we want to check access to memory after its closure + // Result set is not in the try-with-resources statement, as we want to check access to memory + // after its closure // and then check the memory allocation. ResultSet rs; try (Statement statement = connection.createStatement()) { - rs = statement.executeQuery( - "select seq1(), seq2(), seq4(), seq8() from TABLE (generator(rowcount => 300000))"); + rs = + statement.executeQuery( + "select seq1(), seq2(), seq4(), seq8() from TABLE (generator(rowcount => 300000))"); ArrowBatches batches = rs.unwrap(SnowflakeResultSet.class).getArrowBatches(); assertEquals(batches.getRowCount(), 300000); while (batches.hasNext()) { @@ -112,7 +114,7 @@ public void testTinyIntBatch() throws Exception { List values = new ArrayList<>(); try (Statement statement = connection.createStatement(); - ResultSet rs = statement.executeQuery("select 1 union select 2 union select 3;")) { + ResultSet rs = statement.executeQuery("select 1 union select 2 union select 3;")) { ArrowBatches batches = rs.unwrap(SnowflakeResultSet.class).getArrowBatches(); while (batches.hasNext()) { @@ -143,8 +145,8 @@ public void testTinyIntBatch() throws Exception { public void testSmallIntBatch() throws Exception { int totalRows = 0; List values = new ArrayList<>(); - try(Statement statement = connection.createStatement(); - ResultSet rs = statement.executeQuery("select 129 union select 130 union select 131;")) { + try (Statement statement = connection.createStatement(); + ResultSet rs = statement.executeQuery("select 129 union select 130 union select 131;")) { ArrowBatches batches = rs.unwrap(SnowflakeResultSet.class).getArrowBatches(); while (batches.hasNext()) { @@ -177,7 +179,8 @@ public void testIntBatch() throws Exception { List values = new ArrayList<>(); try (Statement statement = connection.createStatement(); - ResultSet rs = statement.executeQuery("select 100000 union select 100001 union select 100002;")) { + ResultSet rs = + statement.executeQuery("select 100000 union select 100001 union select 100002;")) { ArrowBatches batches = rs.unwrap(SnowflakeResultSet.class).getArrowBatches(); while (batches.hasNext()) { @@ -210,9 +213,9 @@ public void testBigIntBatch() throws Exception { List values = new ArrayList<>(); try (Statement statement = connection.createStatement(); - ResultSet rs = - statement.executeQuery( - "select 10000000000 union select 10000000001 union select 10000000002;")) { + ResultSet rs = + statement.executeQuery( + "select 10000000000 union select 10000000001 union select 10000000002;")) { ArrowBatches batches = rs.unwrap(SnowflakeResultSet.class).getArrowBatches(); while (batches.hasNext()) { @@ -245,7 +248,7 @@ public void testDecimalBatch() throws Exception { List values = new ArrayList<>(); try (Statement statement = connection.createStatement(); - ResultSet rs = statement.executeQuery("select 1.1 union select 1.2 union select 1.3;")) { + ResultSet rs = statement.executeQuery("select 1.1 union select 1.2 union select 1.3;")) { ArrowBatches batches = rs.unwrap(SnowflakeResultSet.class).getArrowBatches(); while (batches.hasNext()) { @@ -279,9 +282,9 @@ public void testBitBatch() throws Exception { try (Statement statement = connection.createStatement(); ResultSet rs = - statement.executeQuery( - "select true union all select false union all select true union all select false" - + " union all select true union all select false union all select true")) { + statement.executeQuery( + "select true union all select false union all select true union all select false" + + " union all select true union all select false union all select true")) { ArrowBatches batches = rs.unwrap(SnowflakeResultSet.class).getArrowBatches(); while (batches.hasNext()) { @@ -312,9 +315,10 @@ public void testBinaryBatch() throws Exception { int totalRows = 0; List> values = new ArrayList<>(); - try(Statement statement = connection.createStatement(); + try (Statement statement = connection.createStatement(); ResultSet rs = - statement.executeQuery("select TO_BINARY('546AB0') union select TO_BINARY('018E3271')")) { + statement.executeQuery( + "select TO_BINARY('546AB0') union select TO_BINARY('018E3271')")) { ArrowBatches batches = rs.unwrap(SnowflakeResultSet.class).getArrowBatches(); while (batches.hasNext()) { @@ -327,13 +331,13 @@ public void testBinaryBatch() throws Exception { for (int i = 0; i < root.getRowCount(); i++) { byte[] bytes = vector.getObject(i); ArrayList byteArrayList = - new ArrayList() { - { - for (byte aByte : bytes) { - add(aByte); - } - } - }; + new ArrayList() { + { + for (byte aByte : bytes) { + add(aByte); + } + } + }; values.add(byteArrayList); } root.close(); @@ -376,7 +380,7 @@ public void testDateBatch() throws Exception, SFException { try (Statement statement = connection.createStatement(); ResultSet rs = - statement.executeQuery("select '1119-02-01'::DATE union select '2021-09-11'::DATE")) { + statement.executeQuery("select '1119-02-01'::DATE union select '2021-09-11'::DATE")) { ArrowBatches batches = rs.unwrap(SnowflakeResultSet.class).getArrowBatches(); while (batches.hasNext()) { @@ -414,7 +418,7 @@ public void testTimeSecBatch() throws Exception, SFException { try (Statement statement = connection.createStatement(); ResultSet rs = - statement.executeQuery("select '11:32:54'::TIME(0) union select '8:11:25'::TIME(0)")) { + statement.executeQuery("select '11:32:54'::TIME(0) union select '8:11:25'::TIME(0)")) { ArrowBatches batches = rs.unwrap(SnowflakeResultSet.class).getArrowBatches(); while (batches.hasNext()) { @@ -451,8 +455,9 @@ public void testTimeMilliBatch() throws Exception, SFException { List values = new ArrayList<>(); try (Statement statement = connection.createStatement(); - ResultSet rs = - statement.executeQuery("select '11:32:54.13'::TIME(2) union select '8:11:25.91'::TIME(2)")) { + ResultSet rs = + statement.executeQuery( + "select '11:32:54.13'::TIME(2) union select '8:11:25.91'::TIME(2)")) { ArrowBatches batches = rs.unwrap(SnowflakeResultSet.class).getArrowBatches(); while (batches.hasNext()) { @@ -489,8 +494,9 @@ public void testTimeMicroBatch() throws Exception, SFException { List values = new ArrayList<>(); try (Statement statement = connection.createStatement(); - ResultSet rs = - statement.executeQuery("select '11:32:54.139901'::TIME(6) union select '8:11:25.911765'::TIME(6)")) { + ResultSet rs = + statement.executeQuery( + "select '11:32:54.139901'::TIME(6) union select '8:11:25.911765'::TIME(6)")) { ArrowBatches batches = rs.unwrap(SnowflakeResultSet.class).getArrowBatches(); while (batches.hasNext()) { @@ -527,8 +533,9 @@ public void testTimeNanoBatch() throws Exception, SFException { List values = new ArrayList<>(); try (Statement statement = connection.createStatement(); - ResultSet rs = - statement.executeQuery("select '11:32:54.1399013'::TIME(7) union select '8:11:25.9117654'::TIME(7)")) { + ResultSet rs = + statement.executeQuery( + "select '11:32:54.1399013'::TIME(7) union select '8:11:25.9117654'::TIME(7)")) { ArrowBatches batches = rs.unwrap(SnowflakeResultSet.class).getArrowBatches(); while (batches.hasNext()) { @@ -565,9 +572,9 @@ public void testVarCharBatch() throws Exception { List values = new ArrayList<>(); try (Statement statement = connection.createStatement(); - ResultSet rs = - statement.executeQuery( - "select 'Gallia est ' union select 'omnis divisa ' union select 'in partes tres';")) { + ResultSet rs = + statement.executeQuery( + "select 'Gallia est ' union select 'omnis divisa ' union select 'in partes tres';")) { ArrowBatches batches = rs.unwrap(SnowflakeResultSet.class).getArrowBatches(); while (batches.hasNext()) { @@ -625,10 +632,10 @@ public void testStructBatch() throws Exception { List> values = new ArrayList<>(); try (Statement statement = connection.createStatement(); - ResultSet rs = - statement.executeQuery( - "select {'a': 3.1, 'b': 3.2}::object(a decimal(18, 3), b decimal(18, 3))" - + " union select {'a': 2.2, 'b': 2.3}::object(a decimal(18, 3), b decimal(18, 3))")) { + ResultSet rs = + statement.executeQuery( + "select {'a': 3.1, 'b': 3.2}::object(a decimal(18, 3), b decimal(18, 3))" + + " union select {'a': 2.2, 'b': 2.3}::object(a decimal(18, 3), b decimal(18, 3))")) { ArrowBatches batches = rs.unwrap(SnowflakeResultSet.class).getArrowBatches(); while (batches.hasNext()) { @@ -668,9 +675,9 @@ public void testListBatch() throws Exception { List> values = new ArrayList<>(); try (Statement statement = connection.createStatement(); - ResultSet rs = - statement.executeQuery( - "select array_construct(1.2, 2.3)::array(decimal(18, 3)) union all select array_construct(2.1, 1.0)::array(decimal(18, 3))")) { + ResultSet rs = + statement.executeQuery( + "select array_construct(1.2, 2.3)::array(decimal(18, 3)) union all select array_construct(2.1, 1.0)::array(decimal(18, 3))")) { ArrowBatches batches = rs.unwrap(SnowflakeResultSet.class).getArrowBatches(); while (batches.hasNext()) { @@ -719,11 +726,11 @@ public void testMapBatch() throws Exception { int totalRows = 0; List> values = new ArrayList<>(); - try(Statement statement = connection.createStatement(); - ResultSet rs = - statement.executeQuery( - "select {'a': 3.1, 'b': 4.3}::map(varchar, decimal(18,3)) union" - + " select {'c': 2.2, 'd': 1.5}::map(varchar, decimal(18,3))")) { + try (Statement statement = connection.createStatement(); + ResultSet rs = + statement.executeQuery( + "select {'a': 3.1, 'b': 4.3}::map(varchar, decimal(18,3)) union" + + " select {'c': 2.2, 'd': 1.5}::map(varchar, decimal(18,3))")) { ArrowBatches batches = rs.unwrap(SnowflakeResultSet.class).getArrowBatches(); while (batches.hasNext()) { @@ -734,9 +741,9 @@ public void testMapBatch() throws Exception { assertTrue(root.getVector(0) instanceof MapVector); MapVector vector = (MapVector) root.getVector(0); VarCharVector keyVector = - (VarCharVector) vector.getChildrenFromFields().get(0).getChildrenFromFields().get(0); + (VarCharVector) vector.getChildrenFromFields().get(0).getChildrenFromFields().get(0); DecimalVector valueVector = - (DecimalVector) vector.getChildrenFromFields().get(0).getChildrenFromFields().get(1); + (DecimalVector) vector.getChildrenFromFields().get(0).getChildrenFromFields().get(1); for (int i = 0; i < root.getRowCount(); i++) { int startIndex = vector.getElementStartIndex(i); int endIndex = vector.getElementEndIndex(i); @@ -779,9 +786,9 @@ public void testFixedSizeListBatch() throws Exception { List> values = new ArrayList<>(); try (Statement statement = connection.createStatement(); - ResultSet rs = - statement.executeQuery( - "select [1, 2]::vector(int, 2) union all select [3, 4]::vector(int, 2)")) { + ResultSet rs = + statement.executeQuery( + "select [1, 2]::vector(int, 2) union all select [3, 4]::vector(int, 2)")) { ArrowBatches batches = rs.unwrap(SnowflakeResultSet.class).getArrowBatches(); while (batches.hasNext()) {