Copilot commented on code in PR #13018:
URL: https://github.com/apache/gluten/pull/13018#discussion_r4664960653
##########
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:
These mappings make `VectorSchemaRoot.create` and the native importer
produce `LargeVarCharVector`/`LargeVarBinaryVector` when the flag is enabled,
but `ArrowColumnVector.initAccessor` still handles only `VarCharVector` and
`VarBinaryVector`. The new vectors therefore fail while being wrapped (or have
no usable accessor), so large string/binary batches cannot be read; add
large-vector accessors in `ArrowColumnVector` (including nested children)
before enabling these mappings.
##########
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` is declared as `ValueVector`, not `FieldVector`, so
this method's declared return type makes the new Scala code fail to compile
against Arrow's API. Cast the looked-up vector to `FieldVector` (the dictionary
vectors imported here are field vectors), or keep the helper typed as
`ValueVector` and cast only where field-specific methods are required.
##########
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:
The new UTs do not exercise this native export path: they construct Java
Arrow vectors directly and call `Data.exportVectorSchemaRoot`, so they cannot
detect whether `VarTypeLayout::kLarge` makes Velox emit matching large-offset
schemas and buffers through JNI. Add a Velox/native test that exports string
and binary columns with both flag values and imports them back, since this is
the production behavior introduced here.
--
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]