Skip to content

[SPARK-32374][SQL] Disallow setting properties when creating temporary views#29167

Closed
imback82 wants to merge 7 commits intoapache:masterfrom
imback82:disable_properties_temp_view
Closed

[SPARK-32374][SQL] Disallow setting properties when creating temporary views#29167
imback82 wants to merge 7 commits intoapache:masterfrom
imback82:disable_properties_temp_view

Conversation

@imback82
Copy link
Contributor

What changes were proposed in this pull request?

Currently, you can specify properties when creating a temporary view. However, the specified properties are not used and can be misleading.

This PR propose to disallow specifying properties when creating temporary views.

Why are the changes needed?

To avoid confusion by disallowing specifying unused properties.

Does this PR introduce any user-facing change?

Yes, now if you create a temporary view with properties, the operation will fail:

scala> sql("CREATE TEMPORARY VIEW tv TBLPROPERTIES('p1'='v1') AS SELECT 1 AS c1")
org.apache.spark.sql.catalyst.parser.ParseException:
Operation not allowed: CREATE TEMPORARY VIEW ... TBLPROPERTIES (property_name = property_value, ...)(line 1, pos 0)

== SQL ==
CREATE TEMPORARY VIEW tv TBLPROPERTIES('p1'='v1') AS SELECT 1 AS c1
^^^


How was this patch tested?

Added tests

.getOrElse(Map.empty)
if (ctx.TEMPORARY != null && !properties.isEmpty) {
operationNotAllowed(
"CREATE TEMPORARY VIEW ... TBLPROPERTIES (property_name = property_value, ...)", ctx)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be moved to CreateViewCommand if that is a better place to check this:

// Disallows 'CREATE TEMPORARY VIEW IF NOT EXISTS' to be consistent with 'CREATE TEMPORARY TABLE'
if (allowExisting && isTemporary) {
throw new AnalysisException(
"It is not allowed to define a TEMPORARY view with IF NOT EXISTS.")
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should move that check to the parser as well (in a separate PR). If we support view in DS v2, we shouldn't duplicated the check in both v1 and v2 commands.

@SparkQA
Copy link

SparkQA commented Jul 20, 2020

Test build #126196 has finished for PR 29167 at commit de95968.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@dongjoon-hyun
Copy link
Member

Could you fix the UT failure?

org.apache.spark.sql.hive.execution.HiveSQLViewSuite.correctly parse CREATE TEMPORARY VIEW statement

intercept(sql2, "Found duplicate clauses: TBLPROPERTIES")
}

test("create temporary view with properties not allowed") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if we can have a JIRA ID prefix like SPARK-32374: .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated. thanks!

@viirya
Copy link
Member

viirya commented Jul 20, 2020

Hmm, does it mean the specified properties are not used by Spark currently? If users possibly already use it?

@imback82
Copy link
Contributor Author

Hmm, does it mean the specified properties are not used by Spark currently? If users possibly already use it?

Correct, they are not being used for temporary views. Thus, if you run SHOW TBLPROPERTIES on temp views, you will always get empty results (and it is being addressed in #29127).

Btw, properties are used for DataSource if you do CREATE TEMPORARY VIEW ... USING, but not stored.

@SparkQA
Copy link

SparkQA commented Jul 21, 2020

Test build #126202 has finished for PR 29167 at commit 8b35497.

  • This patch fails PySpark pip packaging tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@imback82
Copy link
Contributor Author

cc @cloud-fan

}
assert(e.message.contains(
"Operation not allowed: CREATE TEMPORARY VIEW ... " +
"TBLPROPERTIES (property_name = property_value, ...)"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about: Operation not allowed: TBLPROPERTIES can't coexist with CREATE TEMPORARY VIEW

@SparkQA
Copy link

SparkQA commented Jul 21, 2020

Test build #126268 has finished for PR 29167 at commit 7d8439f.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jul 21, 2020

Test build #126269 has finished for PR 29167 at commit 4f725c2.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.


test("SPARK-32374: disallow setting properties for CREATE TEMPORARY VIEW") {
withTempView("myabcdview") {
val e = intercept[AnalysisException] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parser exception?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, the tests pass. Do you know why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh because ParseException extends AnalysisException. I will update this.

@SparkQA
Copy link

SparkQA commented Jul 23, 2020

Test build #126380 has finished for PR 29167 at commit 477b696.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@imback82
Copy link
Contributor Author

retest this please

@SparkQA
Copy link

SparkQA commented Jul 23, 2020

Test build #126395 has finished for PR 29167 at commit 477b696.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in 35345e3 Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants