spark-test commented on code in PR #60546: URL: https://github.com/apache/spark/pull/60546#discussion_r4592881998
########## examples/src/main/python/pipelines/hello_world/transformations/orders.py: ########## @@ -0,0 +1,61 @@ +# +# 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. +# + +""" +Python datasets for the hello_world pipeline. + +- `customers` is a materialized view computed from a small in-line batch dataset. +- `orders` is a streaming table that incrementally ingests the JSON files in `data/orders/`. + Each run processes only the files that arrived since the previous run. +""" + +from pathlib import Path + +from pyspark import pipelines as dp +from pyspark.sql import DataFrame, SparkSession +from pyspark.sql.types import IntegerType, StringType, StructField, StructType + +# SDP also injects the session as `spark`; assigning it explicitly keeps linters happy. +spark = SparkSession.active() + +# Build the URI from the plain path rather than with `Path.as_uri()`, which percent-encodes +# spaces and non-ASCII characters that the file source does not decode. +ORDERS_DIR = f"file://{(Path(__file__).parent.parent / 'data' / 'orders').resolve()}" + +# A StructType rather than a DDL string: with Spark Connect, a string schema is parsed with a +# separate analysis request, which is not allowed inside a query function. Review Comment: **Nit (P3):** This comment states the restriction for every string schema, but it applies to `createDataFrame`, not to string schemas in general. With Spark Connect, `createDataFrame` parses a string schema with a separate `ddl_parse` analysis request (`python/pyspark/sql/connect/session.py`), which the server rejects inside a query function, while `spark.read.schema()` and `spark.readStream.schema()` store the string and send it inside the plan. That is why `orders()` below can pass a DDL string inside its query function. Readers copying the example may conclude that DDL-string schemas are off-limits in pipelines, or be left unsure why `orders()` is allowed one. Naming `createDataFrame` keeps the reason accurate: ```suggestion # A StructType rather than a DDL string: with Spark Connect, createDataFrame parses a string # schema with a separate analysis request, which is not allowed inside a query function. ``` This extends an [existing discussion](https://github.com/apache/spark/pull/60546#discussion_r4584916686). **Verification:** - **Inspection:** The comment explaining the customers view's StructType schema names createDataFrame as the call that sends a separate analysis request for a string schema, no comment in the file states that string schemas in general are parsed with such a request, and the file's code lines are unchanged. -- 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]
