zhoulii commented on code in PR #10950:
URL: https://github.com/apache/paimon/pull/10950#discussion_r4463548201


##########
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:
   Non-constant `LOWER`/`UPPER` expressions are now rejected after constant 
folding, before storing a policy. Constant calls remain supported.
   
   Added a Turkish-locale REST regression verifying rejection without 
persisting a policy. Native Predicate JSON behavior is unchanged.



-- 
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]

Reply via email to