You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "LuciferYang (via GitHub)" <gi...@apache.org> on 2023/02/28 13:09:04 UTC
[GitHub] [spark] LuciferYang opened a new pull request, #40218: [SPARK-42579][WIP]
LuciferYang opened a new pull request, #40218:
URL: https://github.com/apache/spark/pull/40218
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'core/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125243219
##########
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:
`ArrayType(DataTypeProtoConverter.toCatalystType)`
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on PR #40218:
URL: https://github.com/apache/spark/pull/40218#issuecomment-1457206111
Merging.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125600149
##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/LiteralValueProtoConverter.scala:
##########
@@ -130,4 +138,61 @@ object LiteralValueProtoConverter {
case o => throw new Exception(s"Unsupported value type: $o")
}
}
+
+ private def toArrayData(array: proto.Expression.Literal.Array): Any = {
+ def makeArrayData[T](converter: proto.Expression.Literal => T)(implicit
+ tag: ClassTag[T]): Array[T] = {
Review Comment:
like this way?
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on PR #40218:
URL: https://github.com/apache/spark/pull/40218#issuecomment-1451322878
cc @hvanhovell @HyukjinKwon
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][WIP]
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1120036910
##########
connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/PlanGenerationTestSuite.scala:
##########
@@ -2004,6 +2004,16 @@ class PlanGenerationTestSuite
fn.lit(new CalendarInterval(2, 20, 100L)))
}
+ test("function lit array") {
+ simple.select(
+ fn.lit(Array(Array(1), Array(2), Array(3))),
+ fn.lit(Array(Array(Array(1)), Array(Array(2)), Array(Array(3)))),
+ fn.lit(Array(1.toShort, 2.toShort, 3.toShort)),
+ fn.lit(Array(1, 2, 3)),
+ fn.lit(Array(1.toDouble, 2.toDouble, 3.toDouble))
Review Comment:
need add more test, a little busy today. will continue tomorrow
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125244166
##########
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 = {
Review Comment:
Can you use a scala ArrayBuilder here? You will need a classTag for that tough.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125231142
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,297 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JBoolean, Byte => JByte, Character => JChar, Double => JDouble, Float => JFloat, Integer => JInteger, Long => JLong, Short => JShort}
+import java.math.{BigDecimal => JBigDecimal}
+import java.sql.{Date, Timestamp}
+import java.time._
+
+import com.google.protobuf.ByteString
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils}
+import org.apache.spark.sql.connect.client.unsupported
+import org.apache.spark.sql.types.{DayTimeIntervalType, Decimal, DecimalType, YearMonthIntervalType}
+import org.apache.spark.unsafe.types.CalendarInterval
+
+object LiteralProtoConverter {
+
+ private lazy val nullType =
+ proto.DataType.newBuilder().setNull(proto.DataType.NULL.getDefaultInstance).build()
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal.Builder`.
+ *
+ * @return
+ * proto.Expression.Literal.Builder
+ */
+ @scala.annotation.tailrec
+ def toLiteralProtoBuilder(literal: Any): proto.Expression.Literal.Builder = {
+ val builder = proto.Expression.Literal.newBuilder()
+
+ def decimalBuilder(precision: Int, scale: Int, value: String) = {
+ builder.getDecimalBuilder.setPrecision(precision).setScale(scale).setValue(value)
+ }
+
+ def calendarIntervalBuilder(months: Int, days: Int, microseconds: Long) = {
+ builder.getCalendarIntervalBuilder
+ .setMonths(months)
+ .setDays(days)
+ .setMicroseconds(microseconds)
+ }
+
+ def arrayBuilder(array: Array[_]) = {
+ val ab = builder.getArrayBuilder
+ .setElementType(componentTypeToProto(array.getClass.getComponentType))
+ array.foreach(x => ab.addElement(toLiteralProto(x)))
+ ab
+ }
+
+ literal match {
+ case v: Boolean => builder.setBoolean(v)
+ case v: Byte => builder.setByte(v)
+ case v: Short => builder.setShort(v)
+ case v: Int => builder.setInteger(v)
+ case v: Long => builder.setLong(v)
+ case v: Float => builder.setFloat(v)
+ case v: Double => builder.setDouble(v)
+ case v: BigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: JBigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: String => builder.setString(v)
+ case v: Char => builder.setString(v.toString)
+ case v: Array[Char] => builder.setString(String.valueOf(v))
+ case v: Array[Byte] => builder.setBinary(ByteString.copyFrom(v))
+ case v: collection.mutable.WrappedArray[_] => toLiteralProtoBuilder(v.array)
+ case v: LocalDate => builder.setDate(v.toEpochDay.toInt)
+ case v: Decimal =>
+ builder.setDecimal(decimalBuilder(Math.max(v.precision, v.scale), v.scale, v.toString))
+ case v: Instant => builder.setTimestamp(DateTimeUtils.instantToMicros(v))
+ case v: Timestamp => builder.setTimestamp(DateTimeUtils.fromJavaTimestamp(v))
+ case v: LocalDateTime => builder.setTimestampNtz(DateTimeUtils.localDateTimeToMicros(v))
+ case v: Date => builder.setDate(DateTimeUtils.fromJavaDate(v))
+ case v: Duration => builder.setDayTimeInterval(IntervalUtils.durationToMicros(v))
+ case v: Period => builder.setYearMonthInterval(IntervalUtils.periodToMonths(v))
+ case v: Array[_] => builder.setArray(arrayBuilder(v))
+ case v: CalendarInterval =>
+ builder.setCalendarInterval(calendarIntervalBuilder(v.months, v.days, v.microseconds))
+ case null => builder.setNull(nullType)
+ case _ => unsupported(s"literal $literal not supported (yet).")
+ }
+ }
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal`.
+ *
+ * @return
+ * proto.Expression.Literal
+ */
+ def toLiteralProto(literal: Any): proto.Expression.Literal =
+ toLiteralProtoBuilder(literal).build()
+
+ private def componentTypeToProto(clz: Class[_]): proto.DataType = clz match {
Review Comment:
Can we simplify this a bit. Please build the conversion from `Class[_] -> org.apach.spark.sql.types.DataType`. Then call the DataTypeProtoConverter to convert it to its proto equivalent.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125852404
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,297 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JBoolean, Byte => JByte, Character => JChar, Double => JDouble, Float => JFloat, Integer => JInteger, Long => JLong, Short => JShort}
+import java.math.{BigDecimal => JBigDecimal}
+import java.sql.{Date, Timestamp}
+import java.time._
+
+import com.google.protobuf.ByteString
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils}
+import org.apache.spark.sql.connect.client.unsupported
+import org.apache.spark.sql.types.{DayTimeIntervalType, Decimal, DecimalType, YearMonthIntervalType}
+import org.apache.spark.unsafe.types.CalendarInterval
+
+object LiteralProtoConverter {
+
+ private lazy val nullType =
+ proto.DataType.newBuilder().setNull(proto.DataType.NULL.getDefaultInstance).build()
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal.Builder`.
+ *
+ * @return
+ * proto.Expression.Literal.Builder
+ */
+ @scala.annotation.tailrec
+ def toLiteralProtoBuilder(literal: Any): proto.Expression.Literal.Builder = {
+ val builder = proto.Expression.Literal.newBuilder()
+
+ def decimalBuilder(precision: Int, scale: Int, value: String) = {
+ builder.getDecimalBuilder.setPrecision(precision).setScale(scale).setValue(value)
+ }
+
+ def calendarIntervalBuilder(months: Int, days: Int, microseconds: Long) = {
+ builder.getCalendarIntervalBuilder
+ .setMonths(months)
+ .setDays(days)
+ .setMicroseconds(microseconds)
+ }
+
+ def arrayBuilder(array: Array[_]) = {
+ val ab = builder.getArrayBuilder
+ .setElementType(componentTypeToProto(array.getClass.getComponentType))
+ array.foreach(x => ab.addElement(toLiteralProto(x)))
+ ab
+ }
+
+ literal match {
+ case v: Boolean => builder.setBoolean(v)
+ case v: Byte => builder.setByte(v)
+ case v: Short => builder.setShort(v)
+ case v: Int => builder.setInteger(v)
+ case v: Long => builder.setLong(v)
+ case v: Float => builder.setFloat(v)
+ case v: Double => builder.setDouble(v)
+ case v: BigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: JBigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: String => builder.setString(v)
+ case v: Char => builder.setString(v.toString)
+ case v: Array[Char] => builder.setString(String.valueOf(v))
+ case v: Array[Byte] => builder.setBinary(ByteString.copyFrom(v))
+ case v: collection.mutable.WrappedArray[_] => toLiteralProtoBuilder(v.array)
+ case v: LocalDate => builder.setDate(v.toEpochDay.toInt)
+ case v: Decimal =>
+ builder.setDecimal(decimalBuilder(Math.max(v.precision, v.scale), v.scale, v.toString))
+ case v: Instant => builder.setTimestamp(DateTimeUtils.instantToMicros(v))
+ case v: Timestamp => builder.setTimestamp(DateTimeUtils.fromJavaTimestamp(v))
+ case v: LocalDateTime => builder.setTimestampNtz(DateTimeUtils.localDateTimeToMicros(v))
+ case v: Date => builder.setDate(DateTimeUtils.fromJavaDate(v))
+ case v: Duration => builder.setDayTimeInterval(IntervalUtils.durationToMicros(v))
+ case v: Period => builder.setYearMonthInterval(IntervalUtils.periodToMonths(v))
+ case v: Array[_] => builder.setArray(arrayBuilder(v))
+ case v: CalendarInterval =>
+ builder.setCalendarInterval(calendarIntervalBuilder(v.months, v.days, v.microseconds))
+ case null => builder.setNull(nullType)
+ case _ => unsupported(s"literal $literal not supported (yet).")
+ }
+ }
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal`.
+ *
+ * @return
+ * proto.Expression.Literal
+ */
+ def toLiteralProto(literal: Any): proto.Expression.Literal =
+ toLiteralProtoBuilder(literal).build()
+
+ private def componentTypeToProto(clz: Class[_]): proto.DataType = clz match {
Review Comment:
Think more, let's keep this function in LiteralProtoConverter. If we implement MapType and other types, should be code changes 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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125240275
##########
connector/connect/common/src/main/protobuf/spark/connect/expressions.proto:
##########
@@ -189,6 +190,11 @@ message Expression {
int32 days = 2;
int64 microseconds = 3;
}
+
+ message Array {
+ DataType elementType = 1;
Review Comment:
Why do we need the element type? The element should be descriptive enough to figure this out.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125231861
##########
connector/connect/common/src/main/protobuf/spark/connect/expressions.proto:
##########
@@ -189,6 +190,11 @@ message Expression {
int32 days = 2;
int64 microseconds = 3;
}
+
+ message Array {
+ DataType elementType = 1;
+ repeated Literal element = 2;
Review Comment:
i would say element.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell closed pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell closed pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
URL: https://github.com/apache/spark/pull/40218
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125246264
##########
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 = {
Review Comment:
Let me try
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125241559
##########
connector/connect/common/src/main/protobuf/spark/connect/expressions.proto:
##########
@@ -189,6 +190,11 @@ message Expression {
int32 days = 2;
int64 microseconds = 3;
}
+
+ message Array {
+ DataType elementType = 1;
Review Comment:
nvm this does not work for empty arrays.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125817796
##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/LiteralValueProtoConverter.scala:
##########
@@ -130,4 +138,61 @@ object LiteralValueProtoConverter {
case o => throw new Exception(s"Unsupported value type: $o")
}
}
+
+ private def toArrayData(array: proto.Expression.Literal.Array): Any = {
+ def makeArrayData[T](converter: proto.Expression.Literal => T)(implicit
+ tag: ClassTag[T]): Array[T] = {
Review Comment:
yes
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1126383844
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JBoolean, Byte => JByte, Character => JChar, Double => JDouble, Float => JFloat, Integer => JInteger, Long => JLong, Short => JShort}
+import java.math.{BigDecimal => JBigDecimal}
+import java.sql.{Date, Timestamp}
+import java.time._
+
+import com.google.protobuf.ByteString
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils}
+import org.apache.spark.sql.connect.client.unsupported
+import org.apache.spark.sql.connect.common.DataTypeProtoConverter._
+import org.apache.spark.sql.types._
+import org.apache.spark.unsafe.types.CalendarInterval
+
+object LiteralProtoConverter {
+
+ private lazy val nullType =
+ proto.DataType.newBuilder().setNull(proto.DataType.NULL.getDefaultInstance).build()
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal.Builder`.
+ *
+ * @return
+ * proto.Expression.Literal.Builder
+ */
+ @scala.annotation.tailrec
+ def toLiteralProtoBuilder(literal: Any): proto.Expression.Literal.Builder = {
+ val builder = proto.Expression.Literal.newBuilder()
+
+ def decimalBuilder(precision: Int, scale: Int, value: String) = {
+ builder.getDecimalBuilder.setPrecision(precision).setScale(scale).setValue(value)
+ }
+
+ def calendarIntervalBuilder(months: Int, days: Int, microseconds: Long) = {
+ builder.getCalendarIntervalBuilder
+ .setMonths(months)
+ .setDays(days)
+ .setMicroseconds(microseconds)
+ }
+
+ def arrayBuilder(array: Array[_]) = {
+ val ab = builder.getArrayBuilder
+ .setElementType(toConnectProtoType(toDataType(array.getClass.getComponentType)))
+ array.foreach(x => ab.addElement(toLiteralProto(x)))
+ ab
+ }
+
+ literal match {
+ case v: Boolean => builder.setBoolean(v)
+ case v: Byte => builder.setByte(v)
+ case v: Short => builder.setShort(v)
+ case v: Int => builder.setInteger(v)
+ case v: Long => builder.setLong(v)
+ case v: Float => builder.setFloat(v)
+ case v: Double => builder.setDouble(v)
+ case v: BigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: JBigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: String => builder.setString(v)
+ case v: Char => builder.setString(v.toString)
+ case v: Array[Char] => builder.setString(String.valueOf(v))
+ case v: Array[Byte] => builder.setBinary(ByteString.copyFrom(v))
+ case v: collection.mutable.WrappedArray[_] => toLiteralProtoBuilder(v.array)
+ case v: LocalDate => builder.setDate(v.toEpochDay.toInt)
+ case v: Decimal =>
+ builder.setDecimal(decimalBuilder(Math.max(v.precision, v.scale), v.scale, v.toString))
+ case v: Instant => builder.setTimestamp(DateTimeUtils.instantToMicros(v))
+ case v: Timestamp => builder.setTimestamp(DateTimeUtils.fromJavaTimestamp(v))
+ case v: LocalDateTime => builder.setTimestampNtz(DateTimeUtils.localDateTimeToMicros(v))
+ case v: Date => builder.setDate(DateTimeUtils.fromJavaDate(v))
+ case v: Duration => builder.setDayTimeInterval(IntervalUtils.durationToMicros(v))
+ case v: Period => builder.setYearMonthInterval(IntervalUtils.periodToMonths(v))
+ case v: Array[_] => builder.setArray(arrayBuilder(v))
+ case v: CalendarInterval =>
+ builder.setCalendarInterval(calendarIntervalBuilder(v.months, v.days, v.microseconds))
+ case null => builder.setNull(nullType)
+ case _ => unsupported(s"literal $literal not supported (yet).")
+ }
+ }
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal`.
+ *
+ * @return
+ * proto.Expression.Literal
+ */
+ def toLiteralProto(literal: Any): proto.Expression.Literal =
Review Comment:
Yeah, let's make it as `private` first
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1126386137
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JBoolean, Byte => JByte, Character => JChar, Double => JDouble, Float => JFloat, Integer => JInteger, Long => JLong, Short => JShort}
+import java.math.{BigDecimal => JBigDecimal}
+import java.sql.{Date, Timestamp}
+import java.time._
+
+import com.google.protobuf.ByteString
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils}
+import org.apache.spark.sql.connect.client.unsupported
+import org.apache.spark.sql.connect.common.DataTypeProtoConverter._
+import org.apache.spark.sql.types._
+import org.apache.spark.unsafe.types.CalendarInterval
+
+object LiteralProtoConverter {
+
+ private lazy val nullType =
+ proto.DataType.newBuilder().setNull(proto.DataType.NULL.getDefaultInstance).build()
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal.Builder`.
+ *
+ * @return
+ * proto.Expression.Literal.Builder
+ */
+ @scala.annotation.tailrec
+ def toLiteralProtoBuilder(literal: Any): proto.Expression.Literal.Builder = {
+ val builder = proto.Expression.Literal.newBuilder()
+
+ def decimalBuilder(precision: Int, scale: Int, value: String) = {
+ builder.getDecimalBuilder.setPrecision(precision).setScale(scale).setValue(value)
+ }
+
+ def calendarIntervalBuilder(months: Int, days: Int, microseconds: Long) = {
+ builder.getCalendarIntervalBuilder
+ .setMonths(months)
+ .setDays(days)
+ .setMicroseconds(microseconds)
+ }
+
+ def arrayBuilder(array: Array[_]) = {
+ val ab = builder.getArrayBuilder
+ .setElementType(toConnectProtoType(toDataType(array.getClass.getComponentType)))
+ array.foreach(x => ab.addElement(toLiteralProto(x)))
+ ab
+ }
+
+ literal match {
+ case v: Boolean => builder.setBoolean(v)
+ case v: Byte => builder.setByte(v)
+ case v: Short => builder.setShort(v)
+ case v: Int => builder.setInteger(v)
+ case v: Long => builder.setLong(v)
+ case v: Float => builder.setFloat(v)
+ case v: Double => builder.setDouble(v)
+ case v: BigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: JBigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: String => builder.setString(v)
+ case v: Char => builder.setString(v.toString)
+ case v: Array[Char] => builder.setString(String.valueOf(v))
+ case v: Array[Byte] => builder.setBinary(ByteString.copyFrom(v))
+ case v: collection.mutable.WrappedArray[_] => toLiteralProtoBuilder(v.array)
+ case v: LocalDate => builder.setDate(v.toEpochDay.toInt)
+ case v: Decimal =>
+ builder.setDecimal(decimalBuilder(Math.max(v.precision, v.scale), v.scale, v.toString))
+ case v: Instant => builder.setTimestamp(DateTimeUtils.instantToMicros(v))
+ case v: Timestamp => builder.setTimestamp(DateTimeUtils.fromJavaTimestamp(v))
+ case v: LocalDateTime => builder.setTimestampNtz(DateTimeUtils.localDateTimeToMicros(v))
+ case v: Date => builder.setDate(DateTimeUtils.fromJavaDate(v))
+ case v: Duration => builder.setDayTimeInterval(IntervalUtils.durationToMicros(v))
+ case v: Period => builder.setYearMonthInterval(IntervalUtils.periodToMonths(v))
+ case v: Array[_] => builder.setArray(arrayBuilder(v))
+ case v: CalendarInterval =>
+ builder.setCalendarInterval(calendarIntervalBuilder(v.months, v.days, v.microseconds))
+ case null => builder.setNull(nullType)
+ case _ => unsupported(s"literal $literal not supported (yet).")
+ }
+ }
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal`.
+ *
+ * @return
+ * proto.Expression.Literal
+ */
+ def toLiteralProto(literal: Any): proto.Expression.Literal =
Review Comment:
done
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on PR #40218:
URL: https://github.com/apache/spark/pull/40218#issuecomment-1457373651
Thanks @hvanhovell
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1123020720
##########
connector/connect/common/src/main/protobuf/spark/connect/expressions.proto:
##########
@@ -189,6 +190,11 @@ message Expression {
int32 days = 2;
int64 microseconds = 3;
}
+
+ message Array {
+ DataType elementType = 1;
+ repeated Literal element = 2;
Review Comment:
should be `element` or `elements`?
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] pan3793 commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1121341315
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,289 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JavaBoolean, Byte => JavaByte, Character => JavaChar, Double => JavaDouble, Float => JavaFloat, Integer => JavaInteger, Long => JavaLong, Short => JavaShort}
Review Comment:
searched on the codebase, Spark used `import java.lang.{Boolean => JBoolean, Integer => JInteger, Long => JLong}` in other places.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125595959
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JBoolean, Byte => JByte, Character => JChar, Double => JDouble, Float => JFloat, Integer => JInteger, Long => JLong, Short => JShort}
+import java.math.{BigDecimal => JBigDecimal}
+import java.sql.{Date, Timestamp}
+import java.time._
+
+import com.google.protobuf.ByteString
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils}
+import org.apache.spark.sql.connect.client.unsupported
+import org.apache.spark.sql.connect.common.DataTypeProtoConverter._
+import org.apache.spark.sql.types._
+import org.apache.spark.unsafe.types.CalendarInterval
+
+object LiteralProtoConverter {
+
+ private lazy val nullType =
+ proto.DataType.newBuilder().setNull(proto.DataType.NULL.getDefaultInstance).build()
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal.Builder`.
+ *
+ * @return
+ * proto.Expression.Literal.Builder
+ */
+ @scala.annotation.tailrec
+ def toLiteralProtoBuilder(literal: Any): proto.Expression.Literal.Builder = {
+ val builder = proto.Expression.Literal.newBuilder()
+
+ def decimalBuilder(precision: Int, scale: Int, value: String) = {
+ builder.getDecimalBuilder.setPrecision(precision).setScale(scale).setValue(value)
+ }
+
+ def calendarIntervalBuilder(months: Int, days: Int, microseconds: Long) = {
+ builder.getCalendarIntervalBuilder
+ .setMonths(months)
+ .setDays(days)
+ .setMicroseconds(microseconds)
+ }
+
+ def arrayBuilder(array: Array[_]) = {
+ val ab = builder.getArrayBuilder
+ .setElementType(componentTypeToProto(array.getClass.getComponentType))
+ array.foreach(x => ab.addElement(toLiteralProto(x)))
+ ab
+ }
+
+ literal match {
+ case v: Boolean => builder.setBoolean(v)
+ case v: Byte => builder.setByte(v)
+ case v: Short => builder.setShort(v)
+ case v: Int => builder.setInteger(v)
+ case v: Long => builder.setLong(v)
+ case v: Float => builder.setFloat(v)
+ case v: Double => builder.setDouble(v)
+ case v: BigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: JBigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: String => builder.setString(v)
+ case v: Char => builder.setString(v.toString)
+ case v: Array[Char] => builder.setString(String.valueOf(v))
+ case v: Array[Byte] => builder.setBinary(ByteString.copyFrom(v))
+ case v: collection.mutable.WrappedArray[_] => toLiteralProtoBuilder(v.array)
+ case v: LocalDate => builder.setDate(v.toEpochDay.toInt)
+ case v: Decimal =>
+ builder.setDecimal(decimalBuilder(Math.max(v.precision, v.scale), v.scale, v.toString))
+ case v: Instant => builder.setTimestamp(DateTimeUtils.instantToMicros(v))
+ case v: Timestamp => builder.setTimestamp(DateTimeUtils.fromJavaTimestamp(v))
+ case v: LocalDateTime => builder.setTimestampNtz(DateTimeUtils.localDateTimeToMicros(v))
+ case v: Date => builder.setDate(DateTimeUtils.fromJavaDate(v))
+ case v: Duration => builder.setDayTimeInterval(IntervalUtils.durationToMicros(v))
+ case v: Period => builder.setYearMonthInterval(IntervalUtils.periodToMonths(v))
+ case v: Array[_] => builder.setArray(arrayBuilder(v))
+ case v: CalendarInterval =>
+ builder.setCalendarInterval(calendarIntervalBuilder(v.months, v.days, v.microseconds))
+ case null => builder.setNull(nullType)
+ case _ => unsupported(s"literal $literal not supported (yet).")
+ }
+ }
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal`.
+ *
+ * @return
+ * proto.Expression.Literal
+ */
+ def toLiteralProto(literal: Any): proto.Expression.Literal =
+ toLiteralProtoBuilder(literal).build()
+
+ private def componentTypeToProto(clz: Class[_]): proto.DataType = clz match {
+ // primitive types
+ case JShort.TYPE => toConnectProtoType(ShortType)
+ case JInteger.TYPE => toConnectProtoType(IntegerType)
+ case JLong.TYPE => toConnectProtoType(LongType)
+ case JDouble.TYPE => toConnectProtoType(DoubleType)
+ case JByte.TYPE => toConnectProtoType(ByteType)
+ case JFloat.TYPE => toConnectProtoType(FloatType)
+ case JBoolean.TYPE => toConnectProtoType(BooleanType)
+ case JChar.TYPE => toConnectProtoType(StringType)
+
+ // java classes
+ case _ if clz == classOf[LocalDate] || clz == classOf[Date] =>
+ toConnectProtoType(DateType)
+ case _ if clz == classOf[Instant] || clz == classOf[Timestamp] =>
+ toConnectProtoType(TimestampType)
+ case _ if clz == classOf[LocalDateTime] => toConnectProtoType(TimestampNTZType)
+ case _ if clz == classOf[Duration] => toConnectProtoType(DayTimeIntervalType.DEFAULT)
+ case _ if clz == classOf[Period] => toConnectProtoType(YearMonthIntervalType.DEFAULT)
+ case _ if clz == classOf[JBigDecimal] => toConnectProtoType(DecimalType.SYSTEM_DEFAULT)
+ case _ if clz == classOf[Array[Byte]] => toConnectProtoType(BinaryType)
+ case _ if clz == classOf[Array[Char]] => toConnectProtoType(StringType)
+ case _ if clz == classOf[JShort] => toConnectProtoType(ShortType)
+ case _ if clz == classOf[JInteger] => toConnectProtoType(IntegerType)
+ case _ if clz == classOf[JLong] => toConnectProtoType(LongType)
+ case _ if clz == classOf[JDouble] => toConnectProtoType(DoubleType)
+ case _ if clz == classOf[JByte] => toConnectProtoType(ByteType)
+ case _ if clz == classOf[JFloat] => toConnectProtoType(FloatType)
+ case _ if clz == classOf[JBoolean] => toConnectProtoType(BooleanType)
+
+ // other scala classes
+ case _ if clz == classOf[String] => toConnectProtoType(StringType)
+ case _ if clz == classOf[BigInt] || clz == classOf[BigDecimal] =>
+ toConnectProtoType(DecimalType.SYSTEM_DEFAULT)
+ case _ if clz == classOf[CalendarInterval] => toConnectProtoType(CalendarIntervalType)
Review Comment:
Should not be possible to call `toConnectProtoType` directly because the `elementType` of `ArrayType` cannot be determined there
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125837371
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,297 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JBoolean, Byte => JByte, Character => JChar, Double => JDouble, Float => JFloat, Integer => JInteger, Long => JLong, Short => JShort}
+import java.math.{BigDecimal => JBigDecimal}
+import java.sql.{Date, Timestamp}
+import java.time._
+
+import com.google.protobuf.ByteString
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils}
+import org.apache.spark.sql.connect.client.unsupported
+import org.apache.spark.sql.types.{DayTimeIntervalType, Decimal, DecimalType, YearMonthIntervalType}
+import org.apache.spark.unsafe.types.CalendarInterval
+
+object LiteralProtoConverter {
+
+ private lazy val nullType =
+ proto.DataType.newBuilder().setNull(proto.DataType.NULL.getDefaultInstance).build()
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal.Builder`.
+ *
+ * @return
+ * proto.Expression.Literal.Builder
+ */
+ @scala.annotation.tailrec
+ def toLiteralProtoBuilder(literal: Any): proto.Expression.Literal.Builder = {
+ val builder = proto.Expression.Literal.newBuilder()
+
+ def decimalBuilder(precision: Int, scale: Int, value: String) = {
+ builder.getDecimalBuilder.setPrecision(precision).setScale(scale).setValue(value)
+ }
+
+ def calendarIntervalBuilder(months: Int, days: Int, microseconds: Long) = {
+ builder.getCalendarIntervalBuilder
+ .setMonths(months)
+ .setDays(days)
+ .setMicroseconds(microseconds)
+ }
+
+ def arrayBuilder(array: Array[_]) = {
+ val ab = builder.getArrayBuilder
+ .setElementType(componentTypeToProto(array.getClass.getComponentType))
+ array.foreach(x => ab.addElement(toLiteralProto(x)))
+ ab
+ }
+
+ literal match {
+ case v: Boolean => builder.setBoolean(v)
+ case v: Byte => builder.setByte(v)
+ case v: Short => builder.setShort(v)
+ case v: Int => builder.setInteger(v)
+ case v: Long => builder.setLong(v)
+ case v: Float => builder.setFloat(v)
+ case v: Double => builder.setDouble(v)
+ case v: BigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: JBigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: String => builder.setString(v)
+ case v: Char => builder.setString(v.toString)
+ case v: Array[Char] => builder.setString(String.valueOf(v))
+ case v: Array[Byte] => builder.setBinary(ByteString.copyFrom(v))
+ case v: collection.mutable.WrappedArray[_] => toLiteralProtoBuilder(v.array)
+ case v: LocalDate => builder.setDate(v.toEpochDay.toInt)
+ case v: Decimal =>
+ builder.setDecimal(decimalBuilder(Math.max(v.precision, v.scale), v.scale, v.toString))
+ case v: Instant => builder.setTimestamp(DateTimeUtils.instantToMicros(v))
+ case v: Timestamp => builder.setTimestamp(DateTimeUtils.fromJavaTimestamp(v))
+ case v: LocalDateTime => builder.setTimestampNtz(DateTimeUtils.localDateTimeToMicros(v))
+ case v: Date => builder.setDate(DateTimeUtils.fromJavaDate(v))
+ case v: Duration => builder.setDayTimeInterval(IntervalUtils.durationToMicros(v))
+ case v: Period => builder.setYearMonthInterval(IntervalUtils.periodToMonths(v))
+ case v: Array[_] => builder.setArray(arrayBuilder(v))
+ case v: CalendarInterval =>
+ builder.setCalendarInterval(calendarIntervalBuilder(v.months, v.days, v.microseconds))
+ case null => builder.setNull(nullType)
+ case _ => unsupported(s"literal $literal not supported (yet).")
+ }
+ }
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal`.
+ *
+ * @return
+ * proto.Expression.Literal
+ */
+ def toLiteralProto(literal: Any): proto.Expression.Literal =
+ toLiteralProtoBuilder(literal).build()
+
+ private def componentTypeToProto(clz: Class[_]): proto.DataType = clz match {
Review Comment:
hmm .. should we just make
https://github.com/apache/spark/blob/4b8b36834e2902184088d171ee919cf5c5e3b9a3/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala#L109-L148
as public ? I think it It is equivalent to `toDataType `
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125820525
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,297 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JBoolean, Byte => JByte, Character => JChar, Double => JDouble, Float => JFloat, Integer => JInteger, Long => JLong, Short => JShort}
+import java.math.{BigDecimal => JBigDecimal}
+import java.sql.{Date, Timestamp}
+import java.time._
+
+import com.google.protobuf.ByteString
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils}
+import org.apache.spark.sql.connect.client.unsupported
+import org.apache.spark.sql.types.{DayTimeIntervalType, Decimal, DecimalType, YearMonthIntervalType}
+import org.apache.spark.unsafe.types.CalendarInterval
+
+object LiteralProtoConverter {
+
+ private lazy val nullType =
+ proto.DataType.newBuilder().setNull(proto.DataType.NULL.getDefaultInstance).build()
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal.Builder`.
+ *
+ * @return
+ * proto.Expression.Literal.Builder
+ */
+ @scala.annotation.tailrec
+ def toLiteralProtoBuilder(literal: Any): proto.Expression.Literal.Builder = {
+ val builder = proto.Expression.Literal.newBuilder()
+
+ def decimalBuilder(precision: Int, scale: Int, value: String) = {
+ builder.getDecimalBuilder.setPrecision(precision).setScale(scale).setValue(value)
+ }
+
+ def calendarIntervalBuilder(months: Int, days: Int, microseconds: Long) = {
+ builder.getCalendarIntervalBuilder
+ .setMonths(months)
+ .setDays(days)
+ .setMicroseconds(microseconds)
+ }
+
+ def arrayBuilder(array: Array[_]) = {
+ val ab = builder.getArrayBuilder
+ .setElementType(componentTypeToProto(array.getClass.getComponentType))
+ array.foreach(x => ab.addElement(toLiteralProto(x)))
+ ab
+ }
+
+ literal match {
+ case v: Boolean => builder.setBoolean(v)
+ case v: Byte => builder.setByte(v)
+ case v: Short => builder.setShort(v)
+ case v: Int => builder.setInteger(v)
+ case v: Long => builder.setLong(v)
+ case v: Float => builder.setFloat(v)
+ case v: Double => builder.setDouble(v)
+ case v: BigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: JBigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: String => builder.setString(v)
+ case v: Char => builder.setString(v.toString)
+ case v: Array[Char] => builder.setString(String.valueOf(v))
+ case v: Array[Byte] => builder.setBinary(ByteString.copyFrom(v))
+ case v: collection.mutable.WrappedArray[_] => toLiteralProtoBuilder(v.array)
+ case v: LocalDate => builder.setDate(v.toEpochDay.toInt)
+ case v: Decimal =>
+ builder.setDecimal(decimalBuilder(Math.max(v.precision, v.scale), v.scale, v.toString))
+ case v: Instant => builder.setTimestamp(DateTimeUtils.instantToMicros(v))
+ case v: Timestamp => builder.setTimestamp(DateTimeUtils.fromJavaTimestamp(v))
+ case v: LocalDateTime => builder.setTimestampNtz(DateTimeUtils.localDateTimeToMicros(v))
+ case v: Date => builder.setDate(DateTimeUtils.fromJavaDate(v))
+ case v: Duration => builder.setDayTimeInterval(IntervalUtils.durationToMicros(v))
+ case v: Period => builder.setYearMonthInterval(IntervalUtils.periodToMonths(v))
+ case v: Array[_] => builder.setArray(arrayBuilder(v))
+ case v: CalendarInterval =>
+ builder.setCalendarInterval(calendarIntervalBuilder(v.months, v.days, v.microseconds))
+ case null => builder.setNull(nullType)
+ case _ => unsupported(s"literal $literal not supported (yet).")
+ }
+ }
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal`.
+ *
+ * @return
+ * proto.Expression.Literal
+ */
+ def toLiteralProto(literal: Any): proto.Expression.Literal =
+ toLiteralProtoBuilder(literal).build()
+
+ private def componentTypeToProto(clz: Class[_]): proto.DataType = clz match {
Review Comment:
So I'd slightly pull it apart more. Create one method that convers the `Class` into a `DataType`, and another converts it into `proto.DataType`. For example:
```scala
private def toDataType(cls: Class[_]): DataType = {
... // most of your current code
}
provate def toProtoDataType(cls: Class[_]): proto.DataType = {
toConnectProtoType(toDataType(cls))
}
```
That way it is easier to test the individual components. Bonus point if you write a UT 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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125852404
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,297 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JBoolean, Byte => JByte, Character => JChar, Double => JDouble, Float => JFloat, Integer => JInteger, Long => JLong, Short => JShort}
+import java.math.{BigDecimal => JBigDecimal}
+import java.sql.{Date, Timestamp}
+import java.time._
+
+import com.google.protobuf.ByteString
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils}
+import org.apache.spark.sql.connect.client.unsupported
+import org.apache.spark.sql.types.{DayTimeIntervalType, Decimal, DecimalType, YearMonthIntervalType}
+import org.apache.spark.unsafe.types.CalendarInterval
+
+object LiteralProtoConverter {
+
+ private lazy val nullType =
+ proto.DataType.newBuilder().setNull(proto.DataType.NULL.getDefaultInstance).build()
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal.Builder`.
+ *
+ * @return
+ * proto.Expression.Literal.Builder
+ */
+ @scala.annotation.tailrec
+ def toLiteralProtoBuilder(literal: Any): proto.Expression.Literal.Builder = {
+ val builder = proto.Expression.Literal.newBuilder()
+
+ def decimalBuilder(precision: Int, scale: Int, value: String) = {
+ builder.getDecimalBuilder.setPrecision(precision).setScale(scale).setValue(value)
+ }
+
+ def calendarIntervalBuilder(months: Int, days: Int, microseconds: Long) = {
+ builder.getCalendarIntervalBuilder
+ .setMonths(months)
+ .setDays(days)
+ .setMicroseconds(microseconds)
+ }
+
+ def arrayBuilder(array: Array[_]) = {
+ val ab = builder.getArrayBuilder
+ .setElementType(componentTypeToProto(array.getClass.getComponentType))
+ array.foreach(x => ab.addElement(toLiteralProto(x)))
+ ab
+ }
+
+ literal match {
+ case v: Boolean => builder.setBoolean(v)
+ case v: Byte => builder.setByte(v)
+ case v: Short => builder.setShort(v)
+ case v: Int => builder.setInteger(v)
+ case v: Long => builder.setLong(v)
+ case v: Float => builder.setFloat(v)
+ case v: Double => builder.setDouble(v)
+ case v: BigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: JBigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: String => builder.setString(v)
+ case v: Char => builder.setString(v.toString)
+ case v: Array[Char] => builder.setString(String.valueOf(v))
+ case v: Array[Byte] => builder.setBinary(ByteString.copyFrom(v))
+ case v: collection.mutable.WrappedArray[_] => toLiteralProtoBuilder(v.array)
+ case v: LocalDate => builder.setDate(v.toEpochDay.toInt)
+ case v: Decimal =>
+ builder.setDecimal(decimalBuilder(Math.max(v.precision, v.scale), v.scale, v.toString))
+ case v: Instant => builder.setTimestamp(DateTimeUtils.instantToMicros(v))
+ case v: Timestamp => builder.setTimestamp(DateTimeUtils.fromJavaTimestamp(v))
+ case v: LocalDateTime => builder.setTimestampNtz(DateTimeUtils.localDateTimeToMicros(v))
+ case v: Date => builder.setDate(DateTimeUtils.fromJavaDate(v))
+ case v: Duration => builder.setDayTimeInterval(IntervalUtils.durationToMicros(v))
+ case v: Period => builder.setYearMonthInterval(IntervalUtils.periodToMonths(v))
+ case v: Array[_] => builder.setArray(arrayBuilder(v))
+ case v: CalendarInterval =>
+ builder.setCalendarInterval(calendarIntervalBuilder(v.months, v.days, v.microseconds))
+ case null => builder.setNull(nullType)
+ case _ => unsupported(s"literal $literal not supported (yet).")
+ }
+ }
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal`.
+ *
+ * @return
+ * proto.Expression.Literal
+ */
+ def toLiteralProto(literal: Any): proto.Expression.Literal =
+ toLiteralProtoBuilder(literal).build()
+
+ private def componentTypeToProto(clz: Class[_]): proto.DataType = clz match {
Review Comment:
Let's keep this function. If we implement MapType and other types, should be code changes 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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125229080
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,289 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JavaBoolean, Byte => JavaByte, Character => JavaChar, Double => JavaDouble, Float => JavaFloat, Integer => JavaInteger, Long => JavaLong, Short => JavaShort}
+import java.math.{BigDecimal => JavaBigDecimal}
+import java.sql.{Date, Timestamp}
+import java.time._
+
+import com.google.protobuf.ByteString
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils}
+import org.apache.spark.sql.connect.client.unsupported
+import org.apache.spark.sql.types.{DayTimeIntervalType, Decimal, DecimalType, YearMonthIntervalType}
+import org.apache.spark.unsafe.types.CalendarInterval
+
+object LiteralProtoConverter {
+
+ private lazy val nullType =
+ proto.DataType.newBuilder().setNull(proto.DataType.NULL.getDefaultInstance).build()
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal.Builder`.
+ *
+ * @return proto.Expression.Literal.Builder
+ */
+ @scala.annotation.tailrec
+ def toLiteralProtoBuilder(literal: Any): proto.Expression.Literal.Builder = {
Review Comment:
Is that is the reason, that feels a tad excessive. However you have already put in the work, so I guess we'll run with it.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1126377905
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JBoolean, Byte => JByte, Character => JChar, Double => JDouble, Float => JFloat, Integer => JInteger, Long => JLong, Short => JShort}
+import java.math.{BigDecimal => JBigDecimal}
+import java.sql.{Date, Timestamp}
+import java.time._
+
+import com.google.protobuf.ByteString
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils}
+import org.apache.spark.sql.connect.client.unsupported
+import org.apache.spark.sql.connect.common.DataTypeProtoConverter._
+import org.apache.spark.sql.types._
+import org.apache.spark.unsafe.types.CalendarInterval
+
+object LiteralProtoConverter {
+
+ private lazy val nullType =
+ proto.DataType.newBuilder().setNull(proto.DataType.NULL.getDefaultInstance).build()
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal.Builder`.
+ *
+ * @return
+ * proto.Expression.Literal.Builder
+ */
+ @scala.annotation.tailrec
+ def toLiteralProtoBuilder(literal: Any): proto.Expression.Literal.Builder = {
+ val builder = proto.Expression.Literal.newBuilder()
+
+ def decimalBuilder(precision: Int, scale: Int, value: String) = {
+ builder.getDecimalBuilder.setPrecision(precision).setScale(scale).setValue(value)
+ }
+
+ def calendarIntervalBuilder(months: Int, days: Int, microseconds: Long) = {
+ builder.getCalendarIntervalBuilder
+ .setMonths(months)
+ .setDays(days)
+ .setMicroseconds(microseconds)
+ }
+
+ def arrayBuilder(array: Array[_]) = {
+ val ab = builder.getArrayBuilder
+ .setElementType(toConnectProtoType(toDataType(array.getClass.getComponentType)))
+ array.foreach(x => ab.addElement(toLiteralProto(x)))
+ ab
+ }
+
+ literal match {
+ case v: Boolean => builder.setBoolean(v)
+ case v: Byte => builder.setByte(v)
+ case v: Short => builder.setShort(v)
+ case v: Int => builder.setInteger(v)
+ case v: Long => builder.setLong(v)
+ case v: Float => builder.setFloat(v)
+ case v: Double => builder.setDouble(v)
+ case v: BigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: JBigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: String => builder.setString(v)
+ case v: Char => builder.setString(v.toString)
+ case v: Array[Char] => builder.setString(String.valueOf(v))
+ case v: Array[Byte] => builder.setBinary(ByteString.copyFrom(v))
+ case v: collection.mutable.WrappedArray[_] => toLiteralProtoBuilder(v.array)
+ case v: LocalDate => builder.setDate(v.toEpochDay.toInt)
+ case v: Decimal =>
+ builder.setDecimal(decimalBuilder(Math.max(v.precision, v.scale), v.scale, v.toString))
+ case v: Instant => builder.setTimestamp(DateTimeUtils.instantToMicros(v))
+ case v: Timestamp => builder.setTimestamp(DateTimeUtils.fromJavaTimestamp(v))
+ case v: LocalDateTime => builder.setTimestampNtz(DateTimeUtils.localDateTimeToMicros(v))
+ case v: Date => builder.setDate(DateTimeUtils.fromJavaDate(v))
+ case v: Duration => builder.setDayTimeInterval(IntervalUtils.durationToMicros(v))
+ case v: Period => builder.setYearMonthInterval(IntervalUtils.periodToMonths(v))
+ case v: Array[_] => builder.setArray(arrayBuilder(v))
+ case v: CalendarInterval =>
+ builder.setCalendarInterval(calendarIntervalBuilder(v.months, v.days, v.microseconds))
+ case null => builder.setNull(nullType)
+ case _ => unsupported(s"literal $literal not supported (yet).")
+ }
+ }
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal`.
+ *
+ * @return
+ * proto.Expression.Literal
+ */
+ def toLiteralProto(literal: Any): proto.Expression.Literal =
Review Comment:
private?
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1121347931
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,289 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JavaBoolean, Byte => JavaByte, Character => JavaChar, Double => JavaDouble, Float => JavaFloat, Integer => JavaInteger, Long => JavaLong, Short => JavaShort}
Review Comment:
done
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1121260378
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,289 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JavaBoolean, Byte => JavaByte, Character => JavaChar, Double => JavaDouble, Float => JavaFloat, Integer => JavaInteger, Long => JavaLong, Short => JavaShort}
+import java.math.{BigDecimal => JavaBigDecimal}
+import java.sql.{Date, Timestamp}
+import java.time._
+
+import com.google.protobuf.ByteString
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils}
+import org.apache.spark.sql.connect.client.unsupported
+import org.apache.spark.sql.types.{DayTimeIntervalType, Decimal, DecimalType, YearMonthIntervalType}
+import org.apache.spark.unsafe.types.CalendarInterval
+
+object LiteralProtoConverter {
+
+ private lazy val nullType =
+ proto.DataType.newBuilder().setNull(proto.DataType.NULL.getDefaultInstance).build()
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal.Builder`.
+ *
+ * @return proto.Expression.Literal.Builder
+ */
+ @scala.annotation.tailrec
+ def toLiteralProtoBuilder(literal: Any): proto.Expression.Literal.Builder = {
Review Comment:
The purpose of refactoring is to avoid get `proto.Expression.Literal` through `lit(x).expr.getLiteral`
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,289 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JavaBoolean, Byte => JavaByte, Character => JavaChar, Double => JavaDouble, Float => JavaFloat, Integer => JavaInteger, Long => JavaLong, Short => JavaShort}
+import java.math.{BigDecimal => JavaBigDecimal}
+import java.sql.{Date, Timestamp}
+import java.time._
+
+import com.google.protobuf.ByteString
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils}
+import org.apache.spark.sql.connect.client.unsupported
+import org.apache.spark.sql.types.{DayTimeIntervalType, Decimal, DecimalType, YearMonthIntervalType}
+import org.apache.spark.unsafe.types.CalendarInterval
+
+object LiteralProtoConverter {
+
+ private lazy val nullType =
+ proto.DataType.newBuilder().setNull(proto.DataType.NULL.getDefaultInstance).build()
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal.Builder`.
+ *
+ * @return proto.Expression.Literal.Builder
+ */
+ @scala.annotation.tailrec
+ def toLiteralProtoBuilder(literal: Any): proto.Expression.Literal.Builder = {
Review Comment:
The purpose of this refactoring is to avoid get `proto.Expression.Literal` through `lit(x).expr.getLiteral`
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125595915
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JBoolean, Byte => JByte, Character => JChar, Double => JDouble, Float => JFloat, Integer => JInteger, Long => JLong, Short => JShort}
+import java.math.{BigDecimal => JBigDecimal}
+import java.sql.{Date, Timestamp}
+import java.time._
+
+import com.google.protobuf.ByteString
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils}
+import org.apache.spark.sql.connect.client.unsupported
+import org.apache.spark.sql.connect.common.DataTypeProtoConverter._
+import org.apache.spark.sql.types._
+import org.apache.spark.unsafe.types.CalendarInterval
+
+object LiteralProtoConverter {
+
+ private lazy val nullType =
+ proto.DataType.newBuilder().setNull(proto.DataType.NULL.getDefaultInstance).build()
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal.Builder`.
+ *
+ * @return
+ * proto.Expression.Literal.Builder
+ */
+ @scala.annotation.tailrec
+ def toLiteralProtoBuilder(literal: Any): proto.Expression.Literal.Builder = {
+ val builder = proto.Expression.Literal.newBuilder()
+
+ def decimalBuilder(precision: Int, scale: Int, value: String) = {
+ builder.getDecimalBuilder.setPrecision(precision).setScale(scale).setValue(value)
+ }
+
+ def calendarIntervalBuilder(months: Int, days: Int, microseconds: Long) = {
+ builder.getCalendarIntervalBuilder
+ .setMonths(months)
+ .setDays(days)
+ .setMicroseconds(microseconds)
+ }
+
+ def arrayBuilder(array: Array[_]) = {
+ val ab = builder.getArrayBuilder
+ .setElementType(componentTypeToProto(array.getClass.getComponentType))
+ array.foreach(x => ab.addElement(toLiteralProto(x)))
+ ab
+ }
+
+ literal match {
+ case v: Boolean => builder.setBoolean(v)
+ case v: Byte => builder.setByte(v)
+ case v: Short => builder.setShort(v)
+ case v: Int => builder.setInteger(v)
+ case v: Long => builder.setLong(v)
+ case v: Float => builder.setFloat(v)
+ case v: Double => builder.setDouble(v)
+ case v: BigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: JBigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: String => builder.setString(v)
+ case v: Char => builder.setString(v.toString)
+ case v: Array[Char] => builder.setString(String.valueOf(v))
+ case v: Array[Byte] => builder.setBinary(ByteString.copyFrom(v))
+ case v: collection.mutable.WrappedArray[_] => toLiteralProtoBuilder(v.array)
+ case v: LocalDate => builder.setDate(v.toEpochDay.toInt)
+ case v: Decimal =>
+ builder.setDecimal(decimalBuilder(Math.max(v.precision, v.scale), v.scale, v.toString))
+ case v: Instant => builder.setTimestamp(DateTimeUtils.instantToMicros(v))
+ case v: Timestamp => builder.setTimestamp(DateTimeUtils.fromJavaTimestamp(v))
+ case v: LocalDateTime => builder.setTimestampNtz(DateTimeUtils.localDateTimeToMicros(v))
+ case v: Date => builder.setDate(DateTimeUtils.fromJavaDate(v))
+ case v: Duration => builder.setDayTimeInterval(IntervalUtils.durationToMicros(v))
+ case v: Period => builder.setYearMonthInterval(IntervalUtils.periodToMonths(v))
+ case v: Array[_] => builder.setArray(arrayBuilder(v))
+ case v: CalendarInterval =>
+ builder.setCalendarInterval(calendarIntervalBuilder(v.months, v.days, v.microseconds))
+ case null => builder.setNull(nullType)
+ case _ => unsupported(s"literal $literal not supported (yet).")
+ }
+ }
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal`.
+ *
+ * @return
+ * proto.Expression.Literal
+ */
+ def toLiteralProto(literal: Any): proto.Expression.Literal =
+ toLiteralProtoBuilder(literal).build()
+
+ private def componentTypeToProto(clz: Class[_]): proto.DataType = clz match {
+ // primitive types
+ case JShort.TYPE => toConnectProtoType(ShortType)
+ case JInteger.TYPE => toConnectProtoType(IntegerType)
+ case JLong.TYPE => toConnectProtoType(LongType)
+ case JDouble.TYPE => toConnectProtoType(DoubleType)
+ case JByte.TYPE => toConnectProtoType(ByteType)
+ case JFloat.TYPE => toConnectProtoType(FloatType)
+ case JBoolean.TYPE => toConnectProtoType(BooleanType)
+ case JChar.TYPE => toConnectProtoType(StringType)
+
+ // java classes
+ case _ if clz == classOf[LocalDate] || clz == classOf[Date] =>
+ toConnectProtoType(DateType)
+ case _ if clz == classOf[Instant] || clz == classOf[Timestamp] =>
+ toConnectProtoType(TimestampType)
+ case _ if clz == classOf[LocalDateTime] => toConnectProtoType(TimestampNTZType)
+ case _ if clz == classOf[Duration] => toConnectProtoType(DayTimeIntervalType.DEFAULT)
+ case _ if clz == classOf[Period] => toConnectProtoType(YearMonthIntervalType.DEFAULT)
+ case _ if clz == classOf[JBigDecimal] => toConnectProtoType(DecimalType.SYSTEM_DEFAULT)
+ case _ if clz == classOf[Array[Byte]] => toConnectProtoType(BinaryType)
+ case _ if clz == classOf[Array[Char]] => toConnectProtoType(StringType)
+ case _ if clz == classOf[JShort] => toConnectProtoType(ShortType)
+ case _ if clz == classOf[JInteger] => toConnectProtoType(IntegerType)
+ case _ if clz == classOf[JLong] => toConnectProtoType(LongType)
+ case _ if clz == classOf[JDouble] => toConnectProtoType(DoubleType)
+ case _ if clz == classOf[JByte] => toConnectProtoType(ByteType)
+ case _ if clz == classOf[JFloat] => toConnectProtoType(FloatType)
+ case _ if clz == classOf[JBoolean] => toConnectProtoType(BooleanType)
+
+ // other scala classes
+ case _ if clz == classOf[String] => toConnectProtoType(StringType)
+ case _ if clz == classOf[BigInt] || clz == classOf[BigDecimal] =>
+ toConnectProtoType(DecimalType.SYSTEM_DEFAULT)
+ case _ if clz == classOf[CalendarInterval] => toConnectProtoType(CalendarIntervalType)
Review Comment:
Should not be possible to call `toConnectProtoType` directly because the `elementType` of `ArrayType` cannot be determined there
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125595959
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JBoolean, Byte => JByte, Character => JChar, Double => JDouble, Float => JFloat, Integer => JInteger, Long => JLong, Short => JShort}
+import java.math.{BigDecimal => JBigDecimal}
+import java.sql.{Date, Timestamp}
+import java.time._
+
+import com.google.protobuf.ByteString
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils}
+import org.apache.spark.sql.connect.client.unsupported
+import org.apache.spark.sql.connect.common.DataTypeProtoConverter._
+import org.apache.spark.sql.types._
+import org.apache.spark.unsafe.types.CalendarInterval
+
+object LiteralProtoConverter {
+
+ private lazy val nullType =
+ proto.DataType.newBuilder().setNull(proto.DataType.NULL.getDefaultInstance).build()
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal.Builder`.
+ *
+ * @return
+ * proto.Expression.Literal.Builder
+ */
+ @scala.annotation.tailrec
+ def toLiteralProtoBuilder(literal: Any): proto.Expression.Literal.Builder = {
+ val builder = proto.Expression.Literal.newBuilder()
+
+ def decimalBuilder(precision: Int, scale: Int, value: String) = {
+ builder.getDecimalBuilder.setPrecision(precision).setScale(scale).setValue(value)
+ }
+
+ def calendarIntervalBuilder(months: Int, days: Int, microseconds: Long) = {
+ builder.getCalendarIntervalBuilder
+ .setMonths(months)
+ .setDays(days)
+ .setMicroseconds(microseconds)
+ }
+
+ def arrayBuilder(array: Array[_]) = {
+ val ab = builder.getArrayBuilder
+ .setElementType(componentTypeToProto(array.getClass.getComponentType))
+ array.foreach(x => ab.addElement(toLiteralProto(x)))
+ ab
+ }
+
+ literal match {
+ case v: Boolean => builder.setBoolean(v)
+ case v: Byte => builder.setByte(v)
+ case v: Short => builder.setShort(v)
+ case v: Int => builder.setInteger(v)
+ case v: Long => builder.setLong(v)
+ case v: Float => builder.setFloat(v)
+ case v: Double => builder.setDouble(v)
+ case v: BigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: JBigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: String => builder.setString(v)
+ case v: Char => builder.setString(v.toString)
+ case v: Array[Char] => builder.setString(String.valueOf(v))
+ case v: Array[Byte] => builder.setBinary(ByteString.copyFrom(v))
+ case v: collection.mutable.WrappedArray[_] => toLiteralProtoBuilder(v.array)
+ case v: LocalDate => builder.setDate(v.toEpochDay.toInt)
+ case v: Decimal =>
+ builder.setDecimal(decimalBuilder(Math.max(v.precision, v.scale), v.scale, v.toString))
+ case v: Instant => builder.setTimestamp(DateTimeUtils.instantToMicros(v))
+ case v: Timestamp => builder.setTimestamp(DateTimeUtils.fromJavaTimestamp(v))
+ case v: LocalDateTime => builder.setTimestampNtz(DateTimeUtils.localDateTimeToMicros(v))
+ case v: Date => builder.setDate(DateTimeUtils.fromJavaDate(v))
+ case v: Duration => builder.setDayTimeInterval(IntervalUtils.durationToMicros(v))
+ case v: Period => builder.setYearMonthInterval(IntervalUtils.periodToMonths(v))
+ case v: Array[_] => builder.setArray(arrayBuilder(v))
+ case v: CalendarInterval =>
+ builder.setCalendarInterval(calendarIntervalBuilder(v.months, v.days, v.microseconds))
+ case null => builder.setNull(nullType)
+ case _ => unsupported(s"literal $literal not supported (yet).")
+ }
+ }
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal`.
+ *
+ * @return
+ * proto.Expression.Literal
+ */
+ def toLiteralProto(literal: Any): proto.Expression.Literal =
+ toLiteralProtoBuilder(literal).build()
+
+ private def componentTypeToProto(clz: Class[_]): proto.DataType = clz match {
+ // primitive types
+ case JShort.TYPE => toConnectProtoType(ShortType)
+ case JInteger.TYPE => toConnectProtoType(IntegerType)
+ case JLong.TYPE => toConnectProtoType(LongType)
+ case JDouble.TYPE => toConnectProtoType(DoubleType)
+ case JByte.TYPE => toConnectProtoType(ByteType)
+ case JFloat.TYPE => toConnectProtoType(FloatType)
+ case JBoolean.TYPE => toConnectProtoType(BooleanType)
+ case JChar.TYPE => toConnectProtoType(StringType)
+
+ // java classes
+ case _ if clz == classOf[LocalDate] || clz == classOf[Date] =>
+ toConnectProtoType(DateType)
+ case _ if clz == classOf[Instant] || clz == classOf[Timestamp] =>
+ toConnectProtoType(TimestampType)
+ case _ if clz == classOf[LocalDateTime] => toConnectProtoType(TimestampNTZType)
+ case _ if clz == classOf[Duration] => toConnectProtoType(DayTimeIntervalType.DEFAULT)
+ case _ if clz == classOf[Period] => toConnectProtoType(YearMonthIntervalType.DEFAULT)
+ case _ if clz == classOf[JBigDecimal] => toConnectProtoType(DecimalType.SYSTEM_DEFAULT)
+ case _ if clz == classOf[Array[Byte]] => toConnectProtoType(BinaryType)
+ case _ if clz == classOf[Array[Char]] => toConnectProtoType(StringType)
+ case _ if clz == classOf[JShort] => toConnectProtoType(ShortType)
+ case _ if clz == classOf[JInteger] => toConnectProtoType(IntegerType)
+ case _ if clz == classOf[JLong] => toConnectProtoType(LongType)
+ case _ if clz == classOf[JDouble] => toConnectProtoType(DoubleType)
+ case _ if clz == classOf[JByte] => toConnectProtoType(ByteType)
+ case _ if clz == classOf[JFloat] => toConnectProtoType(FloatType)
+ case _ if clz == classOf[JBoolean] => toConnectProtoType(BooleanType)
+
+ // other scala classes
+ case _ if clz == classOf[String] => toConnectProtoType(StringType)
+ case _ if clz == classOf[BigInt] || clz == classOf[BigDecimal] =>
+ toConnectProtoType(DecimalType.SYSTEM_DEFAULT)
+ case _ if clz == classOf[CalendarInterval] => toConnectProtoType(CalendarIntervalType)
Review Comment:
Should not be possible to call toConnectProtoType directly because the elementType of ArrayType cannot be determined there
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125837371
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,297 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JBoolean, Byte => JByte, Character => JChar, Double => JDouble, Float => JFloat, Integer => JInteger, Long => JLong, Short => JShort}
+import java.math.{BigDecimal => JBigDecimal}
+import java.sql.{Date, Timestamp}
+import java.time._
+
+import com.google.protobuf.ByteString
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils}
+import org.apache.spark.sql.connect.client.unsupported
+import org.apache.spark.sql.types.{DayTimeIntervalType, Decimal, DecimalType, YearMonthIntervalType}
+import org.apache.spark.unsafe.types.CalendarInterval
+
+object LiteralProtoConverter {
+
+ private lazy val nullType =
+ proto.DataType.newBuilder().setNull(proto.DataType.NULL.getDefaultInstance).build()
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal.Builder`.
+ *
+ * @return
+ * proto.Expression.Literal.Builder
+ */
+ @scala.annotation.tailrec
+ def toLiteralProtoBuilder(literal: Any): proto.Expression.Literal.Builder = {
+ val builder = proto.Expression.Literal.newBuilder()
+
+ def decimalBuilder(precision: Int, scale: Int, value: String) = {
+ builder.getDecimalBuilder.setPrecision(precision).setScale(scale).setValue(value)
+ }
+
+ def calendarIntervalBuilder(months: Int, days: Int, microseconds: Long) = {
+ builder.getCalendarIntervalBuilder
+ .setMonths(months)
+ .setDays(days)
+ .setMicroseconds(microseconds)
+ }
+
+ def arrayBuilder(array: Array[_]) = {
+ val ab = builder.getArrayBuilder
+ .setElementType(componentTypeToProto(array.getClass.getComponentType))
+ array.foreach(x => ab.addElement(toLiteralProto(x)))
+ ab
+ }
+
+ literal match {
+ case v: Boolean => builder.setBoolean(v)
+ case v: Byte => builder.setByte(v)
+ case v: Short => builder.setShort(v)
+ case v: Int => builder.setInteger(v)
+ case v: Long => builder.setLong(v)
+ case v: Float => builder.setFloat(v)
+ case v: Double => builder.setDouble(v)
+ case v: BigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: JBigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: String => builder.setString(v)
+ case v: Char => builder.setString(v.toString)
+ case v: Array[Char] => builder.setString(String.valueOf(v))
+ case v: Array[Byte] => builder.setBinary(ByteString.copyFrom(v))
+ case v: collection.mutable.WrappedArray[_] => toLiteralProtoBuilder(v.array)
+ case v: LocalDate => builder.setDate(v.toEpochDay.toInt)
+ case v: Decimal =>
+ builder.setDecimal(decimalBuilder(Math.max(v.precision, v.scale), v.scale, v.toString))
+ case v: Instant => builder.setTimestamp(DateTimeUtils.instantToMicros(v))
+ case v: Timestamp => builder.setTimestamp(DateTimeUtils.fromJavaTimestamp(v))
+ case v: LocalDateTime => builder.setTimestampNtz(DateTimeUtils.localDateTimeToMicros(v))
+ case v: Date => builder.setDate(DateTimeUtils.fromJavaDate(v))
+ case v: Duration => builder.setDayTimeInterval(IntervalUtils.durationToMicros(v))
+ case v: Period => builder.setYearMonthInterval(IntervalUtils.periodToMonths(v))
+ case v: Array[_] => builder.setArray(arrayBuilder(v))
+ case v: CalendarInterval =>
+ builder.setCalendarInterval(calendarIntervalBuilder(v.months, v.days, v.microseconds))
+ case null => builder.setNull(nullType)
+ case _ => unsupported(s"literal $literal not supported (yet).")
+ }
+ }
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal`.
+ *
+ * @return
+ * proto.Expression.Literal
+ */
+ def toLiteralProto(literal: Any): proto.Expression.Literal =
+ toLiteralProtoBuilder(literal).build()
+
+ private def componentTypeToProto(clz: Class[_]): proto.DataType = clz match {
Review Comment:
hmm .. should we make
https://github.com/apache/spark/blob/4b8b36834e2902184088d171ee919cf5c5e3b9a3/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala#L109-L148
as public ? I think it It is equivalent to `toDataType `
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1121343776
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,289 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JavaBoolean, Byte => JavaByte, Character => JavaChar, Double => JavaDouble, Float => JavaFloat, Integer => JavaInteger, Long => JavaLong, Short => JavaShort}
Review Comment:
> searched on the codebase, Spark used `import java.lang.{Boolean => JBoolean, Integer => JInteger, Long => JLong}` in other places.
but let me follow this
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1121342916
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,289 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JavaBoolean, Byte => JavaByte, Character => JavaChar, Double => JavaDouble, Float => JavaFloat, Integer => JavaInteger, Long => JavaLong, Short => JavaShort}
Review Comment:
not all
https://github.com/apache/spark/blob/d7d8af0dbb47e152b280226a7afcf0771b5a5ae8/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala#L20-L31
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125852404
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,297 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JBoolean, Byte => JByte, Character => JChar, Double => JDouble, Float => JFloat, Integer => JInteger, Long => JLong, Short => JShort}
+import java.math.{BigDecimal => JBigDecimal}
+import java.sql.{Date, Timestamp}
+import java.time._
+
+import com.google.protobuf.ByteString
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils}
+import org.apache.spark.sql.connect.client.unsupported
+import org.apache.spark.sql.types.{DayTimeIntervalType, Decimal, DecimalType, YearMonthIntervalType}
+import org.apache.spark.unsafe.types.CalendarInterval
+
+object LiteralProtoConverter {
+
+ private lazy val nullType =
+ proto.DataType.newBuilder().setNull(proto.DataType.NULL.getDefaultInstance).build()
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal.Builder`.
+ *
+ * @return
+ * proto.Expression.Literal.Builder
+ */
+ @scala.annotation.tailrec
+ def toLiteralProtoBuilder(literal: Any): proto.Expression.Literal.Builder = {
+ val builder = proto.Expression.Literal.newBuilder()
+
+ def decimalBuilder(precision: Int, scale: Int, value: String) = {
+ builder.getDecimalBuilder.setPrecision(precision).setScale(scale).setValue(value)
+ }
+
+ def calendarIntervalBuilder(months: Int, days: Int, microseconds: Long) = {
+ builder.getCalendarIntervalBuilder
+ .setMonths(months)
+ .setDays(days)
+ .setMicroseconds(microseconds)
+ }
+
+ def arrayBuilder(array: Array[_]) = {
+ val ab = builder.getArrayBuilder
+ .setElementType(componentTypeToProto(array.getClass.getComponentType))
+ array.foreach(x => ab.addElement(toLiteralProto(x)))
+ ab
+ }
+
+ literal match {
+ case v: Boolean => builder.setBoolean(v)
+ case v: Byte => builder.setByte(v)
+ case v: Short => builder.setShort(v)
+ case v: Int => builder.setInteger(v)
+ case v: Long => builder.setLong(v)
+ case v: Float => builder.setFloat(v)
+ case v: Double => builder.setDouble(v)
+ case v: BigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: JBigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: String => builder.setString(v)
+ case v: Char => builder.setString(v.toString)
+ case v: Array[Char] => builder.setString(String.valueOf(v))
+ case v: Array[Byte] => builder.setBinary(ByteString.copyFrom(v))
+ case v: collection.mutable.WrappedArray[_] => toLiteralProtoBuilder(v.array)
+ case v: LocalDate => builder.setDate(v.toEpochDay.toInt)
+ case v: Decimal =>
+ builder.setDecimal(decimalBuilder(Math.max(v.precision, v.scale), v.scale, v.toString))
+ case v: Instant => builder.setTimestamp(DateTimeUtils.instantToMicros(v))
+ case v: Timestamp => builder.setTimestamp(DateTimeUtils.fromJavaTimestamp(v))
+ case v: LocalDateTime => builder.setTimestampNtz(DateTimeUtils.localDateTimeToMicros(v))
+ case v: Date => builder.setDate(DateTimeUtils.fromJavaDate(v))
+ case v: Duration => builder.setDayTimeInterval(IntervalUtils.durationToMicros(v))
+ case v: Period => builder.setYearMonthInterval(IntervalUtils.periodToMonths(v))
+ case v: Array[_] => builder.setArray(arrayBuilder(v))
+ case v: CalendarInterval =>
+ builder.setCalendarInterval(calendarIntervalBuilder(v.months, v.days, v.microseconds))
+ case null => builder.setNull(nullType)
+ case _ => unsupported(s"literal $literal not supported (yet).")
+ }
+ }
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal`.
+ *
+ * @return
+ * proto.Expression.Literal
+ */
+ def toLiteralProto(literal: Any): proto.Expression.Literal =
+ toLiteralProtoBuilder(literal).build()
+
+ private def componentTypeToProto(clz: Class[_]): proto.DataType = clz match {
Review Comment:
Think more, let's keep this function. If we implement MapType and other types, should be code changes 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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125854357
##########
connector/connect/common/src/main/protobuf/spark/connect/expressions.proto:
##########
@@ -189,6 +190,11 @@ message Expression {
int32 days = 2;
int64 microseconds = 3;
}
+
+ message Array {
+ DataType elementType = 1;
+ repeated Literal element = 2;
Review Comment:
Thanks for your confirmation
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125340340
##########
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:
done
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on PR #40218:
URL: https://github.com/apache/spark/pull/40218#issuecomment-1454426268
Some other things to do, will update later
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125231142
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,297 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JBoolean, Byte => JByte, Character => JChar, Double => JDouble, Float => JFloat, Integer => JInteger, Long => JLong, Short => JShort}
+import java.math.{BigDecimal => JBigDecimal}
+import java.sql.{Date, Timestamp}
+import java.time._
+
+import com.google.protobuf.ByteString
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils}
+import org.apache.spark.sql.connect.client.unsupported
+import org.apache.spark.sql.types.{DayTimeIntervalType, Decimal, DecimalType, YearMonthIntervalType}
+import org.apache.spark.unsafe.types.CalendarInterval
+
+object LiteralProtoConverter {
+
+ private lazy val nullType =
+ proto.DataType.newBuilder().setNull(proto.DataType.NULL.getDefaultInstance).build()
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal.Builder`.
+ *
+ * @return
+ * proto.Expression.Literal.Builder
+ */
+ @scala.annotation.tailrec
+ def toLiteralProtoBuilder(literal: Any): proto.Expression.Literal.Builder = {
+ val builder = proto.Expression.Literal.newBuilder()
+
+ def decimalBuilder(precision: Int, scale: Int, value: String) = {
+ builder.getDecimalBuilder.setPrecision(precision).setScale(scale).setValue(value)
+ }
+
+ def calendarIntervalBuilder(months: Int, days: Int, microseconds: Long) = {
+ builder.getCalendarIntervalBuilder
+ .setMonths(months)
+ .setDays(days)
+ .setMicroseconds(microseconds)
+ }
+
+ def arrayBuilder(array: Array[_]) = {
+ val ab = builder.getArrayBuilder
+ .setElementType(componentTypeToProto(array.getClass.getComponentType))
+ array.foreach(x => ab.addElement(toLiteralProto(x)))
+ ab
+ }
+
+ literal match {
+ case v: Boolean => builder.setBoolean(v)
+ case v: Byte => builder.setByte(v)
+ case v: Short => builder.setShort(v)
+ case v: Int => builder.setInteger(v)
+ case v: Long => builder.setLong(v)
+ case v: Float => builder.setFloat(v)
+ case v: Double => builder.setDouble(v)
+ case v: BigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: JBigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: String => builder.setString(v)
+ case v: Char => builder.setString(v.toString)
+ case v: Array[Char] => builder.setString(String.valueOf(v))
+ case v: Array[Byte] => builder.setBinary(ByteString.copyFrom(v))
+ case v: collection.mutable.WrappedArray[_] => toLiteralProtoBuilder(v.array)
+ case v: LocalDate => builder.setDate(v.toEpochDay.toInt)
+ case v: Decimal =>
+ builder.setDecimal(decimalBuilder(Math.max(v.precision, v.scale), v.scale, v.toString))
+ case v: Instant => builder.setTimestamp(DateTimeUtils.instantToMicros(v))
+ case v: Timestamp => builder.setTimestamp(DateTimeUtils.fromJavaTimestamp(v))
+ case v: LocalDateTime => builder.setTimestampNtz(DateTimeUtils.localDateTimeToMicros(v))
+ case v: Date => builder.setDate(DateTimeUtils.fromJavaDate(v))
+ case v: Duration => builder.setDayTimeInterval(IntervalUtils.durationToMicros(v))
+ case v: Period => builder.setYearMonthInterval(IntervalUtils.periodToMonths(v))
+ case v: Array[_] => builder.setArray(arrayBuilder(v))
+ case v: CalendarInterval =>
+ builder.setCalendarInterval(calendarIntervalBuilder(v.months, v.days, v.microseconds))
+ case null => builder.setNull(nullType)
+ case _ => unsupported(s"literal $literal not supported (yet).")
+ }
+ }
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal`.
+ *
+ * @return
+ * proto.Expression.Literal
+ */
+ def toLiteralProto(literal: Any): proto.Expression.Literal =
+ toLiteralProtoBuilder(literal).build()
+
+ private def componentTypeToProto(clz: Class[_]): proto.DataType = clz match {
Review Comment:
Can we simplify this a bit. Please build the conversion from `Class[_] -> org.apach.spark.sql.types.DataType`. Then call the `DataTypeProtoConverter` to convert it to its proto equivalent.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] LuciferYang commented on a diff in pull request #40218: [SPARK-42579][CONNECT] Part-1: `function.lit` support `Array[_]` dataType
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #40218:
URL: https://github.com/apache/spark/pull/40218#discussion_r1125243878
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/expressions/LiteralProtoConverter.scala:
##########
@@ -0,0 +1,297 @@
+/*
+ * 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.expressions
+
+import java.lang.{Boolean => JBoolean, Byte => JByte, Character => JChar, Double => JDouble, Float => JFloat, Integer => JInteger, Long => JLong, Short => JShort}
+import java.math.{BigDecimal => JBigDecimal}
+import java.sql.{Date, Timestamp}
+import java.time._
+
+import com.google.protobuf.ByteString
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils}
+import org.apache.spark.sql.connect.client.unsupported
+import org.apache.spark.sql.types.{DayTimeIntervalType, Decimal, DecimalType, YearMonthIntervalType}
+import org.apache.spark.unsafe.types.CalendarInterval
+
+object LiteralProtoConverter {
+
+ private lazy val nullType =
+ proto.DataType.newBuilder().setNull(proto.DataType.NULL.getDefaultInstance).build()
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal.Builder`.
+ *
+ * @return
+ * proto.Expression.Literal.Builder
+ */
+ @scala.annotation.tailrec
+ def toLiteralProtoBuilder(literal: Any): proto.Expression.Literal.Builder = {
+ val builder = proto.Expression.Literal.newBuilder()
+
+ def decimalBuilder(precision: Int, scale: Int, value: String) = {
+ builder.getDecimalBuilder.setPrecision(precision).setScale(scale).setValue(value)
+ }
+
+ def calendarIntervalBuilder(months: Int, days: Int, microseconds: Long) = {
+ builder.getCalendarIntervalBuilder
+ .setMonths(months)
+ .setDays(days)
+ .setMicroseconds(microseconds)
+ }
+
+ def arrayBuilder(array: Array[_]) = {
+ val ab = builder.getArrayBuilder
+ .setElementType(componentTypeToProto(array.getClass.getComponentType))
+ array.foreach(x => ab.addElement(toLiteralProto(x)))
+ ab
+ }
+
+ literal match {
+ case v: Boolean => builder.setBoolean(v)
+ case v: Byte => builder.setByte(v)
+ case v: Short => builder.setShort(v)
+ case v: Int => builder.setInteger(v)
+ case v: Long => builder.setLong(v)
+ case v: Float => builder.setFloat(v)
+ case v: Double => builder.setDouble(v)
+ case v: BigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: JBigDecimal =>
+ builder.setDecimal(decimalBuilder(v.precision, v.scale, v.toString))
+ case v: String => builder.setString(v)
+ case v: Char => builder.setString(v.toString)
+ case v: Array[Char] => builder.setString(String.valueOf(v))
+ case v: Array[Byte] => builder.setBinary(ByteString.copyFrom(v))
+ case v: collection.mutable.WrappedArray[_] => toLiteralProtoBuilder(v.array)
+ case v: LocalDate => builder.setDate(v.toEpochDay.toInt)
+ case v: Decimal =>
+ builder.setDecimal(decimalBuilder(Math.max(v.precision, v.scale), v.scale, v.toString))
+ case v: Instant => builder.setTimestamp(DateTimeUtils.instantToMicros(v))
+ case v: Timestamp => builder.setTimestamp(DateTimeUtils.fromJavaTimestamp(v))
+ case v: LocalDateTime => builder.setTimestampNtz(DateTimeUtils.localDateTimeToMicros(v))
+ case v: Date => builder.setDate(DateTimeUtils.fromJavaDate(v))
+ case v: Duration => builder.setDayTimeInterval(IntervalUtils.durationToMicros(v))
+ case v: Period => builder.setYearMonthInterval(IntervalUtils.periodToMonths(v))
+ case v: Array[_] => builder.setArray(arrayBuilder(v))
+ case v: CalendarInterval =>
+ builder.setCalendarInterval(calendarIntervalBuilder(v.months, v.days, v.microseconds))
+ case null => builder.setNull(nullType)
+ case _ => unsupported(s"literal $literal not supported (yet).")
+ }
+ }
+
+ /**
+ * Transforms literal value to the `proto.Expression.Literal`.
+ *
+ * @return
+ * proto.Expression.Literal
+ */
+ def toLiteralProto(literal: Any): proto.Expression.Literal =
+ toLiteralProtoBuilder(literal).build()
+
+ private def componentTypeToProto(clz: Class[_]): proto.DataType = clz match {
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org