bowenliang123 commented on code in PR #4358:
URL: https://github.com/apache/kyuubi/pull/4358#discussion_r1111990349
##########
extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/ranger/RuleApplyRowFilter.scala:
##########
@@ -45,46 +46,21 @@ class RuleApplyRowFilterAndDataMasking(spark: SparkSession)
extends Rule[Logical
override def apply(plan: LogicalPlan): LogicalPlan = {
mapChildren(plan) {
- case p: RowFilterAndDataMaskingMarker => p
+ case p: RowFilterMarker => p
case scan if isKnownScan(scan) && scan.resolved =>
val tables = getScanSpec(scan).tables(scan, spark)
- tables.headOption.map(applyFilterAndMasking(scan, _)).getOrElse(scan)
+ tables.headOption.map(applyFilter(scan, _)).getOrElse(scan)
case other => apply(other)
}
}
-
- private def applyFilterAndMasking(
+ private def applyFilter(
plan: LogicalPlan,
table: Table): LogicalPlan = {
val ugi = getAuthzUgi(spark.sparkContext)
val opType = operationType(plan)
- val parse = spark.sessionState.sqlParser.parseExpression _
val are = AccessResource(ObjectType.TABLE, table.database.orNull,
table.table, null)
val art = AccessRequest(are, ugi, opType, AccessType.SELECT)
- val filterExprStr = SparkRangerAdminPlugin.getFilterExpr(art)
- val newOutput = plan.output.map { attr =>
- val are =
- AccessResource(ObjectType.COLUMN, table.database.orNull, table.table,
attr.name)
- val art = AccessRequest(are, ugi, opType, AccessType.SELECT)
- val maskExprStr = SparkRangerAdminPlugin.getMaskingExpr(art)
- if (maskExprStr.isEmpty) {
- attr
- } else {
- val maskExpr = parse(maskExprStr.get)
- plan match {
- case _: PermanentViewMarker =>
- Alias(maskExpr, attr.name)(exprId = attr.exprId)
- case _ =>
- Alias(maskExpr, attr.name)()
- }
- }
- }
-
- if (filterExprStr.isEmpty) {
- Project(newOutput, RowFilterAndDataMaskingMarker(plan))
- } else {
- val filterExpr = parse(filterExprStr.get)
- Project(newOutput, Filter(filterExpr,
RowFilterAndDataMaskingMarker(plan)))
- }
+ val filterExpr = SparkRangerAdminPlugin.getFilterExpr(art).map(parse)
+ filterExpr.foldLeft(plan)((p, e) => Filter(e, RowFilterMarker(p)))
Review Comment:
```suggestion
filterExpr.foldLeft(plan)((p, expr) => Filter(expr, RowFilterMarker(p)))
```
Maybe it's better for understanding with the var name `expr` ?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]