roryqi commented on code in PR #14675:
URL: https://github.com/apache/gravitino/pull/14675#discussion_r4490280684


##########
maintenance/optimizer/src/main/java/org/apache/gravitino/maintenance/optimizer/recommender/handler/BaseExpressionStrategyHandler.java:
##########
@@ -241,40 +235,29 @@ private boolean evaluateBool(String expression, 
List<StatisticEntry<?>> statisti
     }
   }
 
-  private Optional<Boolean> tryToEvaluateBool(
-      String expression, List<StatisticEntry<?>> statistics) {
-    Map<String, Object> context = buildExpressionContext(statistics);
-    try {
-      return expressionEvaluator.tryToEvaluateBool(expression, context);
-    } catch (RuntimeException e) {
-      LOG.warn("Failed to evaluate expression '{}' with context {}", 
expression, context, e);
-      // Per ExpressionEvaluator#tryToEvaluateBool, a failed evaluation yields 
an empty Optional so
-      // the caller falls back to per-partition evaluation instead of treating 
it as "do not
-      // trigger".
-      return Optional.empty();
-    }
-  }
-
   /**
-   * Build a combined evaluation context. The {@code statistics} argument 
varies per partition for
-   * partitioned tables; it is layered on top of the precomputed {@link 
#tableLevelContext} (table
-   * statistics, table metadata, and numeric rule values) so that {@code 
trigger-expr} and {@code
-   * score-expr} can reference all of them.
+   * Builds the expression context for one evaluation unit.
+   *
+   * <p>Partition-aware handlers on partitioned tables receive only {@link 
#metadataAndRulesContext}
+   * plus the partition's statistics. Non-partitioned evaluation also includes 
table-level
+   * statistics.
    *
-   * @param statistics statistics of the unit being evaluated (a single 
partition, or empty for the
-   *     table-level evaluation)
+   * @param statistics statistics of the unit being evaluated (a single 
partition, or empty for
+   *     non-partitioned table-level evaluation)
    * @return combined context
    */
   private Map<String, Object> buildExpressionContext(List<StatisticEntry<?>> 
statistics) {
-    Map<String, Object> context = new HashMap<>(tableLevelContext);
+    Map<String, Object> context = new HashMap<>(metadataAndRulesContext);
+    if (!isPartitionTable()) {
+      context.putAll(StatisticsUtils.buildStatisticsContext(tableStatistics));

Review Comment:
   Could we preserve the existing variable precedence for table-level 
evaluation? Previously, the context was built as table statistics → table 
metadata → numeric policy rules, so metadata/rules took precedence on duplicate 
keys. Here, table statistics are applied after `metadataAndRulesContext`, 
reversing that precedence. If a statistic shares a name with a table property 
or numeric rule, the statistic now overrides it and can change the trigger 
result or score even for a non-partitioned table, although the PR says that 
behavior remains unchanged.
   
   Please apply table statistics before `metadataAndRulesContext` on this path, 
while continuing to exclude them from per-partition evaluation, and add a 
regression test with a duplicate key.



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