Skip to content

Commit

Permalink
add it for sql query on views
Browse files Browse the repository at this point in the history
Signed-off-by: Surya Sashank Nistala <[email protected]>
  • Loading branch information
eirsep committed Sep 11, 2024
1 parent ffe721a commit 37818bc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, View}
import org.apache.spark.sql.catalyst.rules.Rule

/**
* This analysis rule validates that the submitted query is not referencing a Glue Catalog view. The rule simply traverses
* the plan and validates that none of the nodes resolved to a [[View]].
* This analysis rule validates that the submitted query is not referencing a Glue Catalog view.
* The rule simply traverses the plan and validates that none of the nodes resolved to a [[View]].
*/
class DisallowCatalogViews extends Rule[LogicalPlan] {
override def apply(plan: LogicalPlan): LogicalPlan = {
plan.foreachUp {
case _: View =>
throw new IllegalArgumentException(
s"Catalog View is not allowed to be queried"
)
throw new IllegalArgumentException(s"Catalog View is not allowed to be queried")

case other => other
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class ApplyFlintSparkCoveringIndexSuite extends FlintSuite with Matchers {
| ('F', 35), ('G', 40), ('H', 45), ('I', 50), ('J', 55)
| """.stripMargin)

// Create a view
sql(s"CREATE VIEW myView AS SELECT name, age FROM $testTable WHERE age > 20")

// Mock static create method in FlintClientBuilder used by Flint data source
clientBuilder
.when(() => FlintClientBuilder.build(any(classOf[FlintOptions])))
Expand Down Expand Up @@ -141,6 +144,12 @@ class ApplyFlintSparkCoveringIndexSuite extends FlintSuite with Matchers {
filterCondition = Some("name = 'A' OR age > 30")))
.assertIndexNotUsed(testTable)
}
test("test querying catalog views throws validation exception") {
the[IllegalArgumentException] thrownBy {
sql(s"SELECT * FROM myview WHERE name = 'A' AND age > 30")
} should have message "Catalog View is not allowed to be queried"

}

test("should not apply if covering index is logically deleted") {
assertFlintQueryRewriter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class FlintSparkPPLGrokITSuite
}
}


test("test querying catalog views throws validation exception") {
the[IllegalArgumentException] thrownBy {
sql("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ class FlintPPLSparkExtensions extends (SparkSessionExtensions => Unit) {
extensions.injectParser { (spark, parser) =>
new FlintSparkPPLParser(parser)
}


}
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.10.1
sbt.version = 1.8.2

0 comments on commit 37818bc

Please sign in to comment.