viirya commented on code in PR #56334:
URL: https://github.com/apache/spark/pull/56334#discussion_r3392593199


##########
sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/ArrowCachedBatchSerializerSuite.scala:
##########
@@ -0,0 +1,2038 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.columnar
+
+import java.sql.{Date, Timestamp}
+import java.time.{Duration, LocalDateTime, LocalTime, Period}
+
+import org.apache.arrow.vector.{
+  BigIntVector, BitVector, DateDayVector, DecimalVector,
+  Float4Vector, Float8Vector, IntVector, LargeVarCharVector, SmallIntVector,
+  TimeNanoVector, TimeStampMicroTZVector, TimeStampMicroVector, TinyIntVector,
+  VarBinaryVector, VarCharVector, VectorSchemaRoot}
+
+import org.apache.spark.SparkConf
+import org.apache.spark.sql.{QueryTest, Row}
+import org.apache.spark.sql.catalyst.expressions.AttributeReference
+import org.apache.spark.sql.internal.{SQLConf, StaticSQLConf}
+import org.apache.spark.sql.test.{ExamplePoint, ExamplePointUDT, 
SharedSparkSession}
+import org.apache.spark.sql.types._
+import org.apache.spark.sql.util.ArrowUtils
+import org.apache.spark.sql.vectorized.{ArrowColumnVector, ColumnarBatch, 
ColumnVector}
+import org.apache.spark.storage.StorageLevel
+import org.apache.spark.unsafe.types.CalendarInterval
+
+/** UDT whose sqlType is Arrow-supported (ArrayType(DoubleType)). */
+private class SupportedUDT extends UserDefinedType[Array[Double]] {
+  override def sqlType: DataType = ArrayType(DoubleType, containsNull = false)
+  override def serialize(obj: Array[Double]): Any = obj
+  override def deserialize(datum: Any): Array[Double] = 
datum.asInstanceOf[Array[Double]]
+  override def userClass: Class[Array[Double]] = classOf[Array[Double]]
+}
+
+/** UDT whose sqlType is ObjectType - not supported by Arrow. */
+private class UnsupportedUDT extends UserDefinedType[AnyRef] {
+  override def sqlType: DataType = ObjectType(classOf[AnyRef])
+  override def serialize(obj: AnyRef): Any = obj
+  override def deserialize(datum: Any): AnyRef = datum.asInstanceOf[AnyRef]
+  override def userClass: Class[AnyRef] = classOf[AnyRef]
+}
+
+class ArrowCachedBatchSerializerSuite extends QueryTest with 
SharedSparkSession {

Review Comment:
   Good question -- there was no test, so I added one (`duplicated column names 
roundtrip through the cache`). It caches a DataFrame with three columns all 
named `a`, verifies both the row-based and vectorized read paths, and prunes a 
single one of the duplicated columns through the cache scan.
   
   Duplicate names work without special handling here because nothing in the 
cache path is keyed by field name: vectors are accessed positionally 
(`getFieldVectors` / `getVector(index)`) and column pruning maps selected 
attributes to cache columns by `exprId`. Arrow schemas themselves permit 
duplicate field names. The renaming you remember from the Python<->JVM Arrow 
exchange is needed because pandas indexes columns by name on the Python side; 
cached batches never cross into Python, so that concern does not apply.



-- 
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]

Reply via email to