-
Notifications
You must be signed in to change notification settings - Fork 28k
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
[SPARK-35685][SQL] Prompt recreating the view when there is an incompatible schema issue #32831
[SPARK-35685][SQL] Prompt recreating the view when there is an incompatible schema issue #32831
Conversation
Kubernetes integration test starting |
Kubernetes integration test status success |
Test build #139525 has finished for PR 32831 at commit
|
val viewName = metadata.identifier.toString | ||
val viewText = metadata.viewText | ||
val viewColumns = metadata.schema.fieldNames.mkString(", ") | ||
s"CREATE OR REPLACE $temp VIEW $viewName ($viewColumns) AS $viewText" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to alter view is better
val viewName = metadata.identifier.toString | ||
val viewText = metadata.viewText | ||
val viewColumns = metadata.schema.fieldNames.mkString(", ") | ||
s"CREATE OR REPLACE $temp VIEW $viewName ($viewColumns) AS $viewText" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can generate ALTER VIEW
Kubernetes integration test starting |
Kubernetes integration test status failure |
Test build #140234 has finished for PR 32831 at commit
|
sql("SELECT * FROM v").show() | ||
sql("DROP TABLE t") | ||
sql("CREATE TABLE t(a INT, b INT) USING json") | ||
sql("ALTER VIEW `v` AS SELECT * FROM t") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the test should check the error message, before altering the view...
incompatible schema issue address comments code clean test example code clean
f9c4e9d
to
cae2be9
Compare
Kubernetes integration test starting |
Test build #140455 has finished for PR 32831 at commit
|
Kubernetes integration test status success |
@@ -846,6 +846,30 @@ class SessionCatalog( | |||
case None => fromCatalogTable(viewInfo.tableMeta, isTempView = true) | |||
} | |||
|
|||
private def buildViewDDL(metadata: CatalogTable, isTempView: Boolean): String = { | |||
val isGlobalTemp = metadata.identifier.database.exists(_ == globalTempViewManager.database) | |||
val viewType = if (isTempView && isGlobalTemp) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this only applies to the permanent view? We don't store temp view in the cataog.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sounds good. this will make the code simpler.
cae2be9
to
2fede50
Compare
Test build #140500 has finished for PR 32831 at commit
|
Kubernetes integration test starting |
thanks, merging to master! |
@@ -910,4 +911,27 @@ abstract class SQLViewSuite extends QueryTest with SQLTestUtils { | |||
} | |||
} | |||
} | |||
|
|||
test("SPARK-35685: Prompt recreating view message for schema mismatch") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I missed it . It's better to move this test to PersistedViewTestSuite
You can fix it in #32832
Kubernetes integration test status success |
… view ### What changes were proposed in this pull request? As described in #32831, Spark has compatible issues when querying a view created by an older version. The root cause is that Spark changed the auto-generated alias name. To avoid this in the future, we could ask the user to specify explicit column names when creating a view. ### Why are the changes needed? Avoid compatible issue when querying a view ### Does this PR introduce _any_ user-facing change? Yes. User will get error when running query below after this change ``` CREATE OR REPLACE VIEW v AS SELECT CAST(t.a AS INT), to_date(t.b, 'yyyyMMdd') FROM t ``` ### How was this patch tested? not yet Closes #32832 from linhongliu-db/SPARK-35686-no-auto-alias. Authored-by: Linhong Liu <linhong.liu@databricks.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
What changes were proposed in this pull request?
If the user creates a view in 2.4 and reads it in 3.1/3.2, there will be an incompatible schema issue.
So this PR adds a view ddl in the error message to prompt the user recreating the view to fix the
incompatible issue.
For example:
Then we will get below error:
Why are the changes needed?
Improve the error message
Does this PR introduce any user-facing change?
Yes, the error message will change
How was this patch tested?
newly added test case