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


##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/catalyst/analysis/expressions/ExpressionUtils.scala:
##########
@@ -18,5 +18,42 @@
 
 package org.apache.paimon.spark.catalyst.analysis.expressions
 
+import org.apache.paimon.predicate.Predicate
+import org.apache.paimon.types.RowType
+
+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
+
 /** 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(

Review Comment:
   Fixed the signed-zero comparisons for FLOAT/DOUBLE. Timestamp precision is 
also normalized; legacy timestamp comparisons and nested timestamp comparisons 
with precision above 6 are rejected before storing a policy.
   
   Added end-to-end REST authorization tests with expected results evaluated 
independently using Spark `VALUES` queries.



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