dengziming commented on code in PR #38899: URL: https://github.com/apache/spark/pull/38899#discussion_r1039377343
########## connector/connect/src/test/scala/org/apache/spark/sql/connect/planner/LiteralValueProtoConverterSuite.scala: ########## @@ -0,0 +1,35 @@ +/* + * 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.connect.planner + +import org.scalatest.funsuite.AnyFunSuite + +import org.apache.spark.sql.connect.planner.LiteralValueProtoConverter.{toCatalystValue, toConnectProtoValue} + + +class LiteralValueProtoConverterSuite extends AnyFunSuite { + + test("Round-trip") { Review Comment: Good suggestions. ########## connector/connect/src/test/scala/org/apache/spark/sql/connect/planner/SparkConnectPlannerSuite.scala: ########## @@ -571,4 +572,28 @@ class SparkConnectPlannerSuite extends SparkFunSuite with SparkConnectPlanTest { Dataset.ofRows(spark, transform(proto.Relation.newBuilder.setProject(project).build())) assert(df.schema.fields.toSeq.map(_.name) == Seq("id")) } + + test("Test Hint") { Review Comment: I added a illegal hint name, it seems that spark will ignore it. ########## connector/connect/src/main/scala/org/apache/spark/sql/connect/planner/SparkConnectPlanner.scala: ########## @@ -233,19 +235,9 @@ class SparkConnectPlanner(session: SparkSession) { } private def transformReplace(rel: proto.NAReplace): LogicalPlan = { - def convert(value: proto.Expression.Literal): Any = { - value.getLiteralTypeCase match { - case proto.Expression.Literal.LiteralTypeCase.NULL => null - case proto.Expression.Literal.LiteralTypeCase.BOOLEAN => value.getBoolean - case proto.Expression.Literal.LiteralTypeCase.DOUBLE => value.getDouble - case proto.Expression.Literal.LiteralTypeCase.STRING => value.getString - case other => throw InvalidPlanInput(s"Unsupported value type: $other") - } - } - val replacement = mutable.Map.empty[Any, Any] rel.getReplacementsList.asScala.foreach { replace => - replacement.update(convert(replace.getOldValue), convert(replace.getNewValue)) + replacement.update(toCatalystValue(replace.getOldValue), toCatalystValue(replace.getNewValue)) Review Comment: I moved the method `transformLiteral` to a util object to reuse its code. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
