ColinLeeo commented on code in PR #18826:
URL: https://github.com/apache/iotdb/pull/18826#discussion_r4279849937


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/schema/source/DeviceAttributeUpdater.java:
##########
@@ -145,9 +152,13 @@ private TsBlock getFilterTsBlock() {
     final List<Column> filterResultColumns =
         new ArrayList<>(Arrays.asList(curBlock.getValueColumns()));
 
-    // Get result of calculated common sub expressions
+    // CASE evaluation can clear a common expression after the filter used it. 
Recompute it before
+    // materializing the column for projection within this same batch.
     commonTransformerList.forEach(
-        columnTransformer -> 
filterResultColumns.add(columnTransformer.getColumn()));
+        columnTransformer -> {
+          columnTransformer.tryEvaluate();
+          filterResultColumns.add(columnTransformer.getColumn());
+        });

Review Comment:
   Common columns now use the final filter mask via `getColumnWithSelection()` 
in both query and attribute UPDATE paths. Added guarded-cast regressions.



##########
iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/FilterAndProjectOperator.java:
##########
@@ -172,8 +191,8 @@ private TsBlock getFilterTsBlock(TsBlock input) {
     if (!hasNonMappableUDF) {
       // get result of calculated common sub expressions
       for (ColumnTransformer columnTransformer : commonTransformerList) {
-        // CASE WHEN clause would clear all its cache
-        // evaluate again to acquire cache
+        // CASE evaluation can clear a common expression after the filter used 
it. Recompute it
+        // before materializing the column for projection within this same 
input block.
         columnTransformer.tryEvaluate();
         resultColumns.add(columnTransformer.getColumn());

Review Comment:
   DIFF now retains one complete result per input block for masked and full 
consumers. CASE no longer clears it during evaluation; added the shared-DIFF 
SQL regressions.



##########
iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/transformation/dag/column/AbstractCaseWhenThenColumnTransformer.java:
##########
@@ -234,6 +235,22 @@ protected void checkType() {
     // do nothing
   }
 
+  @Override
+  protected boolean shouldClearChildrenCache() {
+    // Clearing a cached CASE during evaluation must preserve pending sibling 
columns.
+    return false;
+  }

Review Comment:
   Removed CASE's evaluation-time child-cache clearing and kept selected 
results outside the shared cache. Composite transformers now retain each child 
column before evaluating the next sibling.



##########
iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/transformation/dag/column/multi/MultiColumnTransformer.java:
##########
@@ -90,11 +91,8 @@ public List<ColumnTransformer> getChildren() {
   }
 
   @Override
-  public void clearCache() {
-    super.clearCache();
-    for (ColumnTransformer columnTransformer : columnTransformerList) {
-      columnTransformer.clearCache();
-    }
+  protected void forEachChild(Consumer<ColumnTransformer> action) {
+    columnTransformerList.forEach(action);
   }

Review Comment:
   Changed `positionCount` to come from the retained first child column instead 
of its already-consumed cache.



##########
iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/transformation/dag/column/ColumnTransformer.java:
##########
@@ -112,7 +119,54 @@ public void close() {
     // do nothing
   }
 
+  /**
+   * Clears caches during evaluation. Subclasses should define child edges via 
{@link
+   * #forEachChild(Consumer)} instead of overriding this method.
+   *
+   * <p>This legacy entry point remains non-final for compatibility with 
existing test doubles.

Review Comment:
   Updated the comment to explain that `clearCache()` remains non-final for 
Mockito stubbing, and documented its distinction from new-input reset.



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