prestodb / presto

The official home of the Presto distributed SQL query engine for big data
http://prestodb.io
Apache License 2.0
15.97k stars 5.35k forks source link

GROUPING SETS fails on struct columns with dot notation #23151

Open cploonker opened 2 months ago

cploonker commented 2 months ago

Your Environment

Expected Behavior

Following query to work without any errors

SELECT pr.name as name, MAX(pr.age) as age, MAX(city) as city
FROM (
  SELECT CAST(pr AS ROW(name VARCHAR, age int)) as pr, city
  FROM(
    VALUES 
      (ROW('John Doe', 30), 'New York'),
      (ROW('Jane Doe', 25), 'Los Angeles')
  ) AS t(pr, city)
)
GROUP BY GROUPING SETS (pr.name)

Current Behavior

Following query works

SELECT pr.name as name, MAX(pr.age) as age, MAX(city) as city
FROM (
  SELECT CAST(pr AS ROW(name VARCHAR, age int)) as pr, city
  FROM(
    VALUES 
      (ROW('John Doe', 30), 'New York'),
      (ROW('Jane Doe', 25), 'Los Angeles')
  ) AS t(pr, city)
)
GROUP BY pr.name

However following query fails

SELECT pr.name as name, MAX(pr.age) as age, MAX(city) as city
FROM (
  SELECT CAST(pr AS ROW(name VARCHAR, age int)) as pr, city
  FROM(
    VALUES 
      (ROW('John Doe', 30), 'New York'),
      (ROW('Jane Doe', 25), 'Los Angeles')
  ) AS t(pr, city)
)
GROUP BY GROUPING SETS (pr.name)

Error

Error(type=USER_ERROR, name=INVALID_COLUMN_REFERENCE, message="line 11:26: GROUP BY expression must be a column reference: pr.name

Shouldn't both work?

Possible Solution

Steps to Reproduce

1. 2. 3. 4.

Screenshots (if appropriate)

Context

Unable to use grouping sets with struct columns

cploonker commented 2 months ago

@kaikalur Could you please share your thoughts on this bug. Also if you could please tag the right people. thanks

cploonker commented 2 months ago

Trino has the same issue: https://github.com/trinodb/trino/issues/22604