You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "smiklosovic (via GitHub)" <gi...@apache.org> on 2025/02/05 19:55:11 UTC
[PR] CASSANDRA-20295 trunk fix min/max aggregation on reversed types [cassandra]
smiklosovic opened a new pull request, #3872:
URL: https://github.com/apache/cassandra/pull/3872
Thanks for sending a pull request! Here are some tips if you're new here:
* Ensure you have added or run the [appropriate tests](https://cassandra.apache.org/_/development/testing.html) for your PR.
* Be sure to keep the PR description updated to reflect all changes.
* Write your PR title to summarize what this PR proposes.
* If possible, provide a concise example to reproduce the issue for a faster review.
* Read our [contributor guidelines](https://cassandra.apache.org/_/development/index.html)
* If you're making a documentation change, see our [guide to documentation contribution](https://cassandra.apache.org/_/development/documentation.html)
Commit messages should follow the following format:
```
<One sentence description, usually Jira title or CHANGES.txt summary>
<Optional lengthier description (context on patch)>
patch by <Authors>; reviewed by <Reviewers> for CASSANDRA-#####
Co-authored-by: Name1 <email1>
Co-authored-by: Name2 <email2>
```
The [Cassandra Jira](https://issues.apache.org/jira/projects/CASSANDRA/issues/)
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-20295 trunk fix min/max aggregation on reversed types [cassandra]
Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #3872:
URL: https://github.com/apache/cassandra/pull/3872#discussion_r1943889027
##########
test/unit/org/apache/cassandra/cql3/validation/operations/AggregationTest.java:
##########
@@ -180,6 +180,58 @@ public void testCountStarFunction() throws Throwable
assertRows(execute("SELECT max(b), COUNT(1), b FROM %s WHERE a = 1 LIMIT 2"), row(5, 4L, 1));
}
+ @Test
+ public void testMaxAggregationDescending()
+ {
+ createTable("CREATE TABLE %s (a int, b int, primary key (a, b)) WITH CLUSTERING ORDER BY (b DESC)");
+
+ execute("INSERT INTO %s (a, b) VALUES (1, 1000)");
+ execute("INSERT INTO %s (a, b) VALUES (2, 100)");
+ execute("INSERT INTO %s (a, b) VALUES (4, 1)");
+
+ assertRows(execute("SELECT count(b), max(b) as max FROM %s"),
+ row(3L, 1000));
+ }
+
+ @Test
+ public void testMinAggregationDescending()
+ {
+ createTable("CREATE TABLE %s (a int, b int, primary key (a, b)) WITH CLUSTERING ORDER BY (b DESC)");
+
+ execute("INSERT INTO %s (a, b) VALUES (1, 1000)");
+ execute("INSERT INTO %s (a, b) VALUES (2, 100)");
+ execute("INSERT INTO %s (a, b) VALUES (4, 1)");
+
+ assertRows(execute("SELECT count(b), min(b) as max FROM %s"),
+ row(3L, 1));
+ }
+
+ @Test
+ public void testMaxAggregationAscending()
+ {
+ createTable("CREATE TABLE %s (a int, b int, primary key (a, b)) WITH CLUSTERING ORDER BY (b ASC)");
+
+ execute("INSERT INTO %s (a, b) VALUES (1, 1000)");
+ execute("INSERT INTO %s (a, b) VALUES (2, 100)");
+ execute("INSERT INTO %s (a, b) VALUES (4, 1)");
+
+ assertRows(execute("SELECT count(b), max(b) as max FROM %s"),
+ row(3L, 1000));
+ }
+
+ @Test
+ public void testMinAggregationAscending()
+ {
+ createTable("CREATE TABLE %s (a int, b int, primary key (a, b)) WITH CLUSTERING ORDER BY (b ASC)");
+
+ execute("INSERT INTO %s (a, b) VALUES (1, 1000)");
+ execute("INSERT INTO %s (a, b) VALUES (2, 100)");
+ execute("INSERT INTO %s (a, b) VALUES (4, 1)");
+
+ assertRows(execute("SELECT count(b), min(b) as max FROM %s"),
Review Comment:
```suggestion
assertRows(execute("SELECT count(b), min(b) as min FROM %s"),
```
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-20295 trunk fix min/max aggregation on reversed types [cassandra]
Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #3872:
URL: https://github.com/apache/cassandra/pull/3872#discussion_r1943888687
##########
test/unit/org/apache/cassandra/cql3/validation/operations/AggregationTest.java:
##########
@@ -180,6 +180,58 @@ public void testCountStarFunction() throws Throwable
assertRows(execute("SELECT max(b), COUNT(1), b FROM %s WHERE a = 1 LIMIT 2"), row(5, 4L, 1));
}
+ @Test
+ public void testMaxAggregationDescending()
+ {
+ createTable("CREATE TABLE %s (a int, b int, primary key (a, b)) WITH CLUSTERING ORDER BY (b DESC)");
+
+ execute("INSERT INTO %s (a, b) VALUES (1, 1000)");
+ execute("INSERT INTO %s (a, b) VALUES (2, 100)");
+ execute("INSERT INTO %s (a, b) VALUES (4, 1)");
+
+ assertRows(execute("SELECT count(b), max(b) as max FROM %s"),
+ row(3L, 1000));
+ }
+
+ @Test
+ public void testMinAggregationDescending()
+ {
+ createTable("CREATE TABLE %s (a int, b int, primary key (a, b)) WITH CLUSTERING ORDER BY (b DESC)");
+
+ execute("INSERT INTO %s (a, b) VALUES (1, 1000)");
+ execute("INSERT INTO %s (a, b) VALUES (2, 100)");
+ execute("INSERT INTO %s (a, b) VALUES (4, 1)");
+
+ assertRows(execute("SELECT count(b), min(b) as max FROM %s"),
Review Comment:
```suggestion
assertRows(execute("SELECT count(b), min(b) as min FROM %s"),
```
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-20295 trunk fix min/max aggregation on reversed types [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on PR #3872:
URL: https://github.com/apache/cassandra/pull/3872#issuecomment-2639006128
@dcapwell please check now
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-20295 trunk fix min/max aggregation on reversed types [cassandra]
Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #3872:
URL: https://github.com/apache/cassandra/pull/3872#discussion_r1943887632
##########
src/java/org/apache/cassandra/cql3/functions/AggregateFcts.java:
##########
@@ -836,6 +836,66 @@ public void addInput(Arguments arguments)
}
};
+ private static abstract class AbstractNativeAggregate implements AggregateFunction.Aggregate
+ {
+ private final AbstractType<?> returnType;
+
+ public AbstractNativeAggregate(AbstractType<?> returnType)
+ {
+ this.returnType = returnType;
+ }
+
+ private ByteBuffer result;
+
+ @Override
+ public void reset()
+ {
+ result = null;
+ }
+
+ @Override
+ public ByteBuffer compute(ProtocolVersion protocolVersion)
+ {
+ return result;
+ }
+
+ @Override
+ public void addInput(Arguments arguments)
+ {
+ ByteBuffer value = arguments.get(0);
+
+ if (value == null)
+ return;
+
+ if (returnType.isReversed())
Review Comment:
can you explain why this is needed vs `returnType.unwrap()`? If we are comparing we are just reversing the compare, so if we did `returnType.unwrap()` couldn't we avoid all this?
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-20295 trunk fix min/max aggregation on reversed types [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic closed pull request #3872: CASSANDRA-20295 trunk fix min/max aggregation on reversed types
URL: https://github.com/apache/cassandra/pull/3872
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-20295 trunk fix min/max aggregation on reversed types [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #3872:
URL: https://github.com/apache/cassandra/pull/3872#discussion_r1944207551
##########
src/java/org/apache/cassandra/cql3/functions/AggregateFcts.java:
##########
@@ -836,6 +836,66 @@ public void addInput(Arguments arguments)
}
};
+ private static abstract class AbstractNativeAggregate implements AggregateFunction.Aggregate
+ {
+ private final AbstractType<?> returnType;
+
+ public AbstractNativeAggregate(AbstractType<?> returnType)
+ {
+ this.returnType = returnType;
+ }
+
+ private ByteBuffer result;
+
+ @Override
+ public void reset()
+ {
+ result = null;
+ }
+
+ @Override
+ public ByteBuffer compute(ProtocolVersion protocolVersion)
+ {
+ return result;
+ }
+
+ @Override
+ public void addInput(Arguments arguments)
+ {
+ ByteBuffer value = arguments.get(0);
+
+ if (value == null)
+ return;
+
+ if (returnType.isReversed())
Review Comment:
ah really :D I was completely oblivious to that. Thanks, that's super simple fix now.
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org