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/10/14 20:42:38 UTC

[GitHub] [spark] grundprinzip commented on a diff in pull request #38253: [SPARK-40796][CONNECT][BUILD][WIP] Check the generated python protos in GitHub Actions

grundprinzip commented on code in PR #38253:
URL: https://github.com/apache/spark/pull/38253#discussion_r996130535


##########
dev/check-codegen-python.py:
##########
@@ -0,0 +1,81 @@
+#!/usr/bin/env python3
+
+#
+# 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.
+#
+
+# Utility for checking whether generated codes in PySpark are out of sync.
+#   usage: ./dev/check-codegen-python.py
+
+import os
+import sys
+import filecmp
+import tempfile
+import subprocess
+
+# Location of your Spark git development area
+SPARK_HOME = os.environ.get("SPARK_HOME", os.getcwd())
+
+
+def fail(msg):
+    print(msg)
+    sys.exit(-1)
+
+
+def run_cmd(cmd):
+    print(f"RUN: {cmd}")
+    if isinstance(cmd, list):
+        return subprocess.check_output(cmd).decode("utf-8")
+    else:
+        return subprocess.check_output(cmd.split(" ")).decode("utf-8")
+
+
+def check_connect_protos():
+    print("Start checking the generated codes in pyspark-connect")
+    with tempfile.TemporaryDirectory() as tmp:
+        run_cmd(f"{SPARK_HOME}/connector/connect/dev/generate_protos.sh {tmp}")
+        result = filecmp.dircmp(f"{SPARK_HOME}/python/pyspark/sql/connect/proto/", tmp)
+        failed = False
+
+        if result.left_only != ["__init__.py"]:
+            files = [file for file in result.left_only if file != "__init__.py"]
+            print(f"Unexpected files: {files}")
+            failed = True
+
+        if len(result.right_only) > 0:
+            print(f"Missing files: {result.right_only}")
+            failed = True
+
+        if len(result.funny_files) > 0:
+            print(f"Incomparable files: {result.funny_files}")
+            failed = True
+
+        if len(result.diff_files) > 0:
+            print(f"Different files: {result.diff_files}")
+            failed = True
+
+        if not failed:
+            print("Finish checking the generated codes in pyspark-connect: SUCCESS")
+        else:
+            fail(
+                "Generated codes for pyspark-connect are out of sync! "
+                "Please run ./connector/connect/dev/generate_protos.sh"
+            )
+
+
+check_connect_protos()
+
+# TODO: also check generated codes in pyspark-ml and pyspark-mllib

Review Comment:
   ```suggestion
   # TODO: also check generated code in pyspark-ml and pyspark-mllib.
   ```



##########
python/pyspark/sql/connect/plan.py:
##########
@@ -322,11 +322,15 @@ def _convert_measure(
     ) -> proto.Aggregate.AggregateFunction:
         exp, fun = m
         measure = proto.Aggregate.AggregateFunction()
-        measure.function.name = fun
+        measure.function.name = fun  # type: ignore[attr-defined]

Review Comment:
   Why do these show up as required now, even though we had mypy checks activated before>



##########
dev/check-codegen-python.py:
##########
@@ -0,0 +1,81 @@
+#!/usr/bin/env python3
+
+#
+# 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.
+#
+
+# Utility for checking whether generated codes in PySpark are out of sync.
+#   usage: ./dev/check-codegen-python.py
+
+import os
+import sys
+import filecmp
+import tempfile
+import subprocess
+
+# Location of your Spark git development area
+SPARK_HOME = os.environ.get("SPARK_HOME", os.getcwd())
+
+
+def fail(msg):
+    print(msg)
+    sys.exit(-1)
+
+
+def run_cmd(cmd):
+    print(f"RUN: {cmd}")
+    if isinstance(cmd, list):
+        return subprocess.check_output(cmd).decode("utf-8")
+    else:
+        return subprocess.check_output(cmd.split(" ")).decode("utf-8")
+
+
+def check_connect_protos():
+    print("Start checking the generated codes in pyspark-connect")

Review Comment:
   ```suggestion
       print("Start checking the generated codes in pyspark-connect.")
   ```



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