Skip to content

[IOTDB-1024] Support multiple aggregated measurements for group by level statement#2714

Merged
HTHou merged 9 commits intoapache:masterfrom
wshao08:groupbylevel
Feb 23, 2021
Merged

[IOTDB-1024] Support multiple aggregated measurements for group by level statement#2714
HTHou merged 9 commits intoapache:masterfrom
wshao08:groupbylevel

Conversation

@wshao08
Copy link
Contributor

@wshao08 wshao08 commented Feb 21, 2021

Description

Currently, only one aggregated measurement is supported in this statement to avoid result ambiguity.
This PR is to support multiple aggregated measurements in group by level statement.

JIRA issue: https://issues.apache.org/jira/browse/IOTDB-1024

@HTHou
Copy link
Contributor

HTHou commented Feb 22, 2021

Don't forget to run Run mvn spotless:apply.

@HTHou HTHou linked an issue Feb 22, 2021 that may be closed by this pull request
Copy link
Contributor

@HTHou HTHou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried this feature and the result looks good.

IoTDB> insert into root.yuerj."30001"."client-521".d1.p1(time, errorQps, QPS) values(1,2,3)
Msg: The statement is executed successfully.
IoTDB> insert into root.yuerj."30001"."client-521".d1.p2(time, errorQps, QPS) values(1,2,3)
Msg: The statement is executed successfully.
IoTDB> insert into root.yuerj."30001"."client-521".d1.p3(time, errorQps, QPS) values(1,2,3)
Msg: The statement is executed successfully.
IoTDB> insert into root.yuerj."30001"."client-521".d2.p4(time, errorQps, QPS) values(1,2,3)
Msg: The statement is executed successfully.
IoTDB> insert into root.yuerj."30001"."client-521".d2.p2(time, errorQps, QPS) values(1,2,3)
Msg: The statement is executed successfully.
IoTDB> select sum(errorQps) , sum(QPS) from root.yuerj."30001"."client-521".*.* GROUP BY ([1970-01-01T08:00:00.000+08:00, 1970-01-01T08:00:00.900+08:00), 100ms) ,level=3
+-----------------------------+--------------------------------------------+-------------------------------------------------+
|                         Time|sum(root.yuerj."30001"."client-521".*.*.QPS)|sum(root.yuerj."30001"."client-521".*.*.errorQps)|
+-----------------------------+--------------------------------------------+-------------------------------------------------+
|1970-01-01T08:00:00.000+08:00|                                        15.0|                                             10.0|
|1970-01-01T08:00:00.100+08:00|                                         0.0|                                              0.0|
|1970-01-01T08:00:00.200+08:00|                                         0.0|                                              0.0|
|1970-01-01T08:00:00.300+08:00|                                         0.0|                                              0.0|
|1970-01-01T08:00:00.400+08:00|                                         0.0|                                              0.0|
|1970-01-01T08:00:00.500+08:00|                                         0.0|                                              0.0|
|1970-01-01T08:00:00.600+08:00|                                         0.0|                                              0.0|
|1970-01-01T08:00:00.700+08:00|                                         0.0|                                              0.0|
|1970-01-01T08:00:00.800+08:00|                                         0.0|                                              0.0|
+-----------------------------+--------------------------------------------+-------------------------------------------------+
Total line number = 9
It costs 0.030s

@HTHou HTHou added the 0.12.0 label Feb 22, 2021
@HTHou HTHou self-requested a review February 22, 2021 06:13
Copy link
Contributor

@HTHou HTHou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, the order of the results is not same with the sql statement. Is it normal?

@wshao08
Copy link
Contributor Author

wshao08 commented Feb 22, 2021

By the way, the order of the results is not same with the sql statement. Is it normal?

No, the printed column order is wrong. I will correct it soon.

@HTHou
Copy link
Contributor

HTHou commented Feb 22, 2021

The order is correct now, but the result of avg seems not correct, which shouldn't be null.

