-
Notifications
You must be signed in to change notification settings - Fork 29.2k
[SPARK-56853] Improve PATH Tests #55866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
srielau
wants to merge
3
commits into
apache:master
Choose a base branch
from
srielau:SPARK-56853-path-qa-gaps
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SqlPathFormatSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| * 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.catalyst.catalog | ||
|
|
||
| import org.json4s.JsonAST.{JArray, JObject, JString} | ||
| import org.json4s.jackson.JsonMethods.{compact, render} | ||
|
|
||
| import org.apache.spark.SparkFunSuite | ||
|
|
||
| /** | ||
| * Unit tests for [[SqlPathFormat]] -- the helper that converts the raw JSON-array-of-arrays | ||
| * path stored on view / SQL function metadata into the JSON-object form used by DESCRIBE | ||
| * AS JSON and the human-readable form used by DESCRIBE EXTENDED. | ||
| */ | ||
| class SqlPathFormatSuite extends SparkFunSuite { | ||
|
|
||
| private def compactJson(v: JArray): String = compact(render(v)) | ||
|
|
||
| test("toDescribeJson: maps each [catalog, ns...] entry to a JSON object") { | ||
| val stored = | ||
| """[["spark_catalog","default"],["system","builtin"]]""" | ||
| val result = SqlPathFormat.toDescribeJson(stored) | ||
| .getOrElse(fail(s"Expected a JSON value, got None for: $stored")) | ||
| val expected = JArray(List( | ||
| JObject("catalog_name" -> JString("spark_catalog"), | ||
| "namespace" -> JArray(List(JString("default")))), | ||
| JObject("catalog_name" -> JString("system"), | ||
| "namespace" -> JArray(List(JString("builtin")))))) | ||
| assert(compactJson(result.asInstanceOf[JArray]) == compactJson(expected)) | ||
| } | ||
|
|
||
| test("toDescribeJson: multi-level namespace becomes [head, tail...]") { | ||
| val stored = """[["cat1","db","sub"]]""" | ||
| val result = SqlPathFormat.toDescribeJson(stored) | ||
| .getOrElse(fail("Expected a JSON value")) | ||
| val expected = JArray(List( | ||
| JObject("catalog_name" -> JString("cat1"), | ||
| "namespace" -> JArray(List(JString("db"), JString("sub")))))) | ||
| assert(compactJson(result.asInstanceOf[JArray]) == compactJson(expected)) | ||
| } | ||
|
|
||
| test("toDescribeJson: empty array returns None") { | ||
| assert(SqlPathFormat.toDescribeJson("[]").isEmpty) | ||
| } | ||
|
|
||
| test("toDescribeJson: malformed payloads return None") { | ||
| Seq( | ||
| "", | ||
| "not_json", | ||
| "{}", | ||
| """{"foo":1}""", | ||
| """[1, 2, 3]""" | ||
| ).foreach { payload => | ||
| assert(SqlPathFormat.toDescribeJson(payload).isEmpty, s"payload=$payload") | ||
| } | ||
| } | ||
|
|
||
| test("formatForDisplay: renders plain identifiers without backticks") { | ||
| val json = SqlPathFormat.toDescribeJson( | ||
| """[["spark_catalog","default"],["system","builtin"]]""") | ||
| .getOrElse(fail("Expected a JSON value")) | ||
| val rendered = SqlPathFormat.formatForDisplay(json) | ||
| .getOrElse(fail("Expected a display string")) | ||
| assert(rendered == "spark_catalog.default, system.builtin") | ||
| } | ||
|
|
||
| test("formatForDisplay: backticks identifiers that need quoting") { | ||
| val json = SqlPathFormat.toDescribeJson( | ||
| """[["spark_catalog","weird.schema"]]""") | ||
| .getOrElse(fail("Expected a JSON value")) | ||
| val rendered = SqlPathFormat.formatForDisplay(json) | ||
| .getOrElse(fail("Expected a display string")) | ||
| assert(rendered == "spark_catalog.`weird.schema`") | ||
| } | ||
|
|
||
| test("formatForDisplay: round-trips multi-level namespaces") { | ||
| val json = SqlPathFormat.toDescribeJson("""[["cat","db","ns"]]""") | ||
| .getOrElse(fail("Expected a JSON value")) | ||
| val rendered = SqlPathFormat.formatForDisplay(json) | ||
| .getOrElse(fail("Expected a display string")) | ||
| assert(rendered == "cat.db.ns") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
sql/connect/client/jvm/src/test/scala/org/apache/spark/sql/connect/SqlPathE2ETestSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* | ||
| * 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 | ||
|
|
||
| import org.apache.spark.sql.AnalysisException | ||
| import org.apache.spark.sql.connect.test.{ConnectFunSuite, RemoteSparkSession, SQLHelper} | ||
| import org.apache.spark.sql.functions.current_path | ||
|
|
||
| /** | ||
| * End-to-end coverage for the SQL Standard PATH feature over Spark Connect. | ||
| * | ||
| * SET PATH and the frozen-path semantics for persisted views / SQL functions are implemented | ||
| * entirely server-side, but the analyzer state (`AnalysisContext`) that carries the pinned path | ||
| * must survive plan reification across the gRPC boundary. These tests run the public surface over | ||
| * a real Connect client so regressions there are caught: | ||
| * - `SET PATH = ...` is parsed and applied to the session, | ||
| * - `current_path()` (SQL and the DataFrame builtin) reflects it, | ||
| * - a persisted view created under one path resolves its body under the frozen path even when | ||
| * the invoker switches the session path. | ||
| */ | ||
| class SqlPathE2ETestSuite extends ConnectFunSuite with RemoteSparkSession with SQLHelper { | ||
|
|
||
| test("SET PATH and current_path() round-trip over Connect") { | ||
| withSQLConf("spark.sql.path.enabled" -> "true") { | ||
| try { | ||
| spark.sql("SET PATH = spark_catalog.default, system.builtin") | ||
| val sqlPath = spark.sql("SELECT current_path()").head().getString(0) | ||
| assert( | ||
| sqlPath == "spark_catalog.default,system.builtin", | ||
| s"current_path() over Connect should reflect SET PATH; got: $sqlPath") | ||
|
|
||
| // DataFrame builtin should agree with the SQL form. | ||
| val apiPath = spark.range(1).select(current_path()).head().getString(0) | ||
| assert( | ||
| apiPath == sqlPath, | ||
| s"functions.current_path() should match SQL current_path(); got: $apiPath vs $sqlPath") | ||
| } finally { | ||
| spark.sql("SET PATH = DEFAULT_PATH") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("Persisted view body uses frozen path over Connect") { | ||
| withSQLConf("spark.sql.path.enabled" -> "true") { | ||
| withDatabase("connect_path_a", "connect_path_b") { | ||
| spark.sql("CREATE DATABASE connect_path_a") | ||
| spark.sql("CREATE DATABASE connect_path_b") | ||
| spark.sql("CREATE TABLE connect_path_a.frozen_t USING parquet AS SELECT 1 AS id") | ||
| spark.sql("CREATE TABLE connect_path_b.frozen_t USING parquet AS SELECT 2 AS id") | ||
| withView("default.v_path_connect") { | ||
| try { | ||
| // Create the view under PATH=a. | ||
| spark.sql("SET PATH = spark_catalog.connect_path_a, system.builtin") | ||
| spark.sql("CREATE VIEW default.v_path_connect AS SELECT id FROM frozen_t") | ||
|
|
||
| // Switch the session path to b; bare `frozen_t` now resolves through b, | ||
| // but the view's frozen path keeps it pinned to a. | ||
| spark.sql("SET PATH = spark_catalog.connect_path_b, system.builtin") | ||
| val bare = spark.sql("SELECT id FROM frozen_t").head().getInt(0) | ||
| assert(bare == 2, s"Bare `frozen_t` should follow live PATH=b; got: $bare") | ||
| val viaView = spark.sql("SELECT id FROM default.v_path_connect").head().getInt(0) | ||
| assert( | ||
| viaView == 1, | ||
| s"View body should resolve via the frozen creation-time PATH; got: $viaView") | ||
| } finally { | ||
| spark.sql("SET PATH = DEFAULT_PATH") | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("SET PATH is rejected over Connect when feature is disabled") { | ||
| withSQLConf("spark.sql.path.enabled" -> "false") { | ||
| val ex = intercept[AnalysisException] { | ||
| spark.sql("SET PATH = spark_catalog.default") | ||
| } | ||
| assert( | ||
| ex.getCondition == "UNSUPPORTED_FEATURE.SET_PATH_WHEN_DISABLED", | ||
| s"Expected SET_PATH_WHEN_DISABLED, got: ${ex.getCondition}") | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.