You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@asterixdb.apache.org by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu> on 2026/09/29 18:52:21 UTC

[S] Change in asterixdb[master]: [ASTERIXDB-3792][COMP] Restore commons Pair in KMeans rewrite rule

From Michael Blow <mb...@apache.org>:

Michael Blow has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21935?usp=email )


Change subject: [ASTERIXDB-3792][COMP] Restore commons Pair in KMeans rewrite rule
......................................................................

[ASTERIXDB-3792][COMP] Restore commons Pair in KMeans rewrite rule

- user model changes: no
- storage format changes: no
- interface changes: no

Details: The CLUSTER BY seed change was written against the old
o.a.h.a.common.utils.Pair and, on landing, put that import and its
.first/.second/new Pair<> uses back into RewriteClusterByToKMeansRule.
That class no longer exists, so asterix-algebra does not compile.
Convert the file to org.apache.commons.lang3.tuple.Pair, as the rest of
the tree already is.

Generated-by: Claude Opus 5.5 <no...@anthropic.com>
Change-Id: I516f674d9b8a7b470e905671bf12ec9127fe5500
---
M asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/RewriteClusterByToKMeansRule.java
1 file changed, 11 insertions(+), 11 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/35/21935/1

diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/RewriteClusterByToKMeansRule.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/RewriteClusterByToKMeansRule.java
index ae256a9..a9a86ab 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/RewriteClusterByToKMeansRule.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/RewriteClusterByToKMeansRule.java
@@ -34,8 +34,8 @@
 import org.apache.asterix.om.types.BuiltinType;
 import org.apache.commons.lang3.mutable.Mutable;
 import org.apache.commons.lang3.mutable.MutableObject;
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-import org.apache.hyracks.algebricks.common.utils.Pair;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan;
@@ -231,9 +231,9 @@
 
         // Forgy seeds with k centres and refines them directly; k-means|| grows a pool from one.
         Pair<Mutable<ILogicalOperator>, LogicalVariable> seedInput = branchOf(shared, vectorVar, context, loc);
-        Mutable<ILogicalOperator> centroidsIn = seedOf(seedInput.first, seedInput.second,
+        Mutable<ILogicalOperator> centroidsIn = seedOf(seedInput.getLeft(), seedInput.getRight(),
                 forgy ? kmeans(cop).getNumClusters() : 1, options(cop).getDimension(), seed, context, loc);
-        LogicalVariable centroidsVar = seedInput.second;
+        LogicalVariable centroidsVar = seedInput.getRight();
         if (!forgy) {
             KMeansStageOperator recluster =
                     oversampleAndRecluster(cop, shared, centroidsIn, centroidsVar, seed, context, loc);
@@ -258,8 +258,8 @@
         Pair<Mutable<ILogicalOperator>, LogicalVariable> input =
                 branchOf(shared, cop.getVectorVariable(), context, loc);
         KMeansStageOperator oversample = stage(cop, KMeansStageOperator.Mode.OVERSAMPLE_LOOP, context,
-                ref(input.second), ref(seedVar), oversamplingWidth(cop), seedValue, OVERSAMPLING_ROUNDS);
-        oversample.getInputs().add(input.first);
+                ref(input.getRight()), ref(seedVar), oversamplingWidth(cop), seedValue, OVERSAMPLING_ROUNDS);
+        oversample.getInputs().add(input.getLeft());
         oversample.getInputs().add(seed);
         finish(oversample, context);
 
@@ -276,9 +276,9 @@
             SourceLocation loc) throws AlgebricksException {
         Pair<Mutable<ILogicalOperator>, LogicalVariable> input =
                 branchOf(shared, cop.getVectorVariable(), context, loc);
-        KMeansStageOperator lloyd = stage(cop, KMeansStageOperator.Mode.LLOYD_LOOP, context, ref(input.second),
+        KMeansStageOperator lloyd = stage(cop, KMeansStageOperator.Mode.LLOYD_LOOP, context, ref(input.getRight()),
                 ref(centroidsVar), kmeans(cop).getNumClusters(), 0L, lloydIterations(cop));
-        lloyd.getInputs().add(input.first);
+        lloyd.getInputs().add(input.getLeft());
         lloyd.getInputs().add(centroidsIn);
         // The execution mode is derived from the input, as GROUP BY's is: a partitioned input gives one loop
         // instance per partition, an unpartitioned input a single instance. The physical operators read it
@@ -297,7 +297,7 @@
         LogicalVariable centroidVar = lloyd.getCandidateVariable();
         OrderOperator byValue = new OrderOperator();
         byValue.setSourceLocation(loc);
-        byValue.getOrderExpressions().add(new Pair<>(OrderOperator.ASC_ORDER, ref(centroidVar)));
+        byValue.getOrderExpressions().add(Pair.of(OrderOperator.ASC_ORDER, ref(centroidVar)));
         byValue.getInputs().add(new MutableObject<>(lloyd));
         finish(byValue, context);
 
@@ -449,7 +449,7 @@
         gby.addGbyExpression(cop.getClusterIdVariable(), ref(rowCid).getValue());
         // The decorations ride on every labelled row; the GROUP BY carries them out as the operator promised.
         for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : cop.getDecorList()) {
-            gby.addDecorExpression(p.first, p.second.getValue().cloneExpression());
+            gby.addDecorExpression(p.getLeft(), p.getRight().getValue().cloneExpression());
         }
         gby.getInputs().add(new MutableObject<>(labelled));
 
@@ -562,7 +562,7 @@
         // A top-n sort: PushLimitIntoOrderByRule, which would fuse a sort and a limit, has already run.
         OrderOperator order = new OrderOperator(new ArrayList<>(), n);
         order.setSourceLocation(loc);
-        order.getOrderExpressions().add(new Pair<>(OrderOperator.ASC_ORDER, ref(keyVar)));
+        order.getOrderExpressions().add(Pair.of(OrderOperator.ASC_ORDER, ref(keyVar)));
         order.getInputs().add(new MutableObject<>(assign));
         // The pass that fuses a LIMIT into a top-n sort ran before this rule, so the bound is set here
         // directly, the way the labelling join sets its broadcast NLJ. Property enforcement then derives a
@@ -629,6 +629,6 @@
         thin.setSourceLocation(loc);
         thin.getInputs().add(new MutableObject<>(rename));
         finish(thin, context);
-        return new Pair<>(new MutableObject<>(thin), branchVar);
+        return Pair.of(new MutableObject<>(thin), branchVar);
     }
 }

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21935?usp=email
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: I516f674d9b8a7b470e905671bf12ec9127fe5500
Gerrit-Change-Number: 21935
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Blow <mb...@apache.org>