You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "hvanhovell (via GitHub)" <gi...@apache.org> on 2023/02/07 23:33:04 UTC

[GitHub] [spark] hvanhovell opened a new pull request, #39933: [SPARK-42377][Connect] Test framework for Spark Connect Scala Client

hvanhovell opened a new pull request, #39933:
URL: https://github.com/apache/spark/pull/39933

   ### What changes were proposed in this pull request?
   This PR adds a test framework for the Spark Connect Scala Client.
   
   This framework consists of two tests:
   
   - `PlanGenerationTestSuite`: This is the client side testing. Tests in this suite generate queries (relations), and compare the generated query plan to a golden file. In order to facilitate debugging and review the json of the proto file is also generated when the golden file is generated. The goal of this test is to validate whether the generated plan matches expectations, and to catch changes in the generated queries. **This is the only test suite where tests need to be added.**
   - `ProtoToParsedPlanTestSuite`: This is server side testing. This test uses the protos generated by the `PlanGenerationTestSuite` and tries to convert them to a catalyst parsed plan (unresolved `LogicaPlan`). The string representation of the generated parsed plan is compared to a golden file.
   
   When adding tests using this framework, both the `PlanGenerationTestSuite` and `ProtoToParsedPlanTestSuite` need to be run, and in this order.
   
   ### Why are the changes needed?
   This makes it easier to test new features for the scala client.
   
   ### Does this PR introduce _any_ user-facing change?
   No.
   
   ### How was this patch tested?
   It is a test framework. I have added tests for most existing features.
   


-- 
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 #39933: [SPARK-42377][Connect] Test framework for Spark Connect Scala Client

Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on PR #39933:
URL: https://github.com/apache/spark/pull/39933#issuecomment-1421640160

   cc @zhenlineo @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] hvanhovell commented on pull request #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on PR #39933:
URL: https://github.com/apache/spark/pull/39933#issuecomment-1423312392

   @LuciferYang can you check if maven works now? It should. There is an outstanding issue with one of the UDF tests, but that is for a different PR.


-- 
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 #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on PR #39933:
URL: https://github.com/apache/spark/pull/39933#issuecomment-1424341409

   ```
   The scalafmt check failed on connector/connect at following occurrences:
   
   Requires formatting: ProtoToParsedPlanTestSuite.scala
   
   Before submitting your change, please make sure to format your code using the following command:
   ./build/mvn -Pscala-2.12 scalafmt:format -Dscalafmt.skip=false -Dscalafmt.validateOnly=false -Dscalafmt.changedOnly=false -pl connector/connect/common -pl connector/connect/server -pl connector/connect/client/jvm
   ```


-- 
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] HyukjinKwon commented on a diff in pull request #39933: [SPARK-42377][Connect] Test framework for Spark Connect Scala Client

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #39933:
URL: https://github.com/apache/spark/pull/39933#discussion_r1099484394


##########
connector/connect/common/src/test/resources/query-tests/queries/function_lit.proto:
##########
@@ -0,0 +1,24 @@
+�

Review Comment:
   hmmm .. qq: isn't this enough if we just compare JSON?



-- 
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 #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #39933:
URL: https://github.com/apache/spark/pull/39933#discussion_r1100126601


