You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/11/17 19:20:30 UTC

[GitHub] [pinot] walterddr opened a new pull request, #9826: [multistage][test] add with statement test

walterddr opened a new pull request, #9826:
URL: https://github.com/apache/pinot/pull/9826

   from PostgresQL doc [section 7.8.1](https://www.postgresql.org/docs/15/queries-with.html)


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] siddharthteotia commented on a diff in pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
siddharthteotia commented on code in PR #9826:
URL: https://github.com/apache/pinot/pull/9826#discussion_r1027797276


##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", 3],
+          ["b", 2],
+          ["c", 5],
+          ["a", 1]
+        ]
+      },
+      "tbl2": {
+        "schema": [
+          {"name": "strCol1", "type": "STRING"},
+          {"name": "strCol2", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", "foo", 1],
+          ["a", "bar", 2],
+          ["b", "alice", 42],
+          ["b", "bob", 196883]
+        ]
+      }
+    },
+    "queries": [
+      {
+        "description": "single with with group by",
+        "sql": "WITH w AS ( SELECT strCol, SUM(intCol) AS sumRes FROM {tbl1} GROUP BY strCol ) SELECT strCol, strCol2, sumRes FROM w JOIN {tbl2} ON w.strCol = {tbl2}.strCol1",
+        "outputs": [
+          ["a", "foo", 4],
+          ["a", "bar", 4],
+          ["b", "alice", 2],
+          ["b", "bob", 2]
+        ]
+      },
+      {
+        "description": "multi with table",
+        "sql": "WITH agg1 AS ( SELECT strCol, sum(intCol) AS sumVal FROM {tbl1} GROUP BY strCol), agg2 AS (SELECT strCol1, avg(intCol) AS avgVal FROM {tbl2} GROUP BY strCol1) SELECT strCol, sumVal - avgVal FROM agg1, agg2 WHERE agg1.strCol = agg2.strCol1",
+        "outputs": [
+          ["a", 3],
+          ["b", -98460]
+        ]
+      },
+      {
+        "description": "with collapse into single query",
+        "sql": "WITH can_collapse AS ( SELECT strCol, intCol FROM {tbl1} ) SELECT * FROM can_collapse WHERE intCol > 2",
+        "outputs": [
+          ["a", 3],
+          ["c", 5]
+        ]
+      },
+      {
+        "description": "with statement table being reused multiple times",

Review Comment:
   May be we can call this nested CTE ?



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] siddharthteotia commented on a diff in pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
siddharthteotia commented on code in PR #9826:
URL: https://github.com/apache/pinot/pull/9826#discussion_r1027801868


##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", 3],
+          ["b", 2],
+          ["c", 5],
+          ["a", 1]
+        ]
+      },
+      "tbl2": {
+        "schema": [
+          {"name": "strCol1", "type": "STRING"},
+          {"name": "strCol2", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", "foo", 1],
+          ["a", "bar", 2],
+          ["b", "alice", 42],
+          ["b", "bob", 196883]
+        ]
+      }
+    },
+    "queries": [
+      {
+        "description": "single with with group by",
+        "sql": "WITH w AS ( SELECT strCol, SUM(intCol) AS sumRes FROM {tbl1} GROUP BY strCol ) SELECT strCol, strCol2, sumRes FROM w JOIN {tbl2} ON w.strCol = {tbl2}.strCol1",
+        "outputs": [
+          ["a", "foo", 4],
+          ["a", "bar", 4],
+          ["b", "alice", 2],
+          ["b", "bob", 2]
+        ]
+      },
+      {
+        "description": "multi with table",
+        "sql": "WITH agg1 AS ( SELECT strCol, sum(intCol) AS sumVal FROM {tbl1} GROUP BY strCol), agg2 AS (SELECT strCol1, avg(intCol) AS avgVal FROM {tbl2} GROUP BY strCol1) SELECT strCol, sumVal - avgVal FROM agg1, agg2 WHERE agg1.strCol = agg2.strCol1",
+        "outputs": [
+          ["a", 3],
+          ["b", -98460]
+        ]
+      },
+      {
+        "description": "with collapse into single query",
+        "sql": "WITH can_collapse AS ( SELECT strCol, intCol FROM {tbl1} ) SELECT * FROM can_collapse WHERE intCol > 2",
+        "outputs": [
+          ["a", 3],
+          ["c", 5]
+        ]
+      },
+      {
+        "description": "with statement table being reused multiple times",
+        "sql": "WITH reused AS ( SELECT strCol, intCol FROM {tbl1} ) SELECT a.strCol, a.intCol, b.intCol FROM reused AS a JOIN reused AS b ON a.strCol = b.strCol WHERE b.intCol > ( SELECT AVG(intCol) FROM reused )",

Review Comment:
   Shall we add test for RECURSIVE CTE as well ?



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] siddharthteotia commented on a diff in pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
siddharthteotia commented on code in PR #9826:
URL: https://github.com/apache/pinot/pull/9826#discussion_r1027718283


##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", 3],
+          ["b", 2],
+          ["c", 5],
+          ["a", 1]
+        ]
+      },
+      "tbl2": {
+        "schema": [
+          {"name": "strCol1", "type": "STRING"},
+          {"name": "strCol2", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", "foo", 1],
+          ["a", "bar", 2],
+          ["b", "alice", 42],
+          ["b", "bob", 196883]
+        ]
+      }
+    },
+    "queries": [
+      {
+        "description": "single with with group by",
+        "sql": "WITH w AS ( SELECT strCol, SUM(intCol) AS sumRes FROM {tbl1} GROUP BY strCol ) SELECT strCol, strCol2, sumRes FROM w JOIN {tbl2} ON w.strCol = {tbl2}.strCol1",

Review Comment:
   Basically I think `WITH` can serve for decoration as well (using self-join) where we want to enhance the result of a standard `GROUP BY` aggregation query on a table by projecting additional columns from the same table in the final result
   
   Something like ....
   
   ```
   WITH maxResult AS (
     SELECT
       groupCol1,
       groupCol2,
       MAX(aggCol) AS M
     FROM T
     GROUP BY groupCol1, groupCol2
   )
   SELECT T.*, maxResult.M -> projecting extra columns
    FROM T
    JOIN 
    maxResult
    ON 
    T.groupCol1 = maxResult.groupCol1
    AND 
    T.groupCol2 = maxResult.groupCol2
   ```



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] siddharthteotia commented on a diff in pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
siddharthteotia commented on code in PR #9826:
URL: https://github.com/apache/pinot/pull/9826#discussion_r1027718283


##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", 3],
+          ["b", 2],
+          ["c", 5],
+          ["a", 1]
+        ]
+      },
+      "tbl2": {
+        "schema": [
+          {"name": "strCol1", "type": "STRING"},
+          {"name": "strCol2", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", "foo", 1],
+          ["a", "bar", 2],
+          ["b", "alice", 42],
+          ["b", "bob", 196883]
+        ]
+      }
+    },
+    "queries": [
+      {
+        "description": "single with with group by",
+        "sql": "WITH w AS ( SELECT strCol, SUM(intCol) AS sumRes FROM {tbl1} GROUP BY strCol ) SELECT strCol, strCol2, sumRes FROM w JOIN {tbl2} ON w.strCol = {tbl2}.strCol1",

Review Comment:
   Basically I think `WITH` can serve for decoration as well (using self-join) where we want to enhance the result of a standard `GROUP BY` aggregation query on a table by projecting additional columns from the same table in the final result
   
   Something like ....
   
   ```
   WITH maxResult AS (
     SELECT
       groupCol1,
       groupCol2,
       MAX(aggCol) AS M
     FROM T
     GROUP BY groupCol1, groupCol2
   )
   SELECT T.*, maxResult.M -> projecting extra columns which is otherwise not possible in GROUP BY agg query
    FROM T
    JOIN 
    maxResult
    ON 
    T.groupCol1 = maxResult.groupCol1
    AND 
    T.groupCol2 = maxResult.groupCol2
   ```



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] codecov-commenter commented on pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #9826:
URL: https://github.com/apache/pinot/pull/9826#issuecomment-1319288136

   # [Codecov](https://codecov.io/gh/apache/pinot/pull/9826?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#9826](https://codecov.io/gh/apache/pinot/pull/9826?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (c4bc2aa) into [master](https://codecov.io/gh/apache/pinot/commit/73e6129941d5099e83a0ceca1eae388a38f6b8c4?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (73e6129) will **increase** coverage by `43.31%`.
   > The diff coverage is `n/a`.
   
   ```diff
   @@              Coverage Diff              @@
   ##             master    #9826       +/-   ##
   =============================================
   + Coverage     24.55%   67.86%   +43.31%     
   - Complexity       53     5253     +5200     
   =============================================
     Files          1952     1461      -491     
     Lines        104676    76336    -28340     
     Branches      15856    12144     -3712     
   =============================================
   + Hits          25700    51808    +26108     
   + Misses        76347    20857    -55490     
   - Partials       2629     3671     +1042     
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | integration2 | `?` | |
   | unittests1 | `67.86% <ø> (?)` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://codecov.io/gh/apache/pinot/pull/9826?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...va/org/apache/pinot/common/config/NettyConfig.java](https://codecov.io/gh/apache/pinot/pull/9826/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9jb21tb24vY29uZmlnL05ldHR5Q29uZmlnLmphdmE=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...a/org/apache/pinot/common/metrics/MinionMeter.java](https://codecov.io/gh/apache/pinot/pull/9826/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9jb21tb24vbWV0cmljcy9NaW5pb25NZXRlci5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...g/apache/pinot/common/metrics/ControllerMeter.java](https://codecov.io/gh/apache/pinot/pull/9826/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9jb21tb24vbWV0cmljcy9Db250cm9sbGVyTWV0ZXIuamF2YQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [.../apache/pinot/common/metrics/BrokerQueryPhase.java](https://codecov.io/gh/apache/pinot/pull/9826/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9jb21tb24vbWV0cmljcy9Ccm9rZXJRdWVyeVBoYXNlLmphdmE=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [.../apache/pinot/common/metrics/MinionQueryPhase.java](https://codecov.io/gh/apache/pinot/pull/9826/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9jb21tb24vbWV0cmljcy9NaW5pb25RdWVyeVBoYXNlLmphdmE=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...ache/pinot/server/access/AccessControlFactory.java](https://codecov.io/gh/apache/pinot/pull/9826/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VydmVyL2FjY2Vzcy9BY2Nlc3NDb250cm9sRmFjdG9yeS5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...he/pinot/common/messages/SegmentReloadMessage.java](https://codecov.io/gh/apache/pinot/pull/9826/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9jb21tb24vbWVzc2FnZXMvU2VnbWVudFJlbG9hZE1lc3NhZ2UuamF2YQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...he/pinot/common/messages/TableDeletionMessage.java](https://codecov.io/gh/apache/pinot/pull/9826/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9jb21tb24vbWVzc2FnZXMvVGFibGVEZWxldGlvbk1lc3NhZ2UuamF2YQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...pinot/core/data/manager/realtime/TimerService.java](https://codecov.io/gh/apache/pinot/pull/9826/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29yZS9kYXRhL21hbmFnZXIvcmVhbHRpbWUvVGltZXJTZXJ2aWNlLmphdmE=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...not/common/exception/HttpErrorStatusException.java](https://codecov.io/gh/apache/pinot/pull/9826/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9jb21tb24vZXhjZXB0aW9uL0h0dHBFcnJvclN0YXR1c0V4Y2VwdGlvbi5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | ... and [1709 more](https://codecov.io/gh/apache/pinot/pull/9826/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] 61yao commented on a diff in pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
61yao commented on code in PR #9826:
URL: https://github.com/apache/pinot/pull/9826#discussion_r1025878188


##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},

Review Comment:
   Can we add select .. from (With as x ( select from tbl)) 
   
   With a as (select .. from tbl) , b as (select .. from a), c as (select ... from  join a,b ) select .. from c. 



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] siddharthteotia commented on a diff in pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
siddharthteotia commented on code in PR #9826:
URL: https://github.com/apache/pinot/pull/9826#discussion_r1027797276


##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", 3],
+          ["b", 2],
+          ["c", 5],
+          ["a", 1]
+        ]
+      },
+      "tbl2": {
+        "schema": [
+          {"name": "strCol1", "type": "STRING"},
+          {"name": "strCol2", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", "foo", 1],
+          ["a", "bar", 2],
+          ["b", "alice", 42],
+          ["b", "bob", 196883]
+        ]
+      }
+    },
+    "queries": [
+      {
+        "description": "single with with group by",
+        "sql": "WITH w AS ( SELECT strCol, SUM(intCol) AS sumRes FROM {tbl1} GROUP BY strCol ) SELECT strCol, strCol2, sumRes FROM w JOIN {tbl2} ON w.strCol = {tbl2}.strCol1",
+        "outputs": [
+          ["a", "foo", 4],
+          ["a", "bar", 4],
+          ["b", "alice", 2],
+          ["b", "bob", 2]
+        ]
+      },
+      {
+        "description": "multi with table",
+        "sql": "WITH agg1 AS ( SELECT strCol, sum(intCol) AS sumVal FROM {tbl1} GROUP BY strCol), agg2 AS (SELECT strCol1, avg(intCol) AS avgVal FROM {tbl2} GROUP BY strCol1) SELECT strCol, sumVal - avgVal FROM agg1, agg2 WHERE agg1.strCol = agg2.strCol1",
+        "outputs": [
+          ["a", 3],
+          ["b", -98460]
+        ]
+      },
+      {
+        "description": "with collapse into single query",
+        "sql": "WITH can_collapse AS ( SELECT strCol, intCol FROM {tbl1} ) SELECT * FROM can_collapse WHERE intCol > 2",
+        "outputs": [
+          ["a", 3],
+          ["c", 5]
+        ]
+      },
+      {
+        "description": "with statement table being reused multiple times",

Review Comment:
   May be we can call this `nested CTE` ?



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] siddharthteotia commented on a diff in pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
siddharthteotia commented on code in PR #9826:
URL: https://github.com/apache/pinot/pull/9826#discussion_r1027801868


##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", 3],
+          ["b", 2],
+          ["c", 5],
+          ["a", 1]
+        ]
+      },
+      "tbl2": {
+        "schema": [
+          {"name": "strCol1", "type": "STRING"},
+          {"name": "strCol2", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", "foo", 1],
+          ["a", "bar", 2],
+          ["b", "alice", 42],
+          ["b", "bob", 196883]
+        ]
+      }
+    },
+    "queries": [
+      {
+        "description": "single with with group by",
+        "sql": "WITH w AS ( SELECT strCol, SUM(intCol) AS sumRes FROM {tbl1} GROUP BY strCol ) SELECT strCol, strCol2, sumRes FROM w JOIN {tbl2} ON w.strCol = {tbl2}.strCol1",
+        "outputs": [
+          ["a", "foo", 4],
+          ["a", "bar", 4],
+          ["b", "alice", 2],
+          ["b", "bob", 2]
+        ]
+      },
+      {
+        "description": "multi with table",
+        "sql": "WITH agg1 AS ( SELECT strCol, sum(intCol) AS sumVal FROM {tbl1} GROUP BY strCol), agg2 AS (SELECT strCol1, avg(intCol) AS avgVal FROM {tbl2} GROUP BY strCol1) SELECT strCol, sumVal - avgVal FROM agg1, agg2 WHERE agg1.strCol = agg2.strCol1",
+        "outputs": [
+          ["a", 3],
+          ["b", -98460]
+        ]
+      },
+      {
+        "description": "with collapse into single query",
+        "sql": "WITH can_collapse AS ( SELECT strCol, intCol FROM {tbl1} ) SELECT * FROM can_collapse WHERE intCol > 2",
+        "outputs": [
+          ["a", 3],
+          ["c", 5]
+        ]
+      },
+      {
+        "description": "with statement table being reused multiple times",
+        "sql": "WITH reused AS ( SELECT strCol, intCol FROM {tbl1} ) SELECT a.strCol, a.intCol, b.intCol FROM reused AS a JOIN reused AS b ON a.strCol = b.strCol WHERE b.intCol > ( SELECT AVG(intCol) FROM reused )",

Review Comment:
   Shall we add test for `RECURSIVE` CTE as well ? 
   
   `WITH RECURSIVE ...`



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] siddharthteotia commented on a diff in pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
siddharthteotia commented on code in PR #9826:
URL: https://github.com/apache/pinot/pull/9826#discussion_r1027784767


##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", 3],
+          ["b", 2],
+          ["c", 5],
+          ["a", 1]
+        ]
+      },
+      "tbl2": {
+        "schema": [
+          {"name": "strCol1", "type": "STRING"},
+          {"name": "strCol2", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", "foo", 1],
+          ["a", "bar", 2],
+          ["b", "alice", 42],
+          ["b", "bob", 196883]
+        ]
+      }
+    },
+    "queries": [
+      {
+        "description": "single with with group by",
+        "sql": "WITH w AS ( SELECT strCol, SUM(intCol) AS sumRes FROM {tbl1} GROUP BY strCol ) SELECT strCol, strCol2, sumRes FROM w JOIN {tbl2} ON w.strCol = {tbl2}.strCol1",
+        "outputs": [
+          ["a", "foo", 4],
+          ["a", "bar", 4],
+          ["b", "alice", 2],
+          ["b", "bob", 2]
+        ]
+      },
+      {
+        "description": "multi with table",
+        "sql": "WITH agg1 AS ( SELECT strCol, sum(intCol) AS sumVal FROM {tbl1} GROUP BY strCol), agg2 AS (SELECT strCol1, avg(intCol) AS avgVal FROM {tbl2} GROUP BY strCol1) SELECT strCol, sumVal - avgVal FROM agg1, agg2 WHERE agg1.strCol = agg2.strCol1",

Review Comment:
   In the outer query, can we also project individual aggregations computed in the respective CTEs and also try one more kind of a transform in outer query ? Something like following
   
   ```
   SELECT 
   strCol
   sumVal AS agg1_sum,
   avgVal AS agg2_avg,
   sumVal + avgVal,
   sumVal - avgVal
   FROM agg1, agg2
   WHERE agg1.strCol = agg2.strCol1
   ```
   
   Same or different query should be fine. 
   



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] siddharthteotia commented on a diff in pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
siddharthteotia commented on code in PR #9826:
URL: https://github.com/apache/pinot/pull/9826#discussion_r1027784767


##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", 3],
+          ["b", 2],
+          ["c", 5],
+          ["a", 1]
+        ]
+      },
+      "tbl2": {
+        "schema": [
+          {"name": "strCol1", "type": "STRING"},
+          {"name": "strCol2", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", "foo", 1],
+          ["a", "bar", 2],
+          ["b", "alice", 42],
+          ["b", "bob", 196883]
+        ]
+      }
+    },
+    "queries": [
+      {
+        "description": "single with with group by",
+        "sql": "WITH w AS ( SELECT strCol, SUM(intCol) AS sumRes FROM {tbl1} GROUP BY strCol ) SELECT strCol, strCol2, sumRes FROM w JOIN {tbl2} ON w.strCol = {tbl2}.strCol1",
+        "outputs": [
+          ["a", "foo", 4],
+          ["a", "bar", 4],
+          ["b", "alice", 2],
+          ["b", "bob", 2]
+        ]
+      },
+      {
+        "description": "multi with table",
+        "sql": "WITH agg1 AS ( SELECT strCol, sum(intCol) AS sumVal FROM {tbl1} GROUP BY strCol), agg2 AS (SELECT strCol1, avg(intCol) AS avgVal FROM {tbl2} GROUP BY strCol1) SELECT strCol, sumVal - avgVal FROM agg1, agg2 WHERE agg1.strCol = agg2.strCol1",

Review Comment:
   Can we also project other aggregations computed in the respective CTEs in the outer query and also try some other transform ? Something like following
   
   ```
   SELECT 
   strCol
   sumVal AS agg1_sum,
   avgVal AS agg2_avg,
   sumVal + avgVal,
   sumVal - avgVal
   FROM agg1, agg2
   WHERE agg1.strCol = agg2.strCol1
   ```
   
   Same or different query should be fine. 
   



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] siddharthteotia commented on pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
siddharthteotia commented on PR #9826:
URL: https://github.com/apache/pinot/pull/9826#issuecomment-1336269274

   Thanks for adding all the tests


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] walterddr commented on a diff in pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
walterddr commented on code in PR #9826:
URL: https://github.com/apache/pinot/pull/9826#discussion_r1025903603


##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},

Review Comment:
   could you be more specific?
   
   - `select .. from (With as x ( select from tbl))` is not a valid syntax.
   - `with (...) AS a, with (...) AS b SELECT (...) FROM ` is already added. did you meant you would like to nest the previously with tbl in another WITH? 



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] siddharthteotia commented on a diff in pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
siddharthteotia commented on code in PR #9826:
URL: https://github.com/apache/pinot/pull/9826#discussion_r1027707625


##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", 3],
+          ["b", 2],
+          ["c", 5],
+          ["a", 1]
+        ]
+      },
+      "tbl2": {
+        "schema": [
+          {"name": "strCol1", "type": "STRING"},
+          {"name": "strCol2", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", "foo", 1],
+          ["a", "bar", 2],
+          ["b", "alice", 42],
+          ["b", "bob", 196883]
+        ]
+      }
+    },
+    "queries": [
+      {
+        "description": "single with with group by",
+        "sql": "WITH w AS ( SELECT strCol, SUM(intCol) AS sumRes FROM {tbl1} GROUP BY strCol ) SELECT strCol, strCol2, sumRes FROM w JOIN {tbl2} ON w.strCol = {tbl2}.strCol1",

Review Comment:
   Can we add an example where the `JOIN` in outer query is done between `WITH` virtual table W and the same table (`tbl1`) used in `WITH` ?



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] siddharthteotia commented on a diff in pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
siddharthteotia commented on code in PR #9826:
URL: https://github.com/apache/pinot/pull/9826#discussion_r1027718283


##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", 3],
+          ["b", 2],
+          ["c", 5],
+          ["a", 1]
+        ]
+      },
+      "tbl2": {
+        "schema": [
+          {"name": "strCol1", "type": "STRING"},
+          {"name": "strCol2", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", "foo", 1],
+          ["a", "bar", 2],
+          ["b", "alice", 42],
+          ["b", "bob", 196883]
+        ]
+      }
+    },
+    "queries": [
+      {
+        "description": "single with with group by",
+        "sql": "WITH w AS ( SELECT strCol, SUM(intCol) AS sumRes FROM {tbl1} GROUP BY strCol ) SELECT strCol, strCol2, sumRes FROM w JOIN {tbl2} ON w.strCol = {tbl2}.strCol1",

Review Comment:
   Basically WITH can serve for decoration as well (using self-join) where we want to enhance the result of a standard GROUP BY aggregation query on a table with additional columns from the same table.
   
   Something like ....
   
   ```
   WITH maxResult AS (
     SELECT
       groupCol1,
       groupCol2,
       MAX(aggCol) AS M
     FROM T
     GROUP BY groupCol1, groupCol2
   )
   SELECT T.*, maxResult.M
    FROM T
    JOIN 
    maxResult
    ON 
    T.groupCol1 = maxResult.groupCol1
    AND 
    T.groupCol2 = maxResult.groupCol2
   ```



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] siddharthteotia commented on a diff in pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
siddharthteotia commented on code in PR #9826:
URL: https://github.com/apache/pinot/pull/9826#discussion_r1027784767


##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", 3],
+          ["b", 2],
+          ["c", 5],
+          ["a", 1]
+        ]
+      },
+      "tbl2": {
+        "schema": [
+          {"name": "strCol1", "type": "STRING"},
+          {"name": "strCol2", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", "foo", 1],
+          ["a", "bar", 2],
+          ["b", "alice", 42],
+          ["b", "bob", 196883]
+        ]
+      }
+    },
+    "queries": [
+      {
+        "description": "single with with group by",
+        "sql": "WITH w AS ( SELECT strCol, SUM(intCol) AS sumRes FROM {tbl1} GROUP BY strCol ) SELECT strCol, strCol2, sumRes FROM w JOIN {tbl2} ON w.strCol = {tbl2}.strCol1",
+        "outputs": [
+          ["a", "foo", 4],
+          ["a", "bar", 4],
+          ["b", "alice", 2],
+          ["b", "bob", 2]
+        ]
+      },
+      {
+        "description": "multi with table",
+        "sql": "WITH agg1 AS ( SELECT strCol, sum(intCol) AS sumVal FROM {tbl1} GROUP BY strCol), agg2 AS (SELECT strCol1, avg(intCol) AS avgVal FROM {tbl2} GROUP BY strCol1) SELECT strCol, sumVal - avgVal FROM agg1, agg2 WHERE agg1.strCol = agg2.strCol1",

Review Comment:
   In the outer query, can we also project individual aggregations computed in the respective CTEs and also try one more kind of a transform ? Something like following
   
   ```
   SELECT 
   strCol
   sumVal AS agg1_sum, -> project from CTE
   avgVal AS agg2_avg, -> project from CTE
   sumVal + avgVal, -> + transform
   sumVal - avgVal
   FROM agg1, agg2
   WHERE agg1.strCol = agg2.strCol1
   ```
   
   Same or different query should be fine. 
   



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] siddharthteotia commented on a diff in pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
siddharthteotia commented on code in PR #9826:
URL: https://github.com/apache/pinot/pull/9826#discussion_r1027718283


##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", 3],
+          ["b", 2],
+          ["c", 5],
+          ["a", 1]
+        ]
+      },
+      "tbl2": {
+        "schema": [
+          {"name": "strCol1", "type": "STRING"},
+          {"name": "strCol2", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", "foo", 1],
+          ["a", "bar", 2],
+          ["b", "alice", 42],
+          ["b", "bob", 196883]
+        ]
+      }
+    },
+    "queries": [
+      {
+        "description": "single with with group by",
+        "sql": "WITH w AS ( SELECT strCol, SUM(intCol) AS sumRes FROM {tbl1} GROUP BY strCol ) SELECT strCol, strCol2, sumRes FROM w JOIN {tbl2} ON w.strCol = {tbl2}.strCol1",

Review Comment:
   Basically I think `WITH` can serve for decoration as well (using self-join) where we want to enhance the result of a standard `GROUP BY` aggregation query on a table by projecting additional columns from the same table in the final result
   
   Something like ....
   
   ```
   WITH maxResult AS (
     SELECT
       groupCol1,
       groupCol2,
       MAX(aggCol) AS M
     FROM T
     GROUP BY groupCol1, groupCol2
   )
   SELECT T.*, maxResult.M
    FROM T
    JOIN 
    maxResult
    ON 
    T.groupCol1 = maxResult.groupCol1
    AND 
    T.groupCol2 = maxResult.groupCol2
   ```



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] siddharthteotia commented on a diff in pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
siddharthteotia commented on code in PR #9826:
URL: https://github.com/apache/pinot/pull/9826#discussion_r1027762638


##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", 3],
+          ["b", 2],
+          ["c", 5],
+          ["a", 1]
+        ]
+      },
+      "tbl2": {
+        "schema": [
+          {"name": "strCol1", "type": "STRING"},
+          {"name": "strCol2", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", "foo", 1],
+          ["a", "bar", 2],
+          ["b", "alice", 42],
+          ["b", "bob", 196883]
+        ]
+      }
+    },
+    "queries": [
+      {
+        "description": "single with with group by",
+        "sql": "WITH w AS ( SELECT strCol, SUM(intCol) AS sumRes FROM {tbl1} GROUP BY strCol ) SELECT strCol, strCol2, sumRes FROM w JOIN {tbl2} ON w.strCol = {tbl2}.strCol1",

Review Comment:
   Can we also add one example for transform inside agg.  ? 
   
   Here is a useful example in the context of a non JOIN query...
   
   ```
   WITH metricResult AS ( 
         SELECT 
            groupCol1, 
            groupCol2, 
            SUM(c1 * c2) AS metric 
         FROM T 
         GROUP BY groupCol1, groupCol2
   ) 
   SELECT 
     groupCol1,
     MAX(metricResult.metric)
     FROM metricResult
     GROUP BY groupCol1
     ORDER BY MAX(metricResult.metric) DESC
   ```



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] walterddr commented on a diff in pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
walterddr commented on code in PR #9826:
URL: https://github.com/apache/pinot/pull/9826#discussion_r1038436355


##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", 3],
+          ["b", 2],
+          ["c", 5],
+          ["a", 1]
+        ]
+      },
+      "tbl2": {
+        "schema": [
+          {"name": "strCol1", "type": "STRING"},
+          {"name": "strCol2", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", "foo", 1],
+          ["a", "bar", 2],
+          ["b", "alice", 42],
+          ["b", "bob", 196883]
+        ]
+      }
+    },
+    "queries": [
+      {
+        "description": "single with with group by",
+        "sql": "WITH w AS ( SELECT strCol, SUM(intCol) AS sumRes FROM {tbl1} GROUP BY strCol ) SELECT strCol, strCol2, sumRes FROM w JOIN {tbl2} ON w.strCol = {tbl2}.strCol1",

Review Comment:
   this is added



##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", 3],
+          ["b", 2],
+          ["c", 5],
+          ["a", 1]
+        ]
+      },
+      "tbl2": {
+        "schema": [
+          {"name": "strCol1", "type": "STRING"},
+          {"name": "strCol2", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", "foo", 1],
+          ["a", "bar", 2],
+          ["b", "alice", 42],
+          ["b", "bob", 196883]
+        ]
+      }
+    },
+    "queries": [
+      {
+        "description": "single with with group by",
+        "sql": "WITH w AS ( SELECT strCol, SUM(intCol) AS sumRes FROM {tbl1} GROUP BY strCol ) SELECT strCol, strCol2, sumRes FROM w JOIN {tbl2} ON w.strCol = {tbl2}.strCol1",
+        "outputs": [
+          ["a", "foo", 4],
+          ["a", "bar", 4],
+          ["b", "alice", 2],
+          ["b", "bob", 2]
+        ]
+      },
+      {
+        "description": "multi with table",
+        "sql": "WITH agg1 AS ( SELECT strCol, sum(intCol) AS sumVal FROM {tbl1} GROUP BY strCol), agg2 AS (SELECT strCol1, avg(intCol) AS avgVal FROM {tbl2} GROUP BY strCol1) SELECT strCol, sumVal - avgVal FROM agg1, agg2 WHERE agg1.strCol = agg2.strCol1",
+        "outputs": [
+          ["a", 3],
+          ["b", -98460]
+        ]
+      },
+      {
+        "description": "with collapse into single query",
+        "sql": "WITH can_collapse AS ( SELECT strCol, intCol FROM {tbl1} ) SELECT * FROM can_collapse WHERE intCol > 2",
+        "outputs": [
+          ["a", 3],
+          ["c", 5]
+        ]
+      },
+      {
+        "description": "with statement table being reused multiple times",
+        "sql": "WITH reused AS ( SELECT strCol, intCol FROM {tbl1} ) SELECT a.strCol, a.intCol, b.intCol FROM reused AS a JOIN reused AS b ON a.strCol = b.strCol WHERE b.intCol > ( SELECT AVG(intCol) FROM reused )",

Review Comment:
   added but it is not working



##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", 3],
+          ["b", 2],
+          ["c", 5],
+          ["a", 1]
+        ]
+      },
+      "tbl2": {
+        "schema": [
+          {"name": "strCol1", "type": "STRING"},
+          {"name": "strCol2", "type": "STRING"},
+          {"name": "intCol", "type": "INT"}
+        ],
+        "inputs": [
+          ["a", "foo", 1],
+          ["a", "bar", 2],
+          ["b", "alice", 42],
+          ["b", "bob", 196883]
+        ]
+      }
+    },
+    "queries": [
+      {
+        "description": "single with with group by",
+        "sql": "WITH w AS ( SELECT strCol, SUM(intCol) AS sumRes FROM {tbl1} GROUP BY strCol ) SELECT strCol, strCol2, sumRes FROM w JOIN {tbl2} ON w.strCol = {tbl2}.strCol1",
+        "outputs": [
+          ["a", "foo", 4],
+          ["a", "bar", 4],
+          ["b", "alice", 2],
+          ["b", "bob", 2]
+        ]
+      },
+      {
+        "description": "multi with table",
+        "sql": "WITH agg1 AS ( SELECT strCol, sum(intCol) AS sumVal FROM {tbl1} GROUP BY strCol), agg2 AS (SELECT strCol1, avg(intCol) AS avgVal FROM {tbl2} GROUP BY strCol1) SELECT strCol, sumVal - avgVal FROM agg1, agg2 WHERE agg1.strCol = agg2.strCol1",

Review Comment:
   added



##########
pinot-query-runtime/src/test/resources/queries/WithStatements.json:
##########
@@ -0,0 +1,81 @@
+{
+  "with_statement_tests": {
+    "psql": "7.8.1",
+    "tables": {
+      "tbl1": {
+        "schema": [
+          {"name": "strCol", "type": "STRING"},

Review Comment:
   this is added



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] walterddr merged pull request #9826: [multistage][test] add with statement test

Posted by GitBox <gi...@apache.org>.
walterddr merged PR #9826:
URL: https://github.com/apache/pinot/pull/9826


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org