Skip to content

Commit

Permalink
Fix show materialized view bug
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Dai <[email protected]>
  • Loading branch information
dai-chen committed May 10, 2024
1 parent 9a70d14 commit 78bbfb0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ trait FlintSparkMaterializedViewAstBuilder extends FlintSparkSqlExtensionsVisito
val catalogDbName =
ctx.catalogDb.parts
.map(part => part.getText)
.mkString("_")
val indexNamePattern = s"flint_${catalogDbName}_*"
.mkString(".")
val indexNamePattern = s"flint_${catalogDbName.replace('.', '_')}_*"
flint
.describeIndexes(indexNamePattern)
.collect { case mv: FlintSparkMaterializedView =>
// MV name must be qualified when metadata created
Row(mv.mvName.split('.').drop(2).mkString("."))
.collect {
// Ensure index is a MV within the given catalog and database
case mv: FlintSparkMaterializedView if mv.mvName.startsWith(s"$catalogDbName.") =>
// MV name must be qualified when metadata created
Row(mv.mvName.split('.').drop(2).mkString("."))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class FlintSparkCoveringIndexSqlITSuite extends FlintSparkSuite {
deleteTestIndex(getFlintIndexName("idx_address", testTable), getSkippingIndexName(testTable))
}

test("show covering index on source table with same prefix") {
test("show covering index on source table with the same prefix") {
flint
.coveringIndex()
.name(testIndex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ class FlintSparkMaterializedViewSqlITSuite extends FlintSparkSuite {
checkAnswer(sql(s"SHOW MATERIALIZED VIEW IN spark_catalog.other"), Seq.empty)
}

test("show materialized view in database with the same prefix") {
flint.materializedView().name("spark_catalog.default.mv1").query(testQuery).create()
flint.materializedView().name("spark_catalog.default_test.mv2").query(testQuery).create()
checkAnswer(sql(s"SHOW MATERIALIZED VIEW IN spark_catalog.default"), Seq(Row("mv1")))
}

test("should return emtpy when show materialized views in empty database") {
checkAnswer(sql(s"SHOW MATERIALIZED VIEW IN spark_catalog.other"), Seq.empty)
}
Expand Down

0 comments on commit 78bbfb0

Please sign in to comment.