LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125245356


##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/LiteralValueProtoConverter.scala:
##########
@@ -130,4 +135,117 @@ object LiteralValueProtoConverter {
       case o => throw new Exception(s"Unsupported value type: $o")
     }
   }
+
+  private def toArrayData(array: proto.Expression.Literal.Array): Any = {
+    def makeArrayData[T](
+        initFunc: Int => Array[T],
+        converter: proto.Expression.Literal => T): Array[T] = {
+      val elementList = array.getElementList
+      val data = initFunc(elementList.size())
+      var idx = 0
+      val iter = elementList.iterator()
+      while (iter.hasNext) {
+        data(idx) = converter(iter.next())
+        idx += 1
+      }
+      data
+    }
+
+    val elementType = array.getElementType
+    if (elementType.hasShort) {
+      makeArrayData(size => new Array[Short](size), v => v.getShort.toShort)
+    } else if (elementType.hasInteger) {
+      makeArrayData(size => new Array[Int](size), v => v.getInteger)
+    } else if (elementType.hasLong) {
+      makeArrayData(size => new Array[Long](size), v => v.getLong)
+    } else if (elementType.hasDouble) {
+      makeArrayData(size => new Array[Double](size), v => v.getDouble)
+    } else if (elementType.hasByte) {
+      makeArrayData(size => new Array[Byte](size), v => v.getByte.toByte)
+    } else if (elementType.hasFloat) {
+      makeArrayData(size => new Array[Float](size), v => v.getFloat)
+    } else if (elementType.hasBoolean) {
+      makeArrayData(size => new Array[Boolean](size), v => v.getBoolean)
+    } else if (elementType.hasString) {
+      makeArrayData(size => new Array[String](size), v => v.getString)
+    } else if (elementType.hasBinary) {
+      makeArrayData(size => new Array[Array[Byte]](size), v => 
v.getBinary.toByteArray)
+    } else if (elementType.hasDate) {
+      makeArrayData(
+        size => new Array[java.sql.Date](size),
+        v => DateTimeUtils.toJavaDate(v.getDate))
+    } else if (elementType.hasTimestamp) {
+      makeArrayData(
+        size => new Array[java.sql.Timestamp](size),
+        v => DateTimeUtils.toJavaTimestamp(v.getTimestamp))
+    } else if (elementType.hasTimestampNtz) {
+      makeArrayData(
+        size => new Array[java.time.LocalDateTime](size),
+        v => DateTimeUtils.microsToLocalDateTime(v.getTimestampNtz))
+    } else if (elementType.hasDayTimeInterval) {
+      makeArrayData(
+        size => new Array[java.time.Duration](size),
+        v => IntervalUtils.microsToDuration(v.getDayTimeInterval))
+    } else if (elementType.hasYearMonthInterval) {
+      makeArrayData(
+        size => new Array[java.time.Period](size),
+        v => IntervalUtils.monthsToPeriod(v.getYearMonthInterval))
+    } else if (elementType.hasDecimal) {
+      makeArrayData(size => new Array[Decimal](size), v => 
Decimal(v.getDecimal.getValue))
+    } else if (elementType.hasCalendarInterval) {
+      makeArrayData(
+        size => new Array[CalendarInterval](size),
+        v => {
+          val interval = v.getCalendarInterval
+          new CalendarInterval(interval.getMonths, interval.getDays, 
interval.getMicroseconds)
+        })
+    } else if (elementType.hasArray) {
+      makeArrayData(size => new Array[Any](size), v => toArrayData(v.getArray))
+    } else {
+      throw InvalidPlanInput(s"Unsupported Literal Type: $elementType)")
+    }
+  }
+
+  private def toArrayType(elementType: proto.DataType): ArrayType = {

Review Comment:
   ok



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to