Skip to content

Commit 56edea6

Browse files
committed
expose large var type to all other api calls
1 parent 4f54a2c commit 56edea6

10 files changed

Lines changed: 34 additions & 75 deletions

File tree

backends-velox/src-iceberg/main/scala/org/apache/gluten/connector/write/IcebergDataWriteFactory.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ import org.apache.gluten.runtime.Runtimes
2424
import org.apache.gluten.utils.ArrowAbiUtil
2525

2626
import org.apache.spark.sql.connector.write.DataWriter
27-
import org.apache.spark.sql.internal.SQLConf
2827
import org.apache.spark.sql.types.StructType
29-
import org.apache.spark.sql.utils.SparkArrowUtil
28+
import org.apache.spark.sql.utils.SparkSchemaUtil
3029
import org.apache.spark.sql.vectorized.ColumnarBatch
3130

3231
import org.apache.arrow.c.ArrowSchema
@@ -101,7 +100,7 @@ case class IcebergDataWriteFactory(
101100
partitionSpec: IcebergPartitionSpec,
102101
field: IcebergNestedField,
103102
icebergProperties: util.HashMap[String, String]): (Long, IcebergWriteJniWrapper) = {
104-
val schema = SparkArrowUtil.toArrowSchema(localSchema, SQLConf.get.sessionLocalTimeZone)
103+
val schema = SparkSchemaUtil.toArrowSchema(localSchema)
105104
val arrowAlloc = ArrowBufferAllocators.contextInstance()
106105
val cSchema = ArrowSchema.allocateNew(arrowAlloc)
107106
ArrowAbiUtil.exportSchema(arrowAlloc, schema, cSchema)

backends-velox/src/main/scala/org/apache/gluten/execution/RowToVeloxColumnarExec.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ import org.apache.spark.sql.catalyst.InternalRow
3131
import org.apache.spark.sql.catalyst.expressions.{UnsafeProjection, UnsafeRow}
3232
import org.apache.spark.sql.execution.{BroadcastUtils, SparkPlan}
3333
import org.apache.spark.sql.execution.metric.SQLMetric
34-
import org.apache.spark.sql.internal.SQLConf
3534
import org.apache.spark.sql.types.StructType
36-
import org.apache.spark.sql.utils.SparkArrowUtil
35+
import org.apache.spark.sql.utils.SparkSchemaUtil
3736
import org.apache.spark.sql.vectorized.ColumnarBatch
3837
import org.apache.spark.task.TaskResources
3938
import org.apache.spark.unsafe.Platform
@@ -128,8 +127,7 @@ object RowToVeloxColumnarExec {
128127
return Iterator.empty
129128
}
130129

131-
val arrowSchema =
132-
SparkArrowUtil.toArrowSchema(schema, SQLConf.get.sessionLocalTimeZone)
130+
val arrowSchema = SparkSchemaUtil.toArrowSchema(schema)
133131
val runtime = Runtimes.contextInstance(BackendsApiManager.getBackendName, "RowToColumnar")
134132
val jniWrapper = NativeRowToColumnarJniWrapper.create(runtime)
135133
val arrowAllocator = ArrowBufferAllocators.contextInstance()

backends-velox/src/main/scala/org/apache/spark/sql/execution/ColumnarBuildSideRelation.scala

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ import org.apache.spark.sql.catalyst.InternalRow
3232
import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeSeq, BindReferences, BoundReference, Expression, UnsafeProjection, UnsafeRow}
3333
import org.apache.spark.sql.catalyst.plans.physical.BroadcastMode
3434
import org.apache.spark.sql.execution.joins.{BuildSideRelation, HashedRelationBroadcastMode}
35-
import org.apache.spark.sql.internal.SQLConf
36-
import org.apache.spark.sql.utils.SparkArrowUtil
35+
import org.apache.spark.sql.utils.SparkSchemaUtil
3736
import org.apache.spark.sql.vectorized.ColumnarBatch
3837
import org.apache.spark.task.TaskResources
3938
import org.apache.spark.util.KnownSizeEstimation
@@ -117,9 +116,8 @@ case class ColumnarBuildSideRelation(
117116
val serializeHandle: Long = {
118117
val allocator = ArrowBufferAllocators.contextInstance()
119118
val cSchema = ArrowSchema.allocateNew(allocator)
120-
val arrowSchema = SparkArrowUtil.toArrowSchema(
121-
SparkShimLoader.getSparkShims.structFromAttributes(output),
122-
SQLConf.get.sessionLocalTimeZone)
119+
val arrowSchema = SparkSchemaUtil.toArrowSchema(
120+
SparkShimLoader.getSparkShims.structFromAttributes(output))
123121
ArrowAbiUtil.exportSchema(allocator, arrowSchema, cSchema)
124122
val handle = jniWrapper
125123
.init(cSchema.memoryAddress())
@@ -170,9 +168,8 @@ case class ColumnarBuildSideRelation(
170168
val serializeHandle: Long = {
171169
val allocator = ArrowBufferAllocators.contextInstance()
172170
val cSchema = ArrowSchema.allocateNew(allocator)
173-
val arrowSchema = SparkArrowUtil.toArrowSchema(
174-
SparkShimLoader.getSparkShims.structFromAttributes(output),
175-
SQLConf.get.sessionLocalTimeZone)
171+
val arrowSchema = SparkSchemaUtil.toArrowSchema(
172+
SparkShimLoader.getSparkShims.structFromAttributes(output))
176173
ArrowAbiUtil.exportSchema(allocator, arrowSchema, cSchema)
177174
val handle = jniWrapper
178175
.init(cSchema.memoryAddress())
@@ -260,9 +257,8 @@ case class ColumnarBuildSideRelation(
260257
val serializeHandle = {
261258
val allocator = ArrowBufferAllocators.contextInstance()
262259
val cSchema = ArrowSchema.allocateNew(allocator)
263-
val arrowSchema = SparkArrowUtil.toArrowSchema(
264-
SparkShimLoader.getSparkShims.structFromAttributes(output),
265-
SQLConf.get.sessionLocalTimeZone)
260+
val arrowSchema = SparkSchemaUtil.toArrowSchema(
261+
SparkShimLoader.getSparkShims.structFromAttributes(output))
266262
ArrowAbiUtil.exportSchema(allocator, arrowSchema, cSchema)
267263
val handle = serializerJniWrapper.init(cSchema.memoryAddress())
268264
cSchema.close()

backends-velox/src/main/scala/org/apache/spark/sql/execution/ColumnarCachedBatchSerializer.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import org.apache.spark.sql.columnar.SimpleMetricsCachedBatchSerializer
3939
import org.apache.spark.sql.execution.columnar.DefaultCachedBatchSerializer
4040
import org.apache.spark.sql.internal.SQLConf
4141
import org.apache.spark.sql.types._
42-
import org.apache.spark.sql.utils.SparkArrowUtil
42+
import org.apache.spark.sql.utils.SparkSchemaUtil
4343
import org.apache.spark.sql.vectorized.ColumnarBatch
4444
import org.apache.spark.storage.StorageLevel
4545
import org.apache.spark.unsafe.types.UTF8String
@@ -953,15 +953,14 @@ class ColumnarCachedBatchSerializer extends SimpleMetricsCachedBatchSerializer
953953
}
954954
val shouldSelectAttributes = cacheAttributes != selectedAttributes
955955
val localSchema = toStructType(cacheAttributes)
956-
val timezoneId = SQLConf.get.sessionLocalTimeZone
957956
input.mapPartitions {
958957
it =>
959958
val runtime = Runtimes.contextInstance(
960959
BackendsApiManager.getBackendName,
961960
"ColumnarCachedBatchSerializer#read")
962961
val jniWrapper = ColumnarBatchSerializerJniWrapper
963962
.create(runtime)
964-
val schema = SparkArrowUtil.toArrowSchema(localSchema, timezoneId)
963+
val schema = SparkSchemaUtil.toArrowSchema(localSchema)
965964
val arrowAlloc = ArrowBufferAllocators.contextInstance()
966965
val cSchema = ArrowSchema.allocateNew(arrowAlloc)
967966
ArrowAbiUtil.exportSchema(arrowAlloc, schema, cSchema)

backends-velox/src/main/scala/org/apache/spark/sql/execution/datasources/velox/VeloxFormatWriterInjects.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ import org.apache.gluten.utils.ArrowAbiUtil
2929
import org.apache.spark.sql.SparkSession
3030
import org.apache.spark.sql.catalyst.InternalRow
3131
import org.apache.spark.sql.execution.datasources._
32-
import org.apache.spark.sql.internal.SQLConf
3332
import org.apache.spark.sql.types.StructType
34-
import org.apache.spark.sql.utils.SparkArrowUtil
33+
import org.apache.spark.sql.utils.SparkSchemaUtil
3534
import org.apache.spark.sql.vectorized.ColumnarBatch
3635

3736
import org.apache.arrow.c.ArrowSchema
@@ -56,8 +55,7 @@ trait VeloxFormatWriterInjects extends GlutenFormatWriterInjectsBase {
5655
}
5756
}
5857

59-
val arrowSchema =
60-
SparkArrowUtil.toArrowSchema(dataSchema, SQLConf.get.sessionLocalTimeZone)
58+
val arrowSchema = SparkSchemaUtil.toArrowSchema(dataSchema)
6159
val cSchema = ArrowSchema.allocateNew(ArrowBufferAllocators.contextInstance())
6260
var dsHandle = -1L
6361
val runtime = Runtimes.contextInstance(BackendsApiManager.getBackendName, "VeloxWriter")

backends-velox/src/main/scala/org/apache/spark/sql/execution/unsafe/UnsafeColumnarBuildSideRelation.scala

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeSeq, BindR
3434
import org.apache.spark.sql.catalyst.plans.physical.BroadcastMode
3535
import org.apache.spark.sql.execution.{BroadcastModeUtils, HashExprSafeBroadcastMode, HashSafeBroadcastMode, IdentitySafeBroadcastMode, SafeBroadcastMode}
3636
import org.apache.spark.sql.execution.joins.{BuildSideRelation, HashedRelationBroadcastMode}
37-
import org.apache.spark.sql.internal.SQLConf
38-
import org.apache.spark.sql.utils.SparkArrowUtil
37+
import org.apache.spark.sql.utils.SparkSchemaUtil
3938
import org.apache.spark.sql.vectorized.ColumnarBatch
4039
import org.apache.spark.task.TaskResources
4140
import org.apache.spark.util.{KnownSizeEstimation, Utils}
@@ -139,9 +138,8 @@ class UnsafeColumnarBuildSideRelation(
139138
val serializeHandle: Long = {
140139
val allocator = ArrowBufferAllocators.contextInstance()
141140
val cSchema = ArrowSchema.allocateNew(allocator)
142-
val arrowSchema = SparkArrowUtil.toArrowSchema(
143-
SparkShimLoader.getSparkShims.structFromAttributes(output),
144-
SQLConf.get.sessionLocalTimeZone)
141+
val arrowSchema = SparkSchemaUtil.toArrowSchema(
142+
SparkShimLoader.getSparkShims.structFromAttributes(output))
145143
ArrowAbiUtil.exportSchema(allocator, arrowSchema, cSchema)
146144
val handle = jniWrapper
147145
.init(cSchema.memoryAddress())
@@ -276,9 +274,8 @@ class UnsafeColumnarBuildSideRelation(
276274
val serializerHandle: Long = {
277275
val allocator = ArrowBufferAllocators.contextInstance()
278276
val cSchema = ArrowSchema.allocateNew(allocator)
279-
val arrowSchema = SparkArrowUtil.toArrowSchema(
280-
SparkShimLoader.getSparkShims.structFromAttributes(output),
281-
SQLConf.get.sessionLocalTimeZone)
277+
val arrowSchema = SparkSchemaUtil.toArrowSchema(
278+
SparkShimLoader.getSparkShims.structFromAttributes(output))
282279
ArrowAbiUtil.exportSchema(allocator, arrowSchema, cSchema)
283280
val handle = jniWrapper
284281
.init(cSchema.memoryAddress())
@@ -325,9 +322,8 @@ class UnsafeColumnarBuildSideRelation(
325322
val serializerHandle = {
326323
val allocator = ArrowBufferAllocators.contextInstance()
327324
val cSchema = ArrowSchema.allocateNew(allocator)
328-
val arrowSchema = SparkArrowUtil.toArrowSchema(
329-
SparkShimLoader.getSparkShims.structFromAttributes(output),
330-
SQLConf.get.sessionLocalTimeZone)
325+
val arrowSchema = SparkSchemaUtil.toArrowSchema(
326+
SparkShimLoader.getSparkShims.structFromAttributes(output))
331327
ArrowAbiUtil.exportSchema(allocator, arrowSchema, cSchema)
332328
val handle = serializerJniWrapper.init(cSchema.memoryAddress())
333329
cSchema.close()

gluten-arrow/src/main/java/org/apache/gluten/vectorized/ArrowWritableColumnVector.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,7 @@ public ArrowWritableColumnVector(int capacity, DataType dataType) {
207207
super(capacity, dataType);
208208
vectorCount.getAndIncrement();
209209
refCnt.getAndIncrement();
210-
String timeZoneId = SparkSchemaUtil.getLocalTimezoneID();
211-
boolean useLargeVarTypes = SparkSchemaUtil.enableLargeVarTypes();
212-
List<Field> fields =
213-
Arrays.asList(
214-
SparkArrowUtil.toArrowField("col", dataType, true, timeZoneId, useLargeVarTypes));
210+
List<Field> fields = Arrays.asList(SparkSchemaUtil.toArrowField("col", dataType, true));
215211
Schema arrowSchema = new Schema(fields);
216212
VectorSchemaRoot root =
217213
VectorSchemaRoot.create(arrowSchema, ArrowBufferAllocators.contextInstance());

gluten-arrow/src/main/scala/org/apache/gluten/utils/ArrowUtil.scala

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,17 @@ package org.apache.gluten.utils
1818

1919
import org.apache.gluten.vectorized.ArrowWritableColumnVector
2020

21-
import org.apache.spark.sql.catalyst.expressions.Attribute
22-
import org.apache.spark.sql.types._
2321
import org.apache.spark.sql.utils.{SparkArrowUtil, SparkSchemaUtil}
2422
import org.apache.spark.sql.vectorized.{ColumnarBatch, ColumnVector}
2523

2624
import org.apache.arrow.c.{ArrowSchema, CDataDictionaryProvider, Data}
2725
import org.apache.arrow.memory.BufferAllocator
28-
import org.apache.arrow.vector.types.pojo.{ArrowType, Field, Schema}
26+
import org.apache.arrow.vector.types.pojo.{Field, Schema}
2927

3028
import java.util
3129

32-
import scala.collection.JavaConverters._
33-
3430
object ArrowUtil {
3531

36-
private val defaultTimeZoneId = SparkSchemaUtil.getLocalTimezoneID
37-
38-
private def getResultType(dataType: DataType): ArrowType = {
39-
getResultType(dataType, defaultTimeZoneId)
40-
}
41-
42-
private def getResultType(dataType: DataType, timeZoneId: String): ArrowType = {
43-
dataType match {
44-
case other =>
45-
SparkArrowUtil.toArrowType(dataType, timeZoneId)
46-
}
47-
}
48-
49-
def toArrowSchema(attributes: Seq[Attribute]): Schema = {
50-
val fields = attributes.map(
51-
attr => {
52-
Field
53-
.nullable(s"${attr.name}#${attr.exprId.id}", getResultType(attr.dataType))
54-
})
55-
new Schema(fields.toList.asJava)
56-
}
57-
5832
def toArrowSchema(
5933
cSchema: ArrowSchema,
6034
allocator: BufferAllocator,
@@ -65,8 +39,7 @@ object ArrowUtil {
6539
originFields.forEach {
6640
field =>
6741
val dt = SparkArrowUtil.fromArrowField(field)
68-
fields.add(
69-
SparkArrowUtil.toArrowField(field.getName, dt, true, SparkSchemaUtil.getLocalTimezoneID))
42+
fields.add(SparkSchemaUtil.toArrowField(field.getName, dt, true))
7043
}
7144
new Schema(fields)
7245
}

gluten-arrow/src/main/scala/org/apache/spark/sql/utils/SparkArrowUtil.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import scala.collection.JavaConverters._
3131
object SparkArrowUtil {
3232

3333
/** Maps data type from Spark to Arrow. NOTE: timeZoneId required for TimestampTypes */
34-
def toArrowType(
34+
private[utils] def toArrowType(
3535
dt: DataType,
3636
timeZoneId: String,
3737
largeVarTypes: Boolean = false): ArrowType = dt match {
@@ -100,7 +100,7 @@ object SparkArrowUtil {
100100
}
101101

102102
/** Maps field from Spark to Arrow. NOTE: timeZoneId required for TimestampType */
103-
def toArrowField(
103+
private[utils] def toArrowField(
104104
name: String,
105105
dt: DataType,
106106
nullable: Boolean,
@@ -179,7 +179,7 @@ object SparkArrowUtil {
179179
}
180180

181181
/** Maps schema from Spark to Arrow. NOTE: timeZoneId required for TimestampType in StructType */
182-
def toArrowSchema(
182+
private[utils] def toArrowSchema(
183183
schema: StructType,
184184
timeZoneId: String,
185185
largeVarTypes: Boolean = false): Schema = {

gluten-arrow/src/main/scala/org/apache/spark/sql/utils/SparkSchemaUtil.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@
1717
package org.apache.spark.sql.utils
1818

1919
import org.apache.spark.sql.internal.SQLConf
20-
import org.apache.spark.sql.types.StructType
20+
import org.apache.spark.sql.types.{DataType, StructType}
2121

22-
import org.apache.arrow.vector.types.pojo.Schema
22+
import org.apache.arrow.vector.types.pojo.{Field, Schema}
2323

2424
import java.util.{Objects, TimeZone}
2525

2626
object SparkSchemaUtil {
2727

28+
def toArrowField(name: String, dt: DataType, nullable: Boolean): Field = {
29+
SparkArrowUtil.toArrowField(name, dt, nullable, getLocalTimezoneID, enableLargeVarTypes)
30+
}
31+
2832
def fromArrowSchema(schema: Schema): StructType = {
2933
SparkArrowUtil.fromArrowSchema(schema)
3034
}

0 commit comments

Comments
 (0)