-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Arrow batches all simple types (#1883)
- Loading branch information
1 parent
7d93e03
commit d11a12b
Showing
15 changed files
with
703 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...main/java/net/snowflake/client/core/arrow/fullvectorconverters/BinaryVectorConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package net.snowflake.client.core.arrow.fullvectorconverters; | ||
|
||
import net.snowflake.client.core.DataConversionContext; | ||
import net.snowflake.client.core.SFBaseSession; | ||
import net.snowflake.client.core.SFException; | ||
import net.snowflake.client.core.SnowflakeJdbcInternalApi; | ||
import net.snowflake.client.core.arrow.ArrowVectorConverter; | ||
import org.apache.arrow.memory.RootAllocator; | ||
import org.apache.arrow.vector.ValueVector; | ||
import org.apache.arrow.vector.VarBinaryVector; | ||
|
||
@SnowflakeJdbcInternalApi | ||
public class BinaryVectorConverter extends SimpleArrowFullVectorConverter<VarBinaryVector> { | ||
public BinaryVectorConverter( | ||
RootAllocator allocator, | ||
ValueVector vector, | ||
DataConversionContext context, | ||
SFBaseSession session, | ||
int idx) { | ||
super(allocator, vector, context, session, idx); | ||
} | ||
|
||
@Override | ||
protected boolean matchingType() { | ||
return vector instanceof VarBinaryVector; | ||
} | ||
|
||
@Override | ||
protected VarBinaryVector initVector() { | ||
VarBinaryVector resultVector = new VarBinaryVector(vector.getName(), allocator); | ||
resultVector.allocateNew(vector.getValueCount()); | ||
return resultVector; | ||
} | ||
|
||
@Override | ||
protected void convertValue(ArrowVectorConverter from, VarBinaryVector to, int idx) | ||
throws SFException { | ||
to.set(idx, from.toBytes(idx)); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/BitVectorConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package net.snowflake.client.core.arrow.fullvectorconverters; | ||
|
||
import net.snowflake.client.core.DataConversionContext; | ||
import net.snowflake.client.core.SFBaseSession; | ||
import net.snowflake.client.core.SFException; | ||
import net.snowflake.client.core.SnowflakeJdbcInternalApi; | ||
import net.snowflake.client.core.arrow.ArrowVectorConverter; | ||
import org.apache.arrow.memory.RootAllocator; | ||
import org.apache.arrow.vector.BitVector; | ||
import org.apache.arrow.vector.ValueVector; | ||
|
||
@SnowflakeJdbcInternalApi | ||
public class BitVectorConverter extends SimpleArrowFullVectorConverter<BitVector> { | ||
|
||
public BitVectorConverter( | ||
RootAllocator allocator, | ||
ValueVector vector, | ||
DataConversionContext context, | ||
SFBaseSession session, | ||
int idx) { | ||
super(allocator, vector, context, session, idx); | ||
} | ||
|
||
@Override | ||
protected boolean matchingType() { | ||
return vector instanceof BitVector; | ||
} | ||
|
||
@Override | ||
protected BitVector initVector() { | ||
BitVector resultVector = new BitVector(vector.getName(), allocator); | ||
resultVector.allocateNew(vector.getValueCount()); | ||
return resultVector; | ||
} | ||
|
||
@Override | ||
protected void convertValue(ArrowVectorConverter from, BitVector to, int idx) throws SFException { | ||
to.set(idx, from.toBoolean(idx) ? 1 : 0); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/DateVectorConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package net.snowflake.client.core.arrow.fullvectorconverters; | ||
|
||
import java.util.TimeZone; | ||
import net.snowflake.client.core.DataConversionContext; | ||
import net.snowflake.client.core.SFBaseSession; | ||
import net.snowflake.client.core.SFException; | ||
import net.snowflake.client.core.SnowflakeJdbcInternalApi; | ||
import net.snowflake.client.core.arrow.ArrowVectorConverter; | ||
import org.apache.arrow.memory.RootAllocator; | ||
import org.apache.arrow.vector.DateDayVector; | ||
import org.apache.arrow.vector.ValueVector; | ||
|
||
@SnowflakeJdbcInternalApi | ||
public class DateVectorConverter extends SimpleArrowFullVectorConverter<DateDayVector> { | ||
private TimeZone timeZone; | ||
|
||
public DateVectorConverter( | ||
RootAllocator allocator, | ||
ValueVector vector, | ||
DataConversionContext context, | ||
SFBaseSession session, | ||
int idx, | ||
TimeZone timeZone) { | ||
super(allocator, vector, context, session, idx); | ||
this.timeZone = timeZone; | ||
} | ||
|
||
@Override | ||
protected boolean matchingType() { | ||
return vector instanceof DateDayVector; | ||
} | ||
|
||
@Override | ||
protected DateDayVector initVector() { | ||
DateDayVector resultVector = new DateDayVector(vector.getName(), allocator); | ||
resultVector.allocateNew(vector.getValueCount()); | ||
return resultVector; | ||
} | ||
|
||
@Override | ||
protected void additionalConverterInit(ArrowVectorConverter converter) { | ||
if (timeZone != null) { | ||
converter.setSessionTimeZone(timeZone); | ||
converter.setUseSessionTimezone(true); | ||
} | ||
} | ||
|
||
@Override | ||
protected void convertValue(ArrowVectorConverter from, DateDayVector to, int idx) | ||
throws SFException { | ||
to.set(idx, (int) (from.toDate(idx, null, false).getTime() / (1000 * 3600 * 24))); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/net/snowflake/client/core/arrow/fullvectorconverters/FloatVectorConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package net.snowflake.client.core.arrow.fullvectorconverters; | ||
|
||
import net.snowflake.client.core.DataConversionContext; | ||
import net.snowflake.client.core.SFBaseSession; | ||
import net.snowflake.client.core.SFException; | ||
import net.snowflake.client.core.SnowflakeJdbcInternalApi; | ||
import net.snowflake.client.core.arrow.ArrowVectorConverter; | ||
import org.apache.arrow.memory.RootAllocator; | ||
import org.apache.arrow.vector.Float8Vector; | ||
import org.apache.arrow.vector.ValueVector; | ||
|
||
@SnowflakeJdbcInternalApi | ||
public class FloatVectorConverter extends SimpleArrowFullVectorConverter<Float8Vector> { | ||
|
||
public FloatVectorConverter( | ||
RootAllocator allocator, | ||
ValueVector vector, | ||
DataConversionContext context, | ||
SFBaseSession session, | ||
int idx) { | ||
super(allocator, vector, context, session, idx); | ||
} | ||
|
||
@Override | ||
protected boolean matchingType() { | ||
return vector instanceof Float8Vector; | ||
} | ||
|
||
@Override | ||
protected Float8Vector initVector() { | ||
Float8Vector resultVector = new Float8Vector(vector.getName(), allocator); | ||
resultVector.allocateNew(vector.getValueCount()); | ||
return resultVector; | ||
} | ||
|
||
@Override | ||
protected void convertValue(ArrowVectorConverter from, Float8Vector to, int idx) | ||
throws SFException { | ||
to.set(idx, from.toDouble(idx)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...n/java/net/snowflake/client/core/arrow/fullvectorconverters/TimeMicroVectorConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package net.snowflake.client.core.arrow.fullvectorconverters; | ||
|
||
import net.snowflake.client.core.SnowflakeJdbcInternalApi; | ||
import org.apache.arrow.memory.RootAllocator; | ||
import org.apache.arrow.vector.TimeMicroVector; | ||
import org.apache.arrow.vector.ValueVector; | ||
|
||
@SnowflakeJdbcInternalApi | ||
public class TimeMicroVectorConverter extends TimeVectorConverter<TimeMicroVector> { | ||
|
||
public TimeMicroVectorConverter(RootAllocator allocator, ValueVector vector) { | ||
super(allocator, vector); | ||
} | ||
|
||
@Override | ||
protected TimeMicroVector initVector() { | ||
return new TimeMicroVector(vector.getName(), allocator); | ||
} | ||
|
||
@Override | ||
protected void convertValue(TimeMicroVector dstVector, int idx, long value) { | ||
dstVector.set(idx, value); | ||
} | ||
|
||
@Override | ||
protected int targetScale() { | ||
return 6; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...n/java/net/snowflake/client/core/arrow/fullvectorconverters/TimeMilliVectorConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package net.snowflake.client.core.arrow.fullvectorconverters; | ||
|
||
import net.snowflake.client.core.SnowflakeJdbcInternalApi; | ||
import org.apache.arrow.memory.RootAllocator; | ||
import org.apache.arrow.vector.TimeMilliVector; | ||
import org.apache.arrow.vector.ValueVector; | ||
|
||
@SnowflakeJdbcInternalApi | ||
public class TimeMilliVectorConverter extends TimeVectorConverter<TimeMilliVector> { | ||
public TimeMilliVectorConverter(RootAllocator allocator, ValueVector vector) { | ||
super(allocator, vector); | ||
} | ||
|
||
@Override | ||
protected TimeMilliVector initVector() { | ||
return new TimeMilliVector(vector.getName(), allocator); | ||
} | ||
|
||
@Override | ||
protected void convertValue(TimeMilliVector dstVector, int idx, long value) { | ||
dstVector.set(idx, (int) value); | ||
} | ||
|
||
@Override | ||
protected int targetScale() { | ||
return 3; | ||
} | ||
} |
Oops, something went wrong.