wecharyu commented on code in PR #13018:
URL: https://github.com/apache/gluten/pull/13018#discussion_r4667120397
##########
gluten-arrow/src/main/scala/org/apache/gluten/utils/ArrowAbiUtil.scala:
##########
@@ -53,8 +55,88 @@ object ArrowAbiUtil {
allocator: BufferAllocator,
cSchema: ArrowSchema,
cArray: ArrowArray): ColumnarBatch = {
- val vsr = importToVectorSchemaRoot(allocator, cSchema, cArray)
- toSparkColumnarBatch(vsr)
+ val provider = new CDataDictionaryProvider
+ try {
+ val imported = Data.importVectorSchemaRoot(allocator, cArray, cSchema,
provider)
+ val root = if (provider.getDictionaryIds.isEmpty) {
+ imported
+ } else {
+ try {
+ decodeDictionaries(imported, allocator, provider)
+ } finally {
+ imported.close()
+ }
+ }
+ try {
+ toSparkColumnarBatch(root)
+ } catch {
+ case t: Throwable =>
+ root.close()
+ throw t
+ }
+ } finally {
+ provider.close()
+ }
+ }
+
+ // Spark's Arrow column vectors read values directly, so expand C Data
dictionary indices
+ // while the imported dictionary buffers are still open.
+ private def decodeDictionaries(
+ root: VectorSchemaRoot,
+ allocator: BufferAllocator,
+ provider: DictionaryProvider): VectorSchemaRoot = {
+ def dictionary(field: Field): FieldVector = {
+ provider.lookup(field.getDictionary.getId).getVector
Review Comment:
`Dictionary#getVector()` returns `FieldVector` in all four Arrow versions
used by this PR (15.0.0, 18.1.0, 18.3.0, and 19.0.0).
##########
cpp/velox/memory/VeloxColumnarBatch.cc:
##########
@@ -63,17 +63,17 @@ void VeloxColumnarBatch::ensureFlattened() {
flattened_ = true;
}
-std::shared_ptr<ArrowSchema> VeloxColumnarBatch::exportArrowSchema() {
+std::shared_ptr<ArrowSchema> VeloxColumnarBatch::exportArrowSchema(bool
exportToLargeVarTypes) {
auto out = std::make_shared<ArrowSchema>();
ensureFlattened();
- velox::exportToArrow(rowVector_, *out, ArrowUtils::getBridgeOptions());
+ velox::exportToArrow(rowVector_, *out,
ArrowUtils::getBridgeOptions(exportToLargeVarTypes));
Review Comment:
Added test `ColumnarBatchTest#testLoadVeloxBatchWithLargeVarTypes`.
##########
gluten-arrow/src/main/scala/org/apache/spark/sql/utils/SparkArrowUtil.scala:
##########
@@ -31,16 +31,21 @@ import scala.collection.JavaConverters._
object SparkArrowUtil {
/** Maps data type from Spark to Arrow. NOTE: timeZoneId required for
TimestampTypes */
- def toArrowType(dt: DataType, timeZoneId: String): ArrowType = dt match {
+ private[utils] def toArrowType(
+ dt: DataType,
+ timeZoneId: String,
+ largeVarTypes: Boolean = false): ArrowType = dt match {
case BooleanType => ArrowType.Bool.INSTANCE
case ByteType => new ArrowType.Int(8, true)
case ShortType => new ArrowType.Int(8 * 2, true)
case IntegerType => new ArrowType.Int(8 * 4, true)
case LongType => new ArrowType.Int(8 * 8, true)
case FloatType => new
ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)
case DoubleType => new
ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)
- case StringType => ArrowType.Utf8.INSTANCE
- case BinaryType => ArrowType.Binary.INSTANCE
+ case StringType if !largeVarTypes => ArrowType.Utf8.INSTANCE
+ case BinaryType if !largeVarTypes => ArrowType.Binary.INSTANCE
+ case StringType if largeVarTypes => ArrowType.LargeUtf8.INSTANCE
+ case BinaryType if largeVarTypes => ArrowType.LargeBinary.INSTANCE
Review Comment:
The `ArrowColumnVector` missing these accessors is Gluten’s old
implementation, which has no callers after
https://github.com/apache/gluten/pull/13280.
There are some no used Arrow files (`ArrowColumnVector.java`,
`ArrowColumnarMap.java` and `ArrowColumnarArray.java`) could be removed, we can
do it in a seprate PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]