spark-test commented on code in PR #60580:
URL: https://github.com/apache/spark/pull/60580#discussion_r4595098565
##########
python/pyspark/pipelines/init_cli.py:
##########
@@ -23,6 +23,10 @@
libraries:
- glob:
include: transformations/**
+configuration:
+ # Keep table metadata in a local Hive metastore (metastore_db/ in the
directory the pipeline
+ # is run from) so that tables survive across runs and can be queried after a
run.
+ spark.sql.catalogImplementation: hive
Review Comment:
**Blocking (P1):** On a Spark installation without Hive classes, this line
makes every `spark-pipelines run` and `dry-run` of a newly generated project
fail at session start, although the same project's first run works on the base
branch and in v4.3.0. Such installations include the without-hadoop release
package, which is built without the Hive profiles but still ships
`bin/spark-pipelines` (dev/create-release/release-build.sh:839-843), a pip
install with `PYSPARK_HADOOP_VERSION=without`, and any source build without
`-Phive`.
Reading the default local path: `run` hands the spec's configuration to the
session builder (cli.py:321-327), and `_start_connect_server` builds the
classic session straight from a SparkContext whose conf now carries this
setting (python/pyspark/sql/connect/session.py:1328-1330). That skips the
builder's Hive check, so users do not get the "Unable to instantiate
SparkSession with Hive support because Hive classes are not found." message
that the PR description quotes. Session state instead fails to load
`org.apache.spark.sql.hive.HiveSessionStateBuilder` and raises
`IllegalArgumentException: Error while instantiating
'org.apache.spark.sql.hive.HiveSessionStateBuilder'`
(sql/core/src/main/scala/org/apache/spark/sql/classic/SparkSession.scala:1186-1219),
which does not point at the spec.
Spark's other entry points that pick the Hive catalog on their own,
spark-shell, the pyspark shell, and SparkR, pick it only when Hive classes are
present (repl/Main.scala:113-126; python/pyspark/sql/session.py:1317-1333;
sql/core/src/main/scala/org/apache/spark/sql/api/r/SQLUtils.scala:50-67), so
they still start on these builds. init makes the same default choice for the
user and should follow the same rule.
**Recommended change:** Make `spark-pipelines init` write the
`configuration` section, with its comment and `spark.sql.catalogImplementation:
hive`, only when the Spark installation running it includes Hive, and otherwise
write the base template without that section. In the guide, qualify the Auto
CDC requirement's sentence that projects created with `spark-pipelines init`
set `spark.sql.catalogImplementation: hive`, so that it applies to Spark builds
with Hive support and says that projects generated elsewhere keep the in-memory
session catalog. Extend test_init to cover both outcomes.
**Why this works:** Add a helper beside the template that reports whether
the installation includes Hive, and have init add the `configuration` section
only when it does. The launcher already uses a test for the same installation:
with SPARK_PREPEND_CLASSES it adds the Hive module's classes only when a
`spark-hive_` jar is in the jars directory, which is `SPARK_HOME/jars` or, in a
source build, `assembly/target/scala-<version>/jars`
(AbstractCommandBuilder.java:188-189; CommandBuilderUtils.findJarsDir). The
helper can follow that rule from Python. Where exact agreement with
SparkSession.hiveClassesArePresent matters, the alternative is for the
spark-pipelines launcher, whose JVM has the classpath that later runs use, to
check that HiveSessionStateBuilder and HiveConf load and pass the result to
init. test_init stubs the helper to cover both outcomes.
**Scope:** Write the Hive catalog setting into generated specs only when the
installation running `spark-pipelines init` includes Hive, and say so in the
guide.
**Compatibility:** On installations with Hive classes, generated projects
keep this change's behavior: the same configuration section, comment, and Hive
setting, and table metadata that persists across runs.
**Risks:** init's output now depends on the installation that runs it. A
project generated on an installation without Hive and later run on one with
Hive keeps the in-memory catalog, so its second run fails with
LOCATION_ALREADY_EXISTS as on the base branch; adding the configuration section
by hand gives it the Hive setting. A project generated with Hive and run
without it still fails at session start, as every generated project does with
this change today. A jars-directory check sees only the spark-hive jar. In a
build whose Hive jars come from SPARK_DIST_CLASSPATH, it can report Hive while
HiveConf is missing, and the generated project then fails as it does with this
change today.
**Constraints:** Where Hive classes are present, init writes exactly the
template this change writes today. Where they are absent, init writes the base
branch's template, with no configuration section. `spark-pipelines run`,
hand-written specs, and projects generated earlier keep their current behavior.
**Exclusions:**
- A fallback in `spark-pipelines run` for a spec that sets the Hive catalog
on an installation without Hive classes is out of scope; such a spec keeps
failing at session start, as an explicit setting does today.
- Rewording the guide's Target Format instructions for the generated
configuration mapping belongs to the repair for that passage.
**Success:** On an installation without Hive classes, `spark-pipelines init`
writes a spec with no `configuration` section, and the first `spark-pipelines
run` of the generated project completes, as on the base branch. On an
installation with Hive classes, init writes the same `configuration` section,
comment, and `spark.sql.catalogImplementation: hive` that this change writes
today. The guide's sentence about the catalog setting of projects created with
`spark-pipelines init` applies to Spark builds with Hive support and says which
catalog projects generated elsewhere use. test_init covers both outcomes of the
Hive check.
**Verification:**
- **Behavior:** With the Hive check stubbed to report no Hive, test_init
finds an empty configuration in the generated spec, and with it stubbed to
report Hive, it finds exactly `{"spark.sql.catalogImplementation": "hive"}`.
- **Behavior:** On a build without -Phive, `spark-pipelines init` followed
by `spark-pipelines run` in the new project completes and materializes both
example views.
- **Regression:** On the Hive-enabled PySpark test build, test_init without
the stub still finds the Hive setting, which shows the check detects Hive where
it is present.
- **Compatibility:** If the check reads the jars directory rather than
loading the classes, it agrees with `SparkSession.hiveClassesArePresent` on a
binary distribution, a pip install, and source builds with and without -Phive.
##########
python/pyspark/pipelines/tests/test_init_cli.py:
##########
@@ -50,6 +50,7 @@ def test_init(self):
spec_path = find_pipeline_spec(Path.cwd())
spec = load_pipeline_spec(spec_path)
assert spec.name == project_name
+ self.assertEqual(spec.configuration,
{"spark.sql.catalogImplementation": "hive"})
Review Comment:
**Non-blocking (P2):** This assertion checks only the parsed template, and
nothing else in the suite runs a generated project. test_init registers the
example definitions on the shared test session (lines 62-63), and
EndToEndAPISuite runs the CLI against an already started server with its own
spec (EndToEndAPISuite.scala:153-179), so neither applies the setting at
session start or carries tables into a later run.
The current head shows what slips through. Without the companion
apache/spark#60579, every flow of a generated project fails with
`CANNOT_MODIFY_STATIC_CONFIG`: the spec's configuration is merged into every
flow (GraphRegistrationContext.scala:62) and applied through
`RuntimeConfig.set`, which rejects static keys (FlowExecution.scala:218, 265;
sql/core/src/main/scala/org/apache/spark/sql/classic/RuntimeConfig.scala:41-42,
125-138). No existing test exercises that path, so the suites stay green. A
test that generates a project and runs `spark-pipelines run` twice from its
directory in separate processes on a Hive-enabled build, in the style of the
`spark-submit` subprocess tests in python/pyspark/tests/test_appsubmit.py,
would catch this and any regression in metadata persisting across runs.
**Verification:**
- **Behavior:** On a Hive-enabled build with the companion change present,
the new test passes. Both runs of the generated project complete, and the
second run updates the tables the first run created.
- **Regression:** With the `configuration` section removed from the
generated spec, the new test fails on the second run with
LOCATION_ALREADY_EXISTS. This shows it observes metadata persisting across
processes rather than only the template text.
- **Regression:** On a head without the companion change, the new test fails
because the first run's materialized views fail with
CANNOT_MODIFY_STATIC_CONFIG. This is the failure the current suites miss.
##########
python/pyspark/pipelines/init_cli.py:
##########
@@ -23,6 +23,10 @@
libraries:
- glob:
include: transformations/**
+configuration:
Review Comment:
**Nit (P3):** This new top-level `configuration:` mapping conflicts with the
guide's 'Choosing a Target Format' instructions
(docs/declarative-pipelines-programming-guide.md:686-692), which the Auto CDC
example sends readers to right after `spark-pipelines init`. That passage still
tells readers to add its own top-level `configuration:` block, and it names
only `name`, `storage`, and `libraries` as what init wrote.
`load_pipeline_spec` parses the file with `yaml.safe_load` (cli.py:151-154),
which keeps only the last of duplicate keys, so one setting disappears without
an error. If the snippet is appended, the generated
`spark.sql.catalogImplementation: hive` is dropped, and any session-catalog
tables are again lost when the run ends. If it is placed above,
`spark.sql.catalog.lakehouse` is dropped, and `catalog: lakehouse` fails to
resolve although the key is in the file. The passage should have readers add
the connector key inside the existing `configuration` mapping, or create the
mapping when there is none, and it should list `configuration` among the keys
init wrote.
**Verification:**
- **Inspection:** Apply the passage's instructions to a spec generated with
the Hive `configuration` mapping and to one generated without it, and parse
each result the way `spark-pipelines` loads specs. Each must hold the connector
catalog key, the first must also keep the generated catalog setting, and no
top-level key may appear twice.
--
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]