JingsongLi commented on code in PR #10950:
URL: https://github.com/apache/paimon/pull/10950#discussion_r4456399975
##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/catalyst/analysis/expressions/ExpressionUtils.scala:
##########
@@ -18,5 +18,127 @@
package org.apache.paimon.spark.catalyst.analysis.expressions
+import org.apache.paimon.predicate._
+import
org.apache.paimon.spark.util.shim.TypeUtils.treatPaimonTimestampTypeAsSparkTimestampType
+import org.apache.paimon.types.{DataTypeChecks, DataTypeFamily,
LocalZonedTimestampType, RowType, TimestampType}
+import org.apache.paimon.types.DataTypeRoot.{DOUBLE, FLOAT}
+
+import org.apache.spark.sql.SparkSession
+import org.apache.spark.sql.catalyst.optimizer.{ConstantFolding, SimplifyCasts}
+import org.apache.spark.sql.catalyst.plans.logical.Filter
+import org.apache.spark.sql.catalyst.trees.TreePattern.CURRENT_LIKE
+import org.apache.spark.sql.execution.datasources.v2.DataSourceV2Relation
+
+import scala.collection.JavaConverters._
+
/** This wrapper is only used in java code, e.g. Procedure. */
-object ExpressionUtils extends ExpressionHelper
+object ExpressionUtils extends ExpressionHelper {
+
+ def convertPolicyFilter(
+ spark: SparkSession,
+ relation: DataSourceV2Relation,
+ rowType: RowType,
+ filterSql: String): Predicate = {
+ val parsed = spark.sessionState.sqlParser.parseExpression(filterSql)
+ val analyzed = spark.sessionState.analyzer.execute(Filter(parsed,
relation))
+ spark.sessionState.analyzer.checkAnalysis(analyzed)
+ val filter = analyzed.asInstanceOf[Filter]
+ val condition = filter.condition
+ // Query-context values must not be frozen into a persistent authorization
rule.
+ require(
+ !condition.containsPattern(CURRENT_LIKE),
+ "filter_sql cannot contain expressions that depend on the current query
context."
+ )
+
+ val normalized =
SimplifyCasts(ConstantFolding(filter)).asInstanceOf[Filter].condition
+ // A stored policy has no engine-side residual filter, so every conjunct
must convert.
+ convertConditionToPaimonPredicate(
+ normalized,
+ relation.output,
+ rowType,
+ ignorePartialFailure = false)
+ .map(normalizePolicyPredicate)
Review Comment:
[P1] Reject locale-sensitive case conversion without exact SQL semantics
Case-conversion transforms still pass through with native Paimon semantics.
On JDK 8 / Spark 3.5.8, setting the JVM default locale to `tr_TR`, inserting
`(1, 'Ié')` into `(id INT, region STRING)`, and creating a ROW_FILTER with
`filter_sql => "lower(region) <> 'ıé'"` reproduces an unauthorized row through
the actual REST policy/read path. An independent Spark VALUES query returns no
rows, while `SELECT id` from the protected table (without WHERE) returns id 1.
For this non-ASCII input, Spark's UTF8String lower-case fallback uses the
default locale and yields `ıé`; Paimon's BinaryString lower-case fallback uses
Locale.ROOT and yields `ié`. There is no Spark residual to remove the extra
row. Please reject this conversion when exact case/locale semantics cannot be
represented, or provide an equivalent persisted transform, and retain this
end-to-end locale regression.
--
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]