##########
connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/PlanGenerationTestSuite.scala:
##########
@@ -0,0 +1,247 @@
+/*
+ * 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
+
+import java.nio.file.{Files, Path}
+
+import scala.collection.mutable
+import scala.util.{Failure, Success, Try}
+
+import com.google.protobuf.util.JsonFormat
+import io.grpc.inprocess.InProcessChannelBuilder
+import org.scalatest.BeforeAndAfterAll
+import org.scalatest.funsuite.{AnyFunSuite => ConnectFunSuite} // scalastyle:ignore funsuite
+
+import org.apache.spark.connect.proto
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.{functions => fn}
+import org.apache.spark.sql.connect.client.SparkConnectClient
+import org.apache.spark.sql.types.StructType
+
+// scalastyle:off
+/**
+ * Test the plans generated by the client. This serves two purposes:
+ * 1. Make sure the generated plan matches our expectations.
+ *    The generated JSON file can be used for this during review.
+ * 2. Make sure the generated plans are stable. Changes to the generated plans should be rare. The
+ *    generated plan is compared to the (previously) generated proto file; the test fails when
+ *    they are different.
+ *
+ * If you need to re-generate the golden files, you need to set the SPARK_GENERATE_GOLDEN_FILES=1
+ * environment variable before running this test, e.g.:
+ * {{{
+ *   SPARK_GENERATE_GOLDEN_FILES=1 build/sbt "connect-client-jvm/testOnly org.apache.spark.sql.PlanGenerationTestSuite"
+ * }}}
+ *
+ * Note that the plan protos are used as the input for the `ProtoToParsedPlanTestSuite` in the
+ * `connector/connect/server` module
+ */
+// scalastyle:on
+class PlanGenerationTestSuite extends ConnectFunSuite with BeforeAndAfterAll with Logging {

Review Comment:
   I haven't quite understood why we should keep the same package name for the same name class in `client` and `sql/core`. What are the main benefits?
   
   



-- 
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 #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #39933:
URL: https://github.com/apache/spark/pull/39933#discussion_r1099573713


##########
connector/connect/client/jvm/pom.xml:
##########
@@ -83,6 +83,19 @@
         </exclusion>
       </exclusions>
     </dependency>
+    <dependency>

Review Comment:
   OK, I see the `TestUDFs`, please ignore above question



-- 
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 #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #39933:
URL: https://github.com/apache/spark/pull/39933#discussion_r1099573713


##########
connector/connect/client/jvm/pom.xml:
##########
@@ -83,6 +83,19 @@
         </exclusion>
       </exclusions>
     </dependency>
+    <dependency>

Review Comment:
   OK, I see the `TestUDFs`



-- 
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 #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #39933:
URL: https://github.com/apache/spark/pull/39933#discussion_r1099571513


##########
connector/connect/client/jvm/pom.xml:
##########
@@ -83,6 +83,19 @@
         </exclusion>
       </exclusions>
     </dependency>
+    <dependency>

Review Comment:
   hmm.. `spark-connect-common_2.12-3.5.0-SNAPSHOT-tests.jar ` is empty jar. why need add this  dependency?



-- 
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 #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell closed pull request #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client
URL: https://github.com/apache/spark/pull/39933


-- 
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] dongjoon-hyun commented on a diff in pull request #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #39933:
URL: https://github.com/apache/spark/pull/39933#discussion_r1103885778


