You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/12/04 22:42:25 UTC

[GitHub] [spark] amaliujia commented on a diff in pull request #38899: [SPARK-41349][CONNECT] Implement DataFrame.hint

amaliujia commented on code in PR #38899:
URL: https://github.com/apache/spark/pull/38899#discussion_r1039041717


##########
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:
   Maybe also add a test case to have a random hint name? I expect Catalyst will throw something.



##########
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:
   Nit: better replace this test name by `test proto value and catalyst value conversion`, optionally you can add the SPARK-xxxx at the beginning of the test name.



##########
python/pyspark/sql/connect/plan.py:
##########
@@ -32,6 +32,21 @@ class InputValidationError(Exception):
     pass
 
 
+def convert_value(v: Any) -> proto.Expression.Literal:

Review Comment:
   we have this: https://github.com/apache/spark/blob/master/python/pyspark/sql/connect/column.py#L178
   
   is it feasible to extract the common part and re-use?



##########
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:
   In fact there is a `private def transformLiteral(lit: proto.Expression.Literal):` that covers all literal value conversion. 
   
   Either re-use that one or merge that one with the `toCatalystValue`?



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