Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions extensions/spark/kyuubi-spark-authz/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.kyuubi</groupId>
<artifactId>kyuubi-spark-lineage_${scala.binary.version}</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import org.scalatest.BeforeAndAfterAll
import org.scalatest.funsuite.AnyFunSuite

import org.apache.kyuubi.Utils
import org.apache.kyuubi.plugin.lineage.Lineage
import org.apache.kyuubi.plugin.lineage.helper.SparkSQLLineageParseHelper
import org.apache.kyuubi.plugin.spark.authz.{AccessControlException, SparkSessionProvider}
import org.apache.kyuubi.plugin.spark.authz.MysqlContainerEnv
import org.apache.kyuubi.plugin.spark.authz.RangerTestNamespace._
Expand Down Expand Up @@ -1513,4 +1515,31 @@ class HiveCatalogRangerSparkExtensionSuite extends RangerSparkExtensionSuite {
}
}
}

test("Test view lineage") {
def extractLineage(sql: String): Lineage = {
val parsed = spark.sessionState.sqlParser.parsePlan(sql)
val qe = spark.sessionState.executePlan(parsed)
val analyzed = qe.analyzed
SparkSQLLineageParseHelper(spark).transformToLineage(0, analyzed).get
}

val db1 = defaultDb
val table1 = "table1"
val view1 = "view1"
withSingleCallEnabled {
withCleanTmpResources(Seq((s"$db1.$table1", "table"), (s"$db1.$view1", "view"))) {
doAs(admin, sql(s"CREATE TABLE IF NOT EXISTS $db1.$table1 (id int, scope int)"))
doAs(admin, sql(s"CREATE VIEW $db1.$view1 AS SELECT * FROM $db1.$table1"))

val lineage = doAs(
admin,
extractLineage(s"SELECT id FROM $db1.$view1 WHERE id > 1"))
assert(lineage.inputTables.size == 1)
assert(lineage.inputTables.head === s"spark_catalog.$db1.$table1")
assert(lineage.columnLineage.size == 1)
assert(lineage.columnLineage.head.originalColumns.head === s"spark_catalog.$db1.$table1.id")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,13 @@ trait LineageParser {
})
}

// PermanentViewMarker is introduced by kyuubi authz plugin, which is a wrapper of View,
// so we just extract the columns lineage from its inner children (original view)
case pvm if pvm.nodeName == "PermanentViewMarker" =>
pvm.innerChildren.asInstanceOf[Seq[LogicalPlan]]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

.map(extractColumnsLineage(_, parentColumnsLineage))
.reduce(mergeColumnsLineage)

case p: View =>
if (!p.isTempView && SparkContextHelper.getConf(
LineageConf.SKIP_PARSING_PERMANENT_VIEW_ENABLED)) {
Expand Down
Loading