##########
connector/connect/common/src/test/resources/query-tests/queries/function_udf.json:
##########
@@ -0,0 +1,96 @@
+{
+  "project": {
+    "input": {
+      "localRelation": {
+        "schema": "struct\u003cid:bigint,a:int,b:double\u003e"
+      }
+    },
+    "expressions": [{
+      "commonInlineUserDefinedFunction": {
+        "scalarScalaUdf": {
+          "payload": "rO0ABXNyAC1vcmcuYXBhY2hlLnNwYXJrLnNxbC5jb25uZWN0LmNvbW1vbi5VZGZQYWNrZXR7DRDpFmMz1QIAA0wACGZ1bmN0aW9udAASTGphdmEvbGFuZy9PYmplY3Q7TAANaW5wdXRFbmNvZGVyc3QAFkxzY2FsYS9jb2xsZWN0aW9uL1NlcTtMAA1vdXRwdXRFbmNvZGVydAA4TG9yZy9hcGFjaGUvc3Bhcmsvc3FsL2NhdGFseXN0L2VuY29kZXJzL0Fnbm9zdGljRW5jb2Rlcjt4cHNyACVvcmcuYXBhY2hlLnNwYXJrLnNxbC5UZXN0VURGcyQkYW5vbiQxBwIoVHJpGRUCAAB4cHNyACRzY2FsYS5jb2xsZWN0aW9uLm11dGFibGUuQXJyYXlCdWZmZXIVOLBTg4KOcwIAA0kAC2luaXRpYWxTaXplSQAFc2l6ZTBbAAVhcnJheXQAE1tMamF2YS9sYW5nL09iamVjdDt4cAAAABAAAAAAdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAAEHBwcHBwcHBwcHBwcHBwcHBzcgBPb3JnLmFwYWNoZS5zcGFyay5zcWwuY2F0YWx5c3QuZW5jb2RlcnMuQWdub3N0aWNFbmNvZGVycyRQcmltaXRpdmVEb3VibGVFbmNvZGVyJD0ieXjPZF2NAgAAeHIATG9yZy5hcGFjaGUuc3Bhcmsuc3FsLmNhdGFseXN0LmVuY29kZXJzLkFnbm9zdGljRW5jb2RlcnMkUHJpbWl0aXZlTGVhZkVuY29kZXLf4z0LufMQmwIAAHhyAENvcmcuYXBhY2hlLnNwYXJrLnNxbC5jYXRhbHlzdC5lbmNvZGVycy5BZ25vc3RpY0VuY29kZXJzJExlYWZFbmNvZGVyKtoOee2SqKMCAANaAAtpc1ByaW1pdGl2ZUwABmNsc1RhZ3QAGEx
 zY2FsYS9yZWZsZWN0L0NsYXNzVGFnO0wACGRhdGFUeXBldAAlTG9yZy9hcGFjaGUvc3Bhcmsvc3FsL3R5cGVzL0RhdGFUeXBlO3hwAXNyACxzY2FsYS5yZWZsZWN0Lk1hbmlmZXN0RmFjdG9yeSREb3VibGVNYW5pZmVzdAAAAAAAAAABAgAAeHIAHHNjYWxhLnJlZmxlY3QuQW55VmFsTWFuaWZlc3QAAAAAAAAAAQIAAUwACHRvU3RyaW5ndAASTGphdmEvbGFuZy9TdHJpbmc7eHB0AAZEb3VibGVzcgAmb3JnLmFwYWNoZS5zcGFyay5zcWwudHlwZXMuRG91YmxlVHlwZSTzweZ5PUtZ9gIAAHhw"

Review Comment:
   We need to have both Scala 2.12 and 2.13.



-- 
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] dongjoon-hyun commented on a diff in pull request #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #39933:
URL: https://github.com/apache/spark/pull/39933#discussion_r1103878136


##########
connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/PlanGenerationTestSuite.scala:
##########
@@ -0,0 +1,252 @@
+/*
+ * 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
+
+import java.nio.file.{Files, Path}
+
+import scala.collection.mutable
+import scala.util.{Failure, Success, Try}
+
+import com.google.protobuf.util.JsonFormat
+import io.grpc.inprocess.InProcessChannelBuilder
+import org.scalatest.BeforeAndAfterAll
+import org.scalatest.funsuite.{AnyFunSuite => ConnectFunSuite} // scalastyle:ignore funsuite
+
+import org.apache.spark.connect.proto
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.{functions => fn}
+import org.apache.spark.sql.connect.client.SparkConnectClient
+import org.apache.spark.sql.types.StructType
+
+// scalastyle:off
+/**
+ * Test the plans generated by the client. This serves two purposes:
+ *
+ *   1. Make sure the generated plan matches our expectations. The generated JSON file can be used
+ *      for this during review.
+ *   1. Make sure the generated plans are stable. Changes to the generated plans should be rare.
+ *      The generated plan is compared to the (previously) generated proto file; the test fails
+ *      when they are different.
+ *
+ * If you need to re-generate the golden files, you need to set the SPARK_GENERATE_GOLDEN_FILES=1
+ * environment variable before running this test, e.g.:
+ * {{{
+ *   SPARK_GENERATE_GOLDEN_FILES=1 build/sbt "connect-client-jvm/testOnly org.apache.spark.sql.PlanGenerationTestSuite"
+ * }}}
+ *
+ * Note that the plan protos are used as the input for the `ProtoToParsedPlanTestSuite` in the
+ * `connector/connect/server` module
+ */
+// scalastyle:on
+class PlanGenerationTestSuite extends ConnectFunSuite with BeforeAndAfterAll with Logging {
+
+  // Borrowed from SparkFunSuite
+  private val regenerateGoldenFiles: Boolean = System.getenv("SPARK_GENERATE_GOLDEN_FILES") == "1"
+
+  // Borrowed from SparkFunSuite
+  private def getWorkspaceFilePath(first: String, more: String*): Path = {
+    if (!(sys.props.contains("spark.test.home") || sys.env.contains("SPARK_HOME"))) {
+      fail("spark.test.home or SPARK_HOME is not set.")
+    }
+    val sparkHome = sys.props.getOrElse("spark.test.home", sys.env("SPARK_HOME"))
+    java.nio.file.Paths.get(sparkHome, first +: more: _*)
+  }
+
+  protected val baseResourcePath: Path = {
+    getWorkspaceFilePath(
+      "connector",
+      "connect",
+      "common",
+      "src",
+      "test",
+      "resources",
+      "query-tests").toAbsolutePath
+  }
+
+  protected val queryFilePath: Path = baseResourcePath.resolve("queries")
+
+  private val printer = JsonFormat.printer()
+
+  private var session: SparkSession = _
+
+  override protected def beforeAll(): Unit = {
+    super.beforeAll()
+    val client = new SparkConnectClient(
+      proto.UserContext.newBuilder().build(),
+      InProcessChannelBuilder.forName("/dev/null").build())
+    val builder = SparkSession.builder().client(client)
+    session = builder.build()
+  }
+
+  override protected def afterAll(): Unit = {
+    session.close()
+    super.afterAll()
+  }
+
+  private def test(name: String)(f: => Dataset[_]): Unit = super.test(name) {
+    val actual = f.plan.getRoot
+    val goldenFile = queryFilePath.resolve(name.replace(' ', '_') + ".proto.bin")
+    Try(readRelation(goldenFile)) match {
+      case Success(expected) if expected == actual =>
+      // Ok!
+      case Success(_) if regenerateGoldenFiles =>
+        logInfo("Rewriting Golden File")
+        writeGoldenFile(goldenFile, actual)
+      case Success(expected) =>
+        fail(s"""
+             |Expected and actual plans do not match:
+             |
+             |=== Expected Plan ===
+             |$expected
+             |
+             |=== Actual Plan ===
+             |$actual
+             |""".stripMargin)
+      case Failure(_) if regenerateGoldenFiles =>
+        logInfo("Writing Golden File")
+        writeGoldenFile(goldenFile, actual)
+      case Failure(_) =>
+        fail(
+          "No golden file found. Please re-run this test with the " +
+            "SPARK_GENERATE_GOLDEN_FILES=1 environment variable set")
+    }
+  }
+
+  private def readRelation(path: Path): proto.Relation = {
+    val input = Files.newInputStream(path)
+    try proto.Relation.parseFrom(input)
+    finally {
+      input.close()
+    }
+  }
+
+  private def writeGoldenFile(path: Path, relation: proto.Relation): Unit = {
+    val output = Files.newOutputStream(path)
+    try relation.writeTo(output)
+    finally {
+      output.close()
+    }
+    // Write the json file for verification.
+    val jsonPath =
+      path.getParent.resolve(path.getFileName.toString.stripSuffix(".proto.bin") + ".json")
+    val writer = Files.newBufferedWriter(jsonPath)
+    try writer.write(printer.print(relation))
+    finally {
+      writer.close()
+    }
+  }
+
+  private val simpleSchema = new StructType()
+    .add("id", "long")
+    .add("a", "int")
+    .add("b", "double")
+
+  private val simpleSchemaString = simpleSchema.catalogString
+
+  // We manually construct a simple empty data frame.
+  private def simple = session.newDataset { builder =>
+    // TODO API is not consistent. Now we have two different ways of working with schemas!
+    builder.getLocalRelationBuilder.setSchema(simpleSchemaString)
+  }
+
+  private def select(cs: Column*): DataFrame = simple.select(cs: _*)
+
+  /* Spark Session API */
+  test("sql") {
+    session.sql("select 1")
+  }
+
+  test("range") {
+    session.range(1, 10, 1, 2)
+  }
+
+  /* Dataset API */
+  test("select") {
+    simple.select(fn.col("id"))
+  }
+
+  test("limit") {
+    simple.limit(10)
+  }
+
+  test("filter") {
+    simple.filter(fn.col("id") === fn.lit(10L))
+  }
+
+  /* Column API */
+  test("column by name") {
+    select(fn.col("b"))
+  }
+
+  test("column add") {
+    select(fn.col("a") + fn.col("b"))
+  }
+
+  test("column alias") {
+    select(fn.col("a").name("b"))
+  }
+
+  test("column equals") {
+    select(fn.col("a") === fn.col("b"))
+  }
+
+  /* Function API */
+  test("function col") {
+    select(fn.col("id"))
+  }
+
+  test("function udf") {
+    // This test might be a bit tricky if different JVM
+    // versions are used to generate the golden files.

Review Comment:
   As mentioned here. Not only JVM, but also Scala seems to be affected.



-- 
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 #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on PR #39933:
URL: https://github.com/apache/spark/pull/39933#issuecomment-1423533123

   <img width="928" alt="image" src="https://user-images.githubusercontent.com/1475305/217703128-b0cb8d3e-a103-4595-80b1-db3e4a9da72a.png">
   
   license test failed,  need add new rule to `.rat-excludes`?


-- 
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] HyukjinKwon commented on a diff in pull request #39933: [SPARK-42377][Connect] Test framework for Spark Connect Scala Client

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #39933:
URL: https://github.com/apache/spark/pull/39933#discussion_r1099483089


##########
connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/PlanGenerationTestSuite.scala:
##########
@@ -0,0 +1,247 @@
+/*
+ * 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
+
+import java.nio.file.{Files, Path}
+
+import scala.collection.mutable
+import scala.util.{Failure, Success, Try}
+
+import com.google.protobuf.util.JsonFormat
+import io.grpc.inprocess.InProcessChannelBuilder
+import org.scalatest.BeforeAndAfterAll
+import org.scalatest.funsuite.{AnyFunSuite => ConnectFunSuite} // scalastyle:ignore funsuite
+
+import org.apache.spark.connect.proto
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.{functions => fn}
+import org.apache.spark.sql.connect.client.SparkConnectClient
+import org.apache.spark.sql.types.StructType
+
+// scalastyle:off
+/**
+ * Test the plans generated by the client. This serves two purposes:
+ * 1. Make sure the generated plan matches our expectations.
+ *    The generated JSON file can be used for this during review.
+ * 2. Make sure the generated plans are stable. Changes to the generated plans should be rare. The
+ *    generated plan is compared to the (previously) generated proto file; the test fails when
+ *    they are different.
+ *
+ * If you need to re-generate the golden files, you need to set the SPARK_GENERATE_GOLDEN_FILES=1
+ * environment variable before running this test, e.g.:
+ * {{{
+ *   SPARK_GENERATE_GOLDEN_FILES=1 build/sbt "connect-client-jvm/testOnly org.apache.spark.sql.PlanGenerationTestSuite"
+ * }}}
+ *
+ * Note that the plan protos are used as the input for the `ProtoToParsedPlanTestSuite` in the
+ * `connector/connect/server` module
+ */
+// scalastyle:on
+class PlanGenerationTestSuite extends ConnectFunSuite with BeforeAndAfterAll with Logging {

Review Comment:
   Can be done in a followup but I believe we can reuse some codes in `PlanStabilitySuite` cc @cloud-fan and @Ngone51 FYI



-- 
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 #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on PR #39933:
URL: https://github.com/apache/spark/pull/39933#issuecomment-1423286123

   Alright the golden files for the `ProtoToParsedPlanTestSuite` have been updated.


-- 
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 #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on PR #39933:
URL: https://github.com/apache/spark/pull/39933#issuecomment-1421967697

   ```
   2023-02-08T03:35:47.3912913Z [info] ProtoToParsedPlanTestSuite:
   2023-02-08T03:35:47.5369994Z [info] - column_add *** FAILED *** (21 milliseconds)
   2023-02-08T03:35:47.5421797Z [info]   Expected and actual plans do not match:
   2023-02-08T03:35:47.5426918Z [info]   
   2023-02-08T03:35:47.5432762Z [info]   === Expected Plan ===
   2023-02-08T03:35:47.5438375Z [info]   'Project [unresolvedalias('`+`('a, 'b), None)]
   2023-02-08T03:35:47.5443691Z [info]   +- LocalRelation <empty>, [id#52L, a#53, b#54]
   2023-02-08T03:35:47.5447975Z [info]   
   2023-02-08T03:35:47.5452161Z [info]   
   2023-02-08T03:35:47.5456865Z [info]   === Actual Plan ===
   2023-02-08T03:35:47.5461689Z [info]   'Project [unresolvedalias('`+`('a, 'b), None)]
   2023-02-08T03:35:47.5467307Z [info]   +- LocalRelation <empty>, [id#1845L, a#1846, b#1847] (ProtoToParsedPlanTestSuite.scala:93)
   ```
   The new test failed


-- 
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 #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on PR #39933:
URL: https://github.com/apache/spark/pull/39933#issuecomment-1421968703

   And I local maven test `PlanGenerationTestSuite`  will fail too
   
    


-- 
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 #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #39933:
URL: https://github.com/apache/spark/pull/39933#discussion_r1099486517


##########
connector/connect/common/src/test/resources/query-tests/queries/function_lit.proto:
##########
@@ -0,0 +1,24 @@
+�

Review Comment:
   I would not do that for a couple of reasons:
   
   -  The interface is using proto and not json, so I strongly believe we should test that instead of a derivative. Please note that the protos are used as an input for the other test.
   - Json rendering can be less exact than we want.
   - Comparing the proto's is significantly easier.



-- 
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] dongjoon-hyun commented on pull request #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on PR #39933:
URL: https://github.com/apache/spark/pull/39933#issuecomment-1427164895

   Here is the PR.
   - https://github.com/apache/spark/pull/39982


-- 
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 #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #39933:
URL: https://github.com/apache/spark/pull/39933#discussion_r1099487256


##########
connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/PlanGenerationTestSuite.scala:
##########
@@ -0,0 +1,247 @@
+/*
+ * 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
+
+import java.nio.file.{Files, Path}
+
+import scala.collection.mutable
+import scala.util.{Failure, Success, Try}
+
+import com.google.protobuf.util.JsonFormat
+import io.grpc.inprocess.InProcessChannelBuilder
+import org.scalatest.BeforeAndAfterAll
+import org.scalatest.funsuite.{AnyFunSuite => ConnectFunSuite} // scalastyle:ignore funsuite
+
+import org.apache.spark.connect.proto
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.{functions => fn}
+import org.apache.spark.sql.connect.client.SparkConnectClient
+import org.apache.spark.sql.types.StructType
+
+// scalastyle:off
+/**
+ * Test the plans generated by the client. This serves two purposes:
+ * 1. Make sure the generated plan matches our expectations.
+ *    The generated JSON file can be used for this during review.
+ * 2. Make sure the generated plans are stable. Changes to the generated plans should be rare. The
+ *    generated plan is compared to the (previously) generated proto file; the test fails when
+ *    they are different.
+ *
+ * If you need to re-generate the golden files, you need to set the SPARK_GENERATE_GOLDEN_FILES=1
+ * environment variable before running this test, e.g.:
+ * {{{
+ *   SPARK_GENERATE_GOLDEN_FILES=1 build/sbt "connect-client-jvm/testOnly org.apache.spark.sql.PlanGenerationTestSuite"
+ * }}}
+ *
+ * Note that the plan protos are used as the input for the `ProtoToParsedPlanTestSuite` in the
+ * `connector/connect/server` module
+ */
+// scalastyle:on
+class PlanGenerationTestSuite extends ConnectFunSuite with BeforeAndAfterAll with Logging {

Review Comment:
   The client can't depend on things in sql/core. From a cursory look there is actually not a lot of reuse. I am happy to try in a follow-up.



-- 
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 #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #39933:
URL: https://github.com/apache/spark/pull/39933#discussion_r1099575970


##########
connector/connect/common/src/test/scala/org/apache/spark/sql/TestUDFs.scala:
##########
@@ -0,0 +1,43 @@
+/*
+ * 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
+
+/**
+ * A bunch of functions use for testing udf serialization.
+ */
+object TestUDFs {
+  type L = Long
+  val udf0: () => Double = new Function0[Double] with Serializable {

Review Comment:
   How about 
   
   ```
   val udf0: () => Double = () => Math.random()
   val udf1: L => Tuple1[L] = (i0: L) => Tuple1(i0)
   ....
   ```



-- 
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 #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on PR #39933:
URL: https://github.com/apache/spark/pull/39933#issuecomment-1423528903

   @hvanhovell checked, local maven test passed


-- 
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 #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on PR #39933:
URL: https://github.com/apache/spark/pull/39933#issuecomment-1426939831

   Merging this one.


-- 
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] dongjoon-hyun commented on pull request #39933: [SPARK-42377][CONNECT][TESTS] Test framework for Spark Connect Scala Client

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on PR #39933:
URL: https://github.com/apache/spark/pull/39933#issuecomment-1427160504

   I filed SPARK-42410 and will make a PR soon.


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