IoTDB> select sum(QPS),avg(QPS), sum(errorQps) from root.yuerj."30001"."client-521".*.* GROUP BY ([1970-01-01T08:00:00.000+08:00, 1970-01-01T08:00:00.900+08:00), 100ms) ,level=3
+-----------------------------+--------------------------------------------+--------------------------------------------+-------------------------------------------------+
|                         Time|sum(root.yuerj."30001"."client-521".*.*.QPS)|avg(root.yuerj."30001"."client-521".*.*.QPS)|sum(root.yuerj."30001"."client-521".*.*.errorQps)|
+-----------------------------+--------------------------------------------+--------------------------------------------+-------------------------------------------------+
|1970-01-01T08:00:00.000+08:00|                                        15.0|                                        null|                                             10.0|
|1970-01-01T08:00:00.100+08:00|                                         0.0|                                        null|                                              0.0|
|1970-01-01T08:00:00.200+08:00|                                         0.0|                                        null|                                              0.0|
|1970-01-01T08:00:00.300+08:00|                                         0.0|                                        null|                                              0.0|
|1970-01-01T08:00:00.400+08:00|                                         0.0|                                        null|                                              0.0|
|1970-01-01T08:00:00.500+08:00|                                         0.0|                                        null|                                              0.0|
|1970-01-01T08:00:00.600+08:00|                                         0.0|                                        null|                                              0.0|
|1970-01-01T08:00:00.700+08:00|                                         0.0|                                        null|                                              0.0|
|1970-01-01T08:00:00.800+08:00|                                         0.0|                                        null|                                              0.0|
+-----------------------------+--------------------------------------------+--------------------------------------------+-------------------------------------------------+
Total line number = 9
It costs 0.058s

Copy link
Contributor

@HTHou HTHou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now.

IoTDB> select sum(QPS),avg(QPS), sum(errorQps) from root.yuerj."30001"."client-521".*.* GROUP BY ([1970-01-01T08:00:00.000+08:00, 1970-01-01T08:00:00.900+08:00), 100ms) ,level=3
+-----------------------------+--------------------------------------------+--------------------------------------------+-------------------------------------------------+
|                         Time|sum(root.yuerj."30001"."client-521".*.*.QPS)|avg(root.yuerj."30001"."client-521".*.*.QPS)|sum(root.yuerj."30001"."client-521".*.*.errorQps)|
+-----------------------------+--------------------------------------------+--------------------------------------------+-------------------------------------------------+
|1970-01-01T08:00:00.000+08:00|                                        15.0|                          3.0000000000000004|                                             10.0|
|1970-01-01T08:00:00.100+08:00|                                         0.0|                                        null|                                              0.0|
|1970-01-01T08:00:00.200+08:00|                                         0.0|                                        null|                                              0.0|
|1970-01-01T08:00:00.300+08:00|                                         0.0|                                        null|                                              0.0|
|1970-01-01T08:00:00.400+08:00|                                         0.0|                                        null|                                              0.0|
|1970-01-01T08:00:00.500+08:00|                                         0.0|                                        null|                                              0.0|
|1970-01-01T08:00:00.600+08:00|                                         0.0|                                        null|                                              0.0|
|1970-01-01T08:00:00.700+08:00|                                         0.0|                                        null|                                              0.0|
|1970-01-01T08:00:00.800+08:00|                                         0.0|                                        null|                                              0.0|
+-----------------------------+--------------------------------------------+--------------------------------------------+-------------------------------------------------+
Total line number = 9
It costs 0.661s

@HTHou HTHou requested a review from Alima777 February 22, 2021 14:16
Comment on lines +881 to +886
String aggregatePath =
originalPath.isMeasurementAliasExists()
? FilePathUtils.generatePartialPathByLevel(
originalPath.getFullPathWithAlias(), ((AggregationPlan) queryPlan).getLevel())
: FilePathUtils.generatePartialPathByLevel(
originalPath.toString(), ((AggregationPlan) queryPlan).getLevel());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line 850, check the level and don't change the value of columnForReader. In this way, you can use the columnForReader directly here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The modified value of columnForReader is used between line 858-871. Considering the complexity of deduplicate(), I tried not to make much changes here to keep correctness.
Perhaps refactor deduplicate() and moving it into QueryPlan would be a choice. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay...but maybe we have to rewrite this method later...it's so long

@HTHou HTHou requested a review from Alima777 February 23, 2021 08:02
Comment on lines +881 to +886
String aggregatePath =
originalPath.isMeasurementAliasExists()
? FilePathUtils.generatePartialPathByLevel(
originalPath.getFullPathWithAlias(), ((AggregationPlan) queryPlan).getLevel())
: FilePathUtils.generatePartialPathByLevel(
originalPath.toString(), ((AggregationPlan) queryPlan).getLevel());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay...but maybe we have to rewrite this method later...it's so long

@HTHou HTHou merged commit 3aed578 into apache:master Feb 23, 2021
@wshao08 wshao08 deleted the groupbylevel branch February 23, 2021 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

按层级 sum 功能不支持多个字段的 sum 查询

3 participants