-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow queries that reference catalog views
- Loading branch information
Showing
6 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
flint-spark-integration/src/main/scala/org/opensearch/flint/spark/DisallowCatalogViews.scala
This file contains 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,27 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.spark | ||
|
||
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]]. | ||
*/ | ||
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" | ||
) | ||
|
||
case other => other | ||
} | ||
plan | ||
} | ||
} |
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -101,7 +101,7 @@ trait FlintSparkSuite extends QueryTest with FlintSuite with OpenSearchSuite wit | |
} | ||
|
||
protected def createPartitionedGrokEmailTable(testTable: String): Unit = { | ||
spark.sql(s""" | ||
val table = spark.sql(s""" | ||
| CREATE TABLE $testTable | ||
| ( | ||
| name STRING, | ||
|
@@ -115,7 +115,6 @@ trait FlintSparkSuite extends QueryTest with FlintSuite with OpenSearchSuite wit | |
| month INT | ||
| ) | ||
|""".stripMargin) | ||
|
||
val data = Seq( | ||
("Alice", 30, "[email protected]", "123 Main St, Seattle", 2023, 4), | ||
("Bob", 55, "[email protected]", "456 Elm St, Portland", 2023, 5), | ||
|
@@ -135,6 +134,17 @@ trait FlintSparkSuite extends QueryTest with FlintSuite with OpenSearchSuite wit | |
| VALUES ('$name', $age, '$email', '$street_address') | ||
| """.stripMargin) | ||
} | ||
// Create a Glue view | ||
val glueViewName = "my_view" | ||
val glueViewQuery = s""" | ||
CREATE VIEW $glueViewName | ||
AS | ||
SELECT name, age, email, street_address | ||
FROM $testTable | ||
""" | ||
|
||
val res = spark.sql(glueViewQuery) | ||
log.error(res.toString()) | ||
} | ||
protected def createPartitionedAddressTable(testTable: String): Unit = { | ||
sql(s""" | ||
|
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version = 1.8.2 | ||
sbt.version = 1.10.1 |