You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "yx-zhang (via GitHub)" <gi...@apache.org> on 2024/12/20 14:41:46 UTC
[PR] Add aggregate function count_if for relational table [iotdb]
yx-zhang opened a new pull request, #14511:
URL: https://github.com/apache/iotdb/pull/14511
Add aggregate function count_if for relational table
### Content1 ...
### Content2 ...
### Content3 ...
<!--
In each section, please describe design decisions made, including:
- Choice of algorithms
- Behavioral aspects. What configuration values are acceptable? How are corner cases and error
conditions handled, such as when there are insufficient resources?
- Class organization and design (how the logic is split between classes, inheritance, composition,
design patterns)
- Method organization and design (how the logic is split between methods, parameters and return types)
- Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
-->
<!-- It's good to describe an alternative design (or mention an alternative name) for every design
(or naming) decision point and compare the alternatives with the designs that you've implemented
(or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
<!-- If there was a discussion of the design of the feature implemented in this PR elsewhere
(e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list),
link to that discussion from this PR description and explain what have changed in your final design
compared to your original proposal or the consensus version in the end of the discussion.
If something hasn't changed since the original discussion, you can omit a detailed discussion of
those aspects of the design here, perhaps apart from brief mentioning for the sake of readability
of this PR description. -->
<!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
<hr>
This PR has:
- [ ] been self-reviewed.
- [ ] concurrent read
- [ ] concurrent write
- [ ] concurrent read and write
- [ ] added documentation for new or modified features or behaviors.
- [ ] added Javadocs for most classes and all non-trivial methods.
- [ ] added or updated version, __license__, or notice information
- [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious
for an unfamiliar reader.
- [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold
for code coverage.
- [ ] added integration tests.
- [ ] been tested in a test IoTDB cluster.
<!-- Check the items by putting "x" in the brackets for the done things. Not all of these items
apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items
from the checklist above are strictly necessary, but it would be very helpful if you at least
self-review the PR. -->
<hr>
##### Key changed/added classes (or packages if there are too many classes) in this PR
--
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: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add aggregate function count_if for relational table [iotdb]
Posted by "JackieTien97 (via GitHub)" <gi...@apache.org>.
JackieTien97 commented on code in PR #14511:
URL: https://github.com/apache/iotdb/pull/14511#discussion_r1899959344
##########
integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java:
##########
@@ -433,6 +434,335 @@ public void countTest() {
tableResultSetEqualTest("select count(*) from table1", expectedHeader, retArray, DATABASE_NAME);
}
+ @Test
+ public void countIfTest() {
+ String[] expectedHeader = new String[] {"_col0"};
+ String[] retArray =
+ new String[] {
+ "5,",
+ };
+ tableResultSetEqualTest(
+ "select count_if(device_id = 'd01') from table1", expectedHeader, retArray, DATABASE_NAME);
+
+ expectedHeader = new String[] {"_col0"};
+ retArray =
+ new String[] {
+ "64,",
+ };
+ tableResultSetEqualTest(
+ "select count_if(true) from table1", expectedHeader, retArray, DATABASE_NAME);
+
+ expectedHeader = new String[] {"_col0", "end_time", "device_id", "_col3"};
+ retArray =
+ new String[] {
+ "2024-09-24T06:15:30.000Z,2024-09-24T06:15:35.000Z,d01,1,",
+ "2024-09-24T06:15:35.000Z,2024-09-24T06:15:40.000Z,d01,1,",
+ "2024-09-24T06:15:40.000Z,2024-09-24T06:15:45.000Z,d01,1,",
+ "2024-09-24T06:15:50.000Z,2024-09-24T06:15:55.000Z,d01,1,",
+ "2024-09-24T06:15:55.000Z,2024-09-24T06:16:00.000Z,d01,1,",
+ "2024-09-24T06:15:35.000Z,2024-09-24T06:15:40.000Z,d02,0,",
+ "2024-09-24T06:15:40.000Z,2024-09-24T06:15:45.000Z,d02,0,",
+ "2024-09-24T06:15:50.000Z,2024-09-24T06:15:55.000Z,d02,0,",
+ "2024-09-24T06:15:30.000Z,2024-09-24T06:15:35.000Z,d03,0,",
+ "2024-09-24T06:15:35.000Z,2024-09-24T06:15:40.000Z,d03,0,",
+ "2024-09-24T06:15:40.000Z,2024-09-24T06:15:45.000Z,d03,0,",
+ "2024-09-24T06:15:45.000Z,2024-09-24T06:15:50.000Z,d03,0,",
+ "2024-09-24T06:15:50.000Z,2024-09-24T06:15:55.000Z,d03,0,",
+ "2024-09-24T06:15:30.000Z,2024-09-24T06:15:35.000Z,d04,0,",
+ "2024-09-24T06:15:40.000Z,2024-09-24T06:15:45.000Z,d04,0,",
+ "2024-09-24T06:15:55.000Z,2024-09-24T06:16:00.000Z,d04,0,",
+ "2024-09-24T06:15:30.000Z,2024-09-24T06:15:35.000Z,d05,0,",
+ "2024-09-24T06:15:35.000Z,2024-09-24T06:15:40.000Z,d05,0,",
+ "2024-09-24T06:15:40.000Z,2024-09-24T06:15:45.000Z,d05,0,",
+ "2024-09-24T06:15:50.000Z,2024-09-24T06:15:55.000Z,d05,0,",
+ "2024-09-24T06:15:55.000Z,2024-09-24T06:16:00.000Z,d05,0,",
+ "2024-09-24T06:15:35.000Z,2024-09-24T06:15:40.000Z,d06,0,",
+ "2024-09-24T06:15:40.000Z,2024-09-24T06:15:45.000Z,d06,0,",
+ "2024-09-24T06:15:50.000Z,2024-09-24T06:15:55.000Z,d06,0,",
+ "2024-09-24T06:15:30.000Z,2024-09-24T06:15:35.000Z,d07,0,",
+ "2024-09-24T06:15:35.000Z,2024-09-24T06:15:40.000Z,d07,0,",
+ "2024-09-24T06:15:40.000Z,2024-09-24T06:15:45.000Z,d07,0,",
+ "2024-09-24T06:15:45.000Z,2024-09-24T06:15:50.000Z,d07,0,",
+ "2024-09-24T06:15:50.000Z,2024-09-24T06:15:55.000Z,d07,0,",
+ "2024-09-24T06:15:30.000Z,2024-09-24T06:15:35.000Z,d08,0,",
+ "2024-09-24T06:15:40.000Z,2024-09-24T06:15:45.000Z,d08,0,",
+ "2024-09-24T06:15:55.000Z,2024-09-24T06:16:00.000Z,d08,0,",
+ "2024-09-24T06:15:30.000Z,2024-09-24T06:15:35.000Z,d09,0,",
+ "2024-09-24T06:15:35.000Z,2024-09-24T06:15:40.000Z,d09,0,",
+ "2024-09-24T06:15:40.000Z,2024-09-24T06:15:45.000Z,d09,0,",
+ "2024-09-24T06:15:50.000Z,2024-09-24T06:15:55.000Z,d09,0,",
+ "2024-09-24T06:15:55.000Z,2024-09-24T06:16:00.000Z,d09,0,",
+ "2024-09-24T06:15:35.000Z,2024-09-24T06:15:40.000Z,d10,0,",
+ "2024-09-24T06:15:40.000Z,2024-09-24T06:15:45.000Z,d10,0,",
+ "2024-09-24T06:15:50.000Z,2024-09-24T06:15:55.000Z,d10,0,",
+ "2024-09-24T06:15:30.000Z,2024-09-24T06:15:35.000Z,d11,0,",
+ "2024-09-24T06:15:35.000Z,2024-09-24T06:15:40.000Z,d11,0,",
+ "2024-09-24T06:15:40.000Z,2024-09-24T06:15:45.000Z,d11,0,",
+ "2024-09-24T06:15:45.000Z,2024-09-24T06:15:50.000Z,d11,0,",
+ "2024-09-24T06:15:50.000Z,2024-09-24T06:15:55.000Z,d11,0,",
+ "2024-09-24T06:15:30.000Z,2024-09-24T06:15:35.000Z,d12,0,",
+ "2024-09-24T06:15:40.000Z,2024-09-24T06:15:45.000Z,d12,0,",
+ "2024-09-24T06:15:55.000Z,2024-09-24T06:16:00.000Z,d12,0,",
+ "2024-09-24T06:15:30.000Z,2024-09-24T06:15:35.000Z,d13,0,",
+ "2024-09-24T06:15:35.000Z,2024-09-24T06:15:40.000Z,d13,0,",
+ "2024-09-24T06:15:40.000Z,2024-09-24T06:15:45.000Z,d13,0,",
+ "2024-09-24T06:15:50.000Z,2024-09-24T06:15:55.000Z,d13,0,",
+ "2024-09-24T06:15:55.000Z,2024-09-24T06:16:00.000Z,d13,0,",
+ "2024-09-24T06:15:35.000Z,2024-09-24T06:15:40.000Z,d14,0,",
+ "2024-09-24T06:15:40.000Z,2024-09-24T06:15:45.000Z,d14,0,",
+ "2024-09-24T06:15:50.000Z,2024-09-24T06:15:55.000Z,d14,0,",
+ "2024-09-24T06:15:30.000Z,2024-09-24T06:15:35.000Z,d15,0,",
+ "2024-09-24T06:15:35.000Z,2024-09-24T06:15:40.000Z,d15,0,",
+ "2024-09-24T06:15:40.000Z,2024-09-24T06:15:45.000Z,d15,0,",
+ "2024-09-24T06:15:45.000Z,2024-09-24T06:15:50.000Z,d15,0,",
+ "2024-09-24T06:15:50.000Z,2024-09-24T06:15:55.000Z,d15,0,",
+ "2024-09-24T06:15:30.000Z,2024-09-24T06:15:35.000Z,d16,0,",
+ "2024-09-24T06:15:40.000Z,2024-09-24T06:15:45.000Z,d16,0,",
+ "2024-09-24T06:15:55.000Z,2024-09-24T06:16:00.000Z,d16,0,",
+ };
+ tableResultSetEqualTest(
+ "select date_bin(5s, time), (date_bin(5s, time) + 5000) as end_time, device_id, count_if(device_id = 'd01') from table1 group by 1,device_id",
+ expectedHeader,
+ retArray,
+ DATABASE_NAME);
+
+ expectedHeader = new String[] {"_col0", "province", "city", "region", "device_id", "_col5"};
+ retArray =
+ new String[] {
+ "2024-09-24T06:15:30.000Z,beijing,beijing,chaoyang,d09,0,",
+ "2024-09-24T06:15:35.000Z,beijing,beijing,chaoyang,d09,0,",
+ "2024-09-24T06:15:40.000Z,beijing,beijing,chaoyang,d09,0,",
+ "2024-09-24T06:15:50.000Z,beijing,beijing,chaoyang,d09,0,",
+ "2024-09-24T06:15:55.000Z,beijing,beijing,chaoyang,d09,0,",
+ "2024-09-24T06:15:35.000Z,beijing,beijing,chaoyang,d10,0,",
+ "2024-09-24T06:15:40.000Z,beijing,beijing,chaoyang,d10,0,",
+ "2024-09-24T06:15:50.000Z,beijing,beijing,chaoyang,d10,0,",
+ "2024-09-24T06:15:30.000Z,beijing,beijing,chaoyang,d11,1,",
+ "2024-09-24T06:15:35.000Z,beijing,beijing,chaoyang,d11,1,",
+ "2024-09-24T06:15:40.000Z,beijing,beijing,chaoyang,d11,1,",
+ "2024-09-24T06:15:45.000Z,beijing,beijing,chaoyang,d11,1,",
+ "2024-09-24T06:15:50.000Z,beijing,beijing,chaoyang,d11,1,",
+ "2024-09-24T06:15:30.000Z,beijing,beijing,chaoyang,d12,1,",
+ "2024-09-24T06:15:40.000Z,beijing,beijing,chaoyang,d12,1,",
+ "2024-09-24T06:15:55.000Z,beijing,beijing,chaoyang,d12,1,",
+ "2024-09-24T06:15:30.000Z,beijing,beijing,haidian,d13,0,",
+ "2024-09-24T06:15:35.000Z,beijing,beijing,haidian,d13,0,",
+ "2024-09-24T06:15:40.000Z,beijing,beijing,haidian,d13,0,",
+ "2024-09-24T06:15:50.000Z,beijing,beijing,haidian,d13,0,",
+ "2024-09-24T06:15:55.000Z,beijing,beijing,haidian,d13,0,",
+ "2024-09-24T06:15:35.000Z,beijing,beijing,haidian,d14,0,",
+ "2024-09-24T06:15:40.000Z,beijing,beijing,haidian,d14,0,",
+ "2024-09-24T06:15:50.000Z,beijing,beijing,haidian,d14,0,",
+ "2024-09-24T06:15:30.000Z,beijing,beijing,haidian,d15,1,",
+ "2024-09-24T06:15:35.000Z,beijing,beijing,haidian,d15,1,",
+ "2024-09-24T06:15:40.000Z,beijing,beijing,haidian,d15,1,",
+ "2024-09-24T06:15:45.000Z,beijing,beijing,haidian,d15,1,",
+ "2024-09-24T06:15:50.000Z,beijing,beijing,haidian,d15,1,",
+ "2024-09-24T06:15:30.000Z,beijing,beijing,haidian,d16,1,",
+ "2024-09-24T06:15:40.000Z,beijing,beijing,haidian,d16,1,",
+ "2024-09-24T06:15:55.000Z,beijing,beijing,haidian,d16,1,",
+ "2024-09-24T06:15:30.000Z,shanghai,shanghai,huangpu,d01,0,",
+ "2024-09-24T06:15:35.000Z,shanghai,shanghai,huangpu,d01,0,",
+ "2024-09-24T06:15:40.000Z,shanghai,shanghai,huangpu,d01,0,",
+ "2024-09-24T06:15:50.000Z,shanghai,shanghai,huangpu,d01,0,",
+ "2024-09-24T06:15:55.000Z,shanghai,shanghai,huangpu,d01,0,",
+ "2024-09-24T06:15:35.000Z,shanghai,shanghai,huangpu,d02,0,",
+ "2024-09-24T06:15:40.000Z,shanghai,shanghai,huangpu,d02,0,",
+ "2024-09-24T06:15:50.000Z,shanghai,shanghai,huangpu,d02,0,",
+ "2024-09-24T06:15:30.000Z,shanghai,shanghai,huangpu,d03,1,",
+ "2024-09-24T06:15:35.000Z,shanghai,shanghai,huangpu,d03,1,",
+ "2024-09-24T06:15:40.000Z,shanghai,shanghai,huangpu,d03,1,",
+ "2024-09-24T06:15:45.000Z,shanghai,shanghai,huangpu,d03,1,",
+ "2024-09-24T06:15:50.000Z,shanghai,shanghai,huangpu,d03,1,",
+ "2024-09-24T06:15:30.000Z,shanghai,shanghai,huangpu,d04,1,",
+ "2024-09-24T06:15:40.000Z,shanghai,shanghai,huangpu,d04,1,",
+ "2024-09-24T06:15:55.000Z,shanghai,shanghai,huangpu,d04,1,",
+ "2024-09-24T06:15:30.000Z,shanghai,shanghai,pudong,d05,0,",
+ "2024-09-24T06:15:35.000Z,shanghai,shanghai,pudong,d05,0,",
+ "2024-09-24T06:15:40.000Z,shanghai,shanghai,pudong,d05,0,",
+ "2024-09-24T06:15:50.000Z,shanghai,shanghai,pudong,d05,0,",
+ "2024-09-24T06:15:55.000Z,shanghai,shanghai,pudong,d05,0,",
+ "2024-09-24T06:15:35.000Z,shanghai,shanghai,pudong,d06,0,",
+ "2024-09-24T06:15:40.000Z,shanghai,shanghai,pudong,d06,0,",
+ "2024-09-24T06:15:50.000Z,shanghai,shanghai,pudong,d06,0,",
+ "2024-09-24T06:15:30.000Z,shanghai,shanghai,pudong,d07,1,",
+ "2024-09-24T06:15:35.000Z,shanghai,shanghai,pudong,d07,1,",
+ "2024-09-24T06:15:40.000Z,shanghai,shanghai,pudong,d07,1,",
+ "2024-09-24T06:15:45.000Z,shanghai,shanghai,pudong,d07,1,",
+ "2024-09-24T06:15:50.000Z,shanghai,shanghai,pudong,d07,1,",
+ "2024-09-24T06:15:30.000Z,shanghai,shanghai,pudong,d08,1,",
+ "2024-09-24T06:15:40.000Z,shanghai,shanghai,pudong,d08,1,",
+ "2024-09-24T06:15:55.000Z,shanghai,shanghai,pudong,d08,1,",
+ };
+ tableResultSetEqualTest(
+ "select date_bin(5s, time),province,city,region,device_id,count_if(color != 'red') from table1 group by 1,2,3,4,5 order by 2,3,4,5,1",
+ expectedHeader,
+ retArray,
+ DATABASE_NAME);
+
+ expectedHeader =
+ new String[] {
+ "_col0",
+ "province",
+ "city",
+ "region",
+ "device_id",
+ "_col5",
+ "_col6",
+ "_col7",
+ "_col8",
+ "_col9",
+ "_col10",
+ "_col11",
+ "_col12",
+ "_col13",
+ "_col14"
+ };
+ retArray =
+ new String[] {
+ "2024-09-24T06:15:30.000Z,beijing,beijing,chaoyang,d09,0,0,0,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:35.000Z,beijing,beijing,chaoyang,d09,1,1,1,1,0,0,0,1,1,1,",
+ "2024-09-24T06:15:40.000Z,beijing,beijing,chaoyang,d09,0,0,1,0,1,0,0,1,1,0,",
+ "2024-09-24T06:15:50.000Z,beijing,beijing,chaoyang,d09,1,0,0,0,0,0,0,1,1,1,",
+ "2024-09-24T06:15:55.000Z,beijing,beijing,chaoyang,d09,0,0,0,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:35.000Z,beijing,beijing,chaoyang,d10,0,0,0,0,1,0,0,1,1,0,",
+ "2024-09-24T06:15:40.000Z,beijing,beijing,chaoyang,d10,0,0,0,1,0,0,0,1,1,1,",
+ "2024-09-24T06:15:50.000Z,beijing,beijing,chaoyang,d10,1,0,0,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:30.000Z,beijing,beijing,chaoyang,d11,1,1,0,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:35.000Z,beijing,beijing,chaoyang,d11,0,0,0,1,0,0,0,1,1,1,",
+ "2024-09-24T06:15:40.000Z,beijing,beijing,chaoyang,d11,0,0,1,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:45.000Z,beijing,beijing,chaoyang,d11,1,1,0,1,0,0,0,1,1,0,",
+ "2024-09-24T06:15:50.000Z,beijing,beijing,chaoyang,d11,1,0,1,0,0,0,0,1,1,0,",
+ "2024-09-24T06:15:30.000Z,beijing,beijing,chaoyang,d12,1,0,0,0,1,0,0,1,1,1,",
+ "2024-09-24T06:15:40.000Z,beijing,beijing,chaoyang,d12,1,1,0,0,0,0,0,1,1,0,",
+ "2024-09-24T06:15:55.000Z,beijing,beijing,chaoyang,d12,0,0,0,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:30.000Z,beijing,beijing,haidian,d13,0,0,0,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:35.000Z,beijing,beijing,haidian,d13,1,1,1,1,0,0,0,1,1,1,",
+ "2024-09-24T06:15:40.000Z,beijing,beijing,haidian,d13,0,0,1,0,1,0,0,1,1,0,",
+ "2024-09-24T06:15:50.000Z,beijing,beijing,haidian,d13,1,0,0,0,0,0,0,1,1,1,",
+ "2024-09-24T06:15:55.000Z,beijing,beijing,haidian,d13,0,0,0,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:35.000Z,beijing,beijing,haidian,d14,0,0,0,0,1,0,0,1,1,0,",
+ "2024-09-24T06:15:40.000Z,beijing,beijing,haidian,d14,0,0,0,1,0,0,0,1,1,1,",
+ "2024-09-24T06:15:50.000Z,beijing,beijing,haidian,d14,1,0,0,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:30.000Z,beijing,beijing,haidian,d15,1,1,0,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:35.000Z,beijing,beijing,haidian,d15,0,0,0,1,0,0,0,1,1,1,",
+ "2024-09-24T06:15:40.000Z,beijing,beijing,haidian,d15,0,0,1,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:45.000Z,beijing,beijing,haidian,d15,1,1,0,1,0,0,0,1,1,0,",
+ "2024-09-24T06:15:50.000Z,beijing,beijing,haidian,d15,1,0,1,0,0,0,0,1,1,0,",
+ "2024-09-24T06:15:30.000Z,beijing,beijing,haidian,d16,1,0,0,0,1,0,0,1,1,1,",
+ "2024-09-24T06:15:40.000Z,beijing,beijing,haidian,d16,1,1,0,0,0,0,0,1,1,0,",
+ "2024-09-24T06:15:55.000Z,beijing,beijing,haidian,d16,0,0,0,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:30.000Z,shanghai,shanghai,huangpu,d01,0,0,0,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:35.000Z,shanghai,shanghai,huangpu,d01,1,1,1,1,0,0,0,1,1,1,",
+ "2024-09-24T06:15:40.000Z,shanghai,shanghai,huangpu,d01,0,0,1,0,1,0,0,1,1,0,",
+ "2024-09-24T06:15:50.000Z,shanghai,shanghai,huangpu,d01,1,0,0,0,0,0,0,1,1,1,",
+ "2024-09-24T06:15:55.000Z,shanghai,shanghai,huangpu,d01,0,0,0,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:35.000Z,shanghai,shanghai,huangpu,d02,0,0,0,0,1,0,0,1,1,0,",
+ "2024-09-24T06:15:40.000Z,shanghai,shanghai,huangpu,d02,0,0,0,1,0,0,0,1,1,1,",
+ "2024-09-24T06:15:50.000Z,shanghai,shanghai,huangpu,d02,1,0,0,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:30.000Z,shanghai,shanghai,huangpu,d03,1,1,0,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:35.000Z,shanghai,shanghai,huangpu,d03,0,0,0,1,0,0,0,1,1,1,",
+ "2024-09-24T06:15:40.000Z,shanghai,shanghai,huangpu,d03,0,0,1,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:45.000Z,shanghai,shanghai,huangpu,d03,1,1,0,1,0,0,0,1,1,0,",
+ "2024-09-24T06:15:50.000Z,shanghai,shanghai,huangpu,d03,1,0,1,0,0,0,0,1,1,0,",
+ "2024-09-24T06:15:30.000Z,shanghai,shanghai,huangpu,d04,1,0,0,0,1,0,0,1,1,1,",
+ "2024-09-24T06:15:40.000Z,shanghai,shanghai,huangpu,d04,1,1,0,0,0,0,0,1,1,0,",
+ "2024-09-24T06:15:55.000Z,shanghai,shanghai,huangpu,d04,0,0,0,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:30.000Z,shanghai,shanghai,pudong,d05,0,0,0,0,0,1,0,0,1,0,",
+ "2024-09-24T06:15:35.000Z,shanghai,shanghai,pudong,d05,1,1,1,1,0,1,0,1,1,1,",
+ "2024-09-24T06:15:40.000Z,shanghai,shanghai,pudong,d05,0,0,1,0,1,0,0,1,1,0,",
+ "2024-09-24T06:15:50.000Z,shanghai,shanghai,pudong,d05,1,0,0,0,0,0,0,1,1,1,",
+ "2024-09-24T06:15:55.000Z,shanghai,shanghai,pudong,d05,0,0,0,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:35.000Z,shanghai,shanghai,pudong,d06,0,0,0,0,1,1,1,1,1,0,",
+ "2024-09-24T06:15:40.000Z,shanghai,shanghai,pudong,d06,0,0,0,1,0,0,0,1,1,1,",
+ "2024-09-24T06:15:50.000Z,shanghai,shanghai,pudong,d06,1,0,0,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:30.000Z,shanghai,shanghai,pudong,d07,1,1,0,0,0,0,0,0,1,0,",
+ "2024-09-24T06:15:35.000Z,shanghai,shanghai,pudong,d07,0,0,0,1,0,0,0,1,1,1,",
+ "2024-09-24T06:15:40.000Z,shanghai,shanghai,pudong,d07,0,0,1,0,0,1,0,0,1,0,",
+ "2024-09-24T06:15:45.000Z,shanghai,shanghai,pudong,d07,1,1,0,1,0,0,0,1,1,0,",
+ "2024-09-24T06:15:50.000Z,shanghai,shanghai,pudong,d07,1,0,1,0,0,1,0,1,1,0,",
+ "2024-09-24T06:15:30.000Z,shanghai,shanghai,pudong,d08,1,0,0,0,1,0,0,1,1,1,",
+ "2024-09-24T06:15:40.000Z,shanghai,shanghai,pudong,d08,1,1,0,0,0,0,0,1,1,0,",
+ "2024-09-24T06:15:55.000Z,shanghai,shanghai,pudong,d08,0,0,0,0,0,1,0,0,1,0,",
+ };
+ tableResultSetEqualTest(
+ "select date_bin(5s, time),province,city,region,device_id, count_if(s1 is null), count_if(s2 < 50000), count_if(s3 > 30), count_if(s4 < 55), count_if(s5), count_if(s6 like '%pudong%'), count_if(s7 = 'shanghai_pudong_red_B_d06_36'), count_if(s8 is null), count(s9 is null), count_if(s10 is not null) from table1 group by 1,2,3,4,5 order by 2,3,4,5,1",
+ expectedHeader, retArray, DATABASE_NAME);
+
+ expectedHeader =
+ new String[] {
+ "province",
+ "city",
+ "region",
+ "device_id",
+ "_col4",
+ "_col5",
+ "_col6",
+ "_col7",
+ "_col8",
+ "_col9",
+ "_col10",
+ "_col11",
+ "_col12",
+ "_col13"
+ };
+ retArray =
+ new String[] {
+ "beijing,beijing,chaoyang,d09,2,1,2,1,1,0,0,3,5,2,",
+ "beijing,beijing,chaoyang,d10,1,0,0,1,1,0,0,2,3,1,",
+ "beijing,beijing,chaoyang,d11,3,2,2,2,0,0,0,3,5,1,",
+ "beijing,beijing,chaoyang,d12,2,1,0,0,1,0,0,2,3,1,",
+ "beijing,beijing,haidian,d13,2,1,2,1,1,0,0,3,5,2,",
+ "beijing,beijing,haidian,d14,1,0,0,1,1,0,0,2,3,1,",
+ "beijing,beijing,haidian,d15,3,2,2,2,0,0,0,3,5,1,",
+ "beijing,beijing,haidian,d16,2,1,0,0,1,0,0,2,3,1,",
+ "shanghai,shanghai,huangpu,d01,2,1,2,1,1,0,0,3,5,2,",
+ "shanghai,shanghai,huangpu,d02,1,0,0,1,1,0,0,2,3,1,",
+ "shanghai,shanghai,huangpu,d03,3,2,2,2,0,0,0,3,5,1,",
+ "shanghai,shanghai,huangpu,d04,2,1,0,0,1,0,0,2,3,1,",
+ "shanghai,shanghai,pudong,d05,2,1,2,1,1,2,0,3,5,2,",
+ "shanghai,shanghai,pudong,d06,1,0,0,1,1,1,1,2,3,1,",
+ "shanghai,shanghai,pudong,d07,3,2,2,2,0,2,0,3,5,1,",
+ "shanghai,shanghai,pudong,d08,2,1,0,0,1,1,0,2,3,1,",
+ };
+ tableResultSetEqualTest(
+ "select province,city,region,device_id, count_if(s1 is null), count_if(s2 < 50000), count_if(s3 > 30), count_if(s4 < 55), count_if(s5), count_if(s6 like '%pudong%'), count_if(s7 = 'shanghai_pudong_red_B_d06_36'), count_if(s8 is null), count(s9 is null), count_if(s10 is not null) from table1 group by 1,2,3,4 order by 1,2,3,4",
+ expectedHeader, retArray, DATABASE_NAME);
+
+ expectedHeader = new String[] {"province", "city", "region", "_col3"};
+ retArray =
+ new String[] {
+ "beijing,beijing,chaoyang,5,",
+ "beijing,beijing,haidian,5,",
+ "shanghai,shanghai,huangpu,5,",
+ "shanghai,shanghai,pudong,5,",
+ };
+ tableResultSetEqualTest(
+ "select province,city,region,count(s3 > 30 and s4 < 55) from table1 group by 1,2,3 order by 1,2,3",
+ expectedHeader,
+ retArray,
+ DATABASE_NAME);
+
+ expectedHeader = new String[] {"province", "_col1"};
+ retArray =
+ new String[] {
+ "beijing,6,", "shanghai,6,",
+ };
+ tableResultSetEqualTest(
+ "select province,count_if(s5) from table1 group by 1 order by 1",
+ expectedHeader,
+ retArray,
+ DATABASE_NAME);
+
+ assertTestFail(
+ "select count_if(device_id) from table1",
+ "700: Error occurred while parsing SQL to physical plan: line 1:32 no viable alternative at input 'select count_if(device_id) from table1");
+
+ assertTestFail(
+ "select count_if(s5, device_id != 'd01') from table1",
+ "700: Error occurred while parsing SQL to physical plan: line 1:45 no viable alternative at input 'select count_if(s5, device_id != 'd01') from table1'");
+ }
Review Comment:
the error msg should be actually what you throw in `TableMetadataImpl`, the reason that you got this is that you use the `tree` model function, so this will fail in the very early stage(antlr throw that).
Instead you should use `tableAssertTestFail`.
--
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: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add aggregate function count_if for relational table [iotdb]
Posted by "JackieTien97 (via GitHub)" <gi...@apache.org>.
JackieTien97 merged PR #14511:
URL: https://github.com/apache/iotdb/pull/14511
--
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: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add aggregate function count_if for relational table [iotdb]
Posted by "JackieTien97 (via GitHub)" <gi...@apache.org>.
JackieTien97 commented on code in PR #14511:
URL: https://github.com/apache/iotdb/pull/14511#discussion_r1894728712
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java:
##########
@@ -567,6 +567,7 @@ && isIntegerNumber(argumentTypes.get(2)))) {
case SqlConstant.MIN:
case SqlConstant.MAX:
case SqlConstant.MODE:
+ case SqlConstant.COUNT_IF:
Review Comment:
the type of argument should be boolean?
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/CountIfAccumulator.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.file.metadata.statistics.Statistics;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.Collections;
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.tsfile.enums.TSDataType.BOOLEAN;
+
+public class CountIfAccumulator implements TableAccumulator {
+ private static final long INSTANCE_SIZE =
+ RamUsageEstimator.shallowSizeOfInstance(CountIfAccumulator.class);
+
+ private long countState = 0;
+
+ public CountIfAccumulator(List<TSDataType> seriesDataType) {
+ checkArgument(
+ seriesDataType.size() == 1 && seriesDataType.get(0) == BOOLEAN,
+ "argument of count_if should be one boolean expression");
+ }
+
+ @Override
+ public long getEstimatedSize() {
+ return INSTANCE_SIZE;
+ }
+
+ @Override
+ public TableAccumulator copy() {
+ return new CountIfAccumulator(Collections.singletonList(BOOLEAN));
+ }
+
+ @Override
+ public void addInput(Column[] arguments) {
+ int count = arguments[0].getPositionCount();
+ for (int i = 0; i < count; i++) {
+ if (arguments[0].getBoolean(i)) {
+ countState++;
+ }
+ }
+ }
+
+ @Override
+ public void addIntermediate(Column argument) {
+ for (int i = 0; i < argument.getPositionCount(); i++) {
+ if (argument.isNull(i)) {
+ continue;
+ }
+ countState += argument.getLong(i);
+ }
+ }
+
+ @Override
+ public void evaluateIntermediate(ColumnBuilder columnBuilder) {
+ columnBuilder.writeLong(countState);
+ }
+
+ @Override
+ public void evaluateFinal(ColumnBuilder columnBuilder) {
+ columnBuilder.writeLong(countState);
+ }
+
+ @Override
+ public boolean hasFinalResult() {
+ return false;
+ }
+
+ @Override
+ public void removeInput(Column[] arguments) {
+ for (int i = 0; i < arguments[0].getPositionCount(); i++) {
+ if (arguments[0].getBoolean(i)) {
Review Comment:
```suggestion
if (!arguments[0].isNull(i) && arguments[0].getBoolean(i)) {
```
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/AccumulatorFactory.java:
##########
@@ -149,6 +150,8 @@ private static GroupedAccumulator createBuiltinGroupedAccumulator(
switch (aggregationType) {
case COUNT:
return new GroupedCountAccumulator();
+ case COUNT_IF:
+ return new GroupedCountIfAccumulator(inputDataTypes);
Review Comment:
```suggestion
return new GroupedCountIfAccumulator();
```
##########
integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java:
##########
@@ -433,6 +433,327 @@ public void countTest() {
tableResultSetEqualTest("select count(*) from table1", expectedHeader, retArray, DATABASE_NAME);
}
+ @Test
+ public void countIfTest() {
Review Comment:
also need to add some extra unexpected exception test, like:
1. input expression is not boolean type
2. number of input expressions are not only 1
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/grouped/GroupedCountIfAccumulator.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.grouped;
+
+import org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.grouped.array.LongBigArray;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.tsfile.enums.TSDataType.BOOLEAN;
+
+public class GroupedCountIfAccumulator implements GroupedAccumulator {
+ private final LongBigArray countValues = new LongBigArray(0L);
+
+ private static final long INSTANCE_SIZE =
+ RamUsageEstimator.shallowSizeOfInstance(GroupedCountIfAccumulator.class);
+
+ public GroupedCountIfAccumulator(List<TSDataType> seriesDataType) {
+ checkArgument(
+ seriesDataType.size() == 1 && seriesDataType.get(0) == BOOLEAN,
+ "argument of count_if should be one boolean expression");
+ }
+
+ @Override
+ public long getEstimatedSize() {
+ return INSTANCE_SIZE + countValues.sizeOf();
+ }
+
+ @Override
+ public void setGroupCount(long groupCount) {
+ countValues.ensureCapacity(groupCount);
+ }
+
+ @Override
+ public void addInput(int[] groupIds, Column[] arguments) {
+ for (int i = 0; i < groupIds.length; i++) {
+ if (arguments[0].getBoolean(i)) {
Review Comment:
firstly should check the nullability of arguments by if (arguments[0].isNull(i))
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/grouped/GroupedCountIfAccumulator.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.grouped;
+
+import org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.grouped.array.LongBigArray;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.tsfile.enums.TSDataType.BOOLEAN;
+
+public class GroupedCountIfAccumulator implements GroupedAccumulator {
+ private final LongBigArray countValues = new LongBigArray(0L);
+
+ private static final long INSTANCE_SIZE =
+ RamUsageEstimator.shallowSizeOfInstance(GroupedCountIfAccumulator.class);
+
+ public GroupedCountIfAccumulator(List<TSDataType> seriesDataType) {
Review Comment:
don't need to pass `seriesDataType` here, you should check data type in the analyze phase.
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/CountIfAccumulator.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.file.metadata.statistics.Statistics;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.Collections;
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.tsfile.enums.TSDataType.BOOLEAN;
+
+public class CountIfAccumulator implements TableAccumulator {
+ private static final long INSTANCE_SIZE =
+ RamUsageEstimator.shallowSizeOfInstance(CountIfAccumulator.class);
+
+ private long countState = 0;
+
+ public CountIfAccumulator(List<TSDataType> seriesDataType) {
+ checkArgument(
+ seriesDataType.size() == 1 && seriesDataType.get(0) == BOOLEAN,
+ "argument of count_if should be one boolean expression");
+ }
+
+ @Override
+ public long getEstimatedSize() {
+ return INSTANCE_SIZE;
+ }
+
+ @Override
+ public TableAccumulator copy() {
+ return new CountIfAccumulator(Collections.singletonList(BOOLEAN));
+ }
+
+ @Override
+ public void addInput(Column[] arguments) {
+ int count = arguments[0].getPositionCount();
+ for (int i = 0; i < count; i++) {
+ if (arguments[0].getBoolean(i)) {
Review Comment:
```suggestion
if (!arguments[0].isNull(i) && arguments[0].getBoolean(i)) {
```
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/CountIfAccumulator.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.file.metadata.statistics.Statistics;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.Collections;
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.tsfile.enums.TSDataType.BOOLEAN;
+
+public class CountIfAccumulator implements TableAccumulator {
+ private static final long INSTANCE_SIZE =
+ RamUsageEstimator.shallowSizeOfInstance(CountIfAccumulator.class);
+
+ private long countState = 0;
+
+ public CountIfAccumulator(List<TSDataType> seriesDataType) {
+ checkArgument(
+ seriesDataType.size() == 1 && seriesDataType.get(0) == BOOLEAN,
+ "argument of count_if should be one boolean expression");
+ }
+
+ @Override
+ public long getEstimatedSize() {
+ return INSTANCE_SIZE;
+ }
+
+ @Override
+ public TableAccumulator copy() {
+ return new CountIfAccumulator(Collections.singletonList(BOOLEAN));
+ }
+
+ @Override
+ public void addInput(Column[] arguments) {
+ int count = arguments[0].getPositionCount();
+ for (int i = 0; i < count; i++) {
+ if (arguments[0].getBoolean(i)) {
+ countState++;
+ }
+ }
+ }
+
+ @Override
+ public void addIntermediate(Column argument) {
+ for (int i = 0; i < argument.getPositionCount(); i++) {
+ if (argument.isNull(i)) {
+ continue;
+ }
+ countState += argument.getLong(i);
+ }
+ }
+
+ @Override
+ public void evaluateIntermediate(ColumnBuilder columnBuilder) {
+ columnBuilder.writeLong(countState);
+ }
+
+ @Override
+ public void evaluateFinal(ColumnBuilder columnBuilder) {
+ columnBuilder.writeLong(countState);
+ }
+
+ @Override
+ public boolean hasFinalResult() {
+ return false;
+ }
+
+ @Override
+ public void removeInput(Column[] arguments) {
+ for (int i = 0; i < arguments[0].getPositionCount(); i++) {
+ if (arguments[0].getBoolean(i)) {
+ countState--;
+ }
+ }
+ }
+
+ @Override
+ public void addStatistics(Statistics[] statistics) {}
Review Comment:
better to throw unsupported exception if we don't plan to support push down count_if into scan
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/CountIfAccumulator.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.file.metadata.statistics.Statistics;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.Collections;
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.tsfile.enums.TSDataType.BOOLEAN;
+
+public class CountIfAccumulator implements TableAccumulator {
+ private static final long INSTANCE_SIZE =
+ RamUsageEstimator.shallowSizeOfInstance(CountIfAccumulator.class);
+
+ private long countState = 0;
+
+ public CountIfAccumulator(List<TSDataType> seriesDataType) {
Review Comment:
don't need to pass `seriesDataType` here, you should check data type in the analyze phase.
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/grouped/GroupedCountIfAccumulator.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.grouped;
+
+import org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.grouped.array.LongBigArray;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.tsfile.enums.TSDataType.BOOLEAN;
+
+public class GroupedCountIfAccumulator implements GroupedAccumulator {
+ private final LongBigArray countValues = new LongBigArray(0L);
+
+ private static final long INSTANCE_SIZE =
+ RamUsageEstimator.shallowSizeOfInstance(GroupedCountIfAccumulator.class);
+
+ public GroupedCountIfAccumulator(List<TSDataType> seriesDataType) {
+ checkArgument(
+ seriesDataType.size() == 1 && seriesDataType.get(0) == BOOLEAN,
+ "argument of count_if should be one boolean expression");
+ }
+
+ @Override
+ public long getEstimatedSize() {
+ return INSTANCE_SIZE + countValues.sizeOf();
+ }
+
+ @Override
+ public void setGroupCount(long groupCount) {
+ countValues.ensureCapacity(groupCount);
+ }
+
+ @Override
+ public void addInput(int[] groupIds, Column[] arguments) {
+ for (int i = 0; i < groupIds.length; i++) {
+ if (arguments[0].getBoolean(i)) {
Review Comment:
```suggestion
if (!arguments[0].isNull(i) && arguments[0].getBoolean(i)) {
```
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/CountIfAccumulator.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.file.metadata.statistics.Statistics;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.Collections;
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.tsfile.enums.TSDataType.BOOLEAN;
+
+public class CountIfAccumulator implements TableAccumulator {
+ private static final long INSTANCE_SIZE =
+ RamUsageEstimator.shallowSizeOfInstance(CountIfAccumulator.class);
+
+ private long countState = 0;
+
+ public CountIfAccumulator(List<TSDataType> seriesDataType) {
+ checkArgument(
+ seriesDataType.size() == 1 && seriesDataType.get(0) == BOOLEAN,
+ "argument of count_if should be one boolean expression");
+ }
+
+ @Override
+ public long getEstimatedSize() {
+ return INSTANCE_SIZE;
+ }
+
+ @Override
+ public TableAccumulator copy() {
+ return new CountIfAccumulator(Collections.singletonList(BOOLEAN));
+ }
+
+ @Override
+ public void addInput(Column[] arguments) {
+ int count = arguments[0].getPositionCount();
+ for (int i = 0; i < count; i++) {
+ if (arguments[0].getBoolean(i)) {
+ countState++;
+ }
+ }
+ }
+
+ @Override
+ public void addIntermediate(Column argument) {
+ for (int i = 0; i < argument.getPositionCount(); i++) {
+ if (argument.isNull(i)) {
+ continue;
+ }
+ countState += argument.getLong(i);
+ }
+ }
+
+ @Override
+ public void evaluateIntermediate(ColumnBuilder columnBuilder) {
+ columnBuilder.writeLong(countState);
+ }
+
+ @Override
+ public void evaluateFinal(ColumnBuilder columnBuilder) {
+ columnBuilder.writeLong(countState);
+ }
+
+ @Override
+ public boolean hasFinalResult() {
+ return false;
+ }
+
+ @Override
+ public void removeInput(Column[] arguments) {
Review Comment:
you should also override `removable` method to return true.
--
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: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org