cloud-fan commented on code in PR #51014: URL: https://github.com/apache/spark/pull/51014#discussion_r2107426135
########## sql/core/src/test/scala/org/apache/spark/sql/analysis/AnalysisConfOverrideSuite.scala: ########## @@ -0,0 +1,184 @@ +/* + * 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.analysis + +import org.apache.spark.SparkConf +import org.apache.spark.sql.SparkSessionExtensions +import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan +import org.apache.spark.sql.catalyst.rules.Rule +import org.apache.spark.sql.test.SharedSparkSession + +class AnalysisConfOverrideSuite extends SharedSparkSession { + + override protected def sparkConf: SparkConf = { + super.sparkConf + .set("spark.sql.extensions", "com.databricks.sql.ConfOverrideValidationExtensions") + } + + override def beforeAll(): Unit = { + super.beforeAll() + spark.sql("SELECT id as a FROM range(10)").createTempView("table") + spark.sql("SELECT id as a, (id + 1) as b FROM range(10)").createTempView("table2") + } + + override def afterAll(): Unit = { + spark.catalog.dropTempView("table") + spark.catalog.dropTempView("table2") + super.afterAll() + } + + private def testOverride(testName: String)(f: (String, String) => Unit): Unit = { + test(testName) { + val key = "spark.sql.catalog.x.y" + val value = "true" + withSQLConf(key -> value) { + f + } + } + } + + testOverride("simple plan") { case (key, value) => + ValidateConfOverrideRule.withConfValidationEnabled(key, value) { + spark.sql("SELECT * FROM TaBlE") + } + } + + testOverride("CTE") { case (key, value) => + ValidateConfOverrideRule.withConfValidationEnabled(key, value) { + spark.sql( + """WITH cte AS (SELECT * FROM TaBlE) + |SELECT * FROM cte + |""".stripMargin) + } + } + + testOverride("Subquery") { case (key, value) => + ValidateConfOverrideRule.withConfValidationEnabled(key, value) { + spark.sql( + """ + |SELECT * FROM TaBlE WHERE a in (SELECT a FROM table2) + |""".stripMargin) + } + } + + testOverride("View") { case (key, value) => + withTable("test_table", "test_table2") { + spark.sql("CREATE TABLE test_table AS SELECT id as a FROM range(10)") + spark.sql("CREATE TABLE test_table2 AS SELECT id as a, (id + 1) as b FROM range(10)") + withView("test_view") { + spark.sql("CREATE VIEW test_view AS " + + "SELECT * FROM test_table WHERE a in (SELECT a FROM test_table2)") + + ValidateConfOverrideRule.withConfValidationEnabled(key, value) { Review Comment: to confirm: the check is performed three times in this test, one for subquery expression, one for the view query, and one for the main query? -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org