Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WITH not behaving as expected #42

Closed
dwayneberry opened this issue Jul 7, 2017 · 3 comments
Closed

WITH not behaving as expected #42

dwayneberry opened this issue Jul 7, 2017 · 3 comments

Comments

@dwayneberry
Copy link
Contributor

I'm trying to use table expressions, eventually using them in joins but seem to be hitting limits. The following code snippets show the issue:

CREATE TABLE test (ts TIMESTAMP NOT NULL)

This is fine:

SELECT (EXTRACT(EPOCH FROM ts) / 60) * 60 start_time FROM test GROUP BY start_time;

As is:

SELECT * FROM (SELECT (EXTRACT(EPOCH FROM ts) / 60) * 60 start_time FROM test GROUP BY start_time);

However, the following fails:

WITH s AS (SELECT (EXTRACT(EPOCH FROM ts) / 60) * 60 start_time FROM test GROUP BY start_time) SELECT * FROM s
Exception: Validate failed: From line 3, column 10 to line 3, column 21: Column 'start_time' not found in any table

Similarly, I get the same error if I try to use the select expression in a join.

I can start to work round it by using:

WITH s AS (SELECT (EXTRACT(EPOCH FROM ts) / 60) * 60 FROM test GROUP BY ((EXTRACT(EPOCH FROM ts / 60) * 60)) SELECT EXPR$0 FROM s;

but is there a simpler/better way?

Thanks,

Julian

@dwayneberry
Copy link
Contributor Author

Hi,

I can reproduce your issue with WITH not sure what is going on there will need to investigate.

As a work around you can use a view

create view eview as SELECT (EXTRACT(EPOCH FROM ts) / 60) * 60 START_TIME FROM test GROUP BY START_TIME;

and query like

select start_time from eview;

hope this helps

regards

@dwayneberry
Copy link
Contributor Author

Additional info

this works:

 WITH s AS (SELECT (EXTRACT(EPOCH FROM ts) / 60) * 60 start_time FROM test GROUP BY (EXTRACT(EPOCH FROM ts) / 60) * 60) SELECT * FROM s;

The calcite process is losing something when as alias is used

@dwayneberry
Copy link
Contributor Author

closed with 9738335

andrewseidl pushed a commit that referenced this issue Oct 1, 2018
* Cleanup:  EMC++ Item #42

* fixup: use emplace_back when possible
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

No branches or pull requests

1 participant