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

final clause #79

Merged
merged 1 commit into from
Feb 15, 2020
Merged

final clause #79

merged 1 commit into from
Feb 15, 2020

Conversation

sdrenn
Copy link

@sdrenn sdrenn commented Feb 10, 2020

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 92.109% when pulling 5534f3e on sdrenn:final-clause into 2f79283 on xzkostyan:master.

@xzkostyan xzkostyan merged commit 5a9f3bd into xzkostyan:master Feb 15, 2020
@xzkostyan
Copy link
Owner

Good job!

@xzkostyan xzkostyan mentioned this pull request Feb 15, 2020
@ods
Copy link
Contributor

ods commented May 15, 2020

How does it work for JOIN-s, select from what table will be FINAL-ized?

And why not just use standard SQLAlchemy way for such cases with_hint() method? It requires just 2 lines in compiler:

    def get_from_hint_text(self, table, text):
        return text

Usage:

table.select().with_hint(table, 'FINAL')

@xzkostyan
Copy link
Owner

It seems than FINAL clause makes sense only in selecting from single table with *mergetree engine.

According to docs FINAL clause should be rendered after FROM .... and before any JOINs.

Currently FINAL will be rendered after JOINs:

q1 = self.session.query(table.c.x).subquery()
q2 = self.session.query(table.c.x).subquery()

print(self.session.query(q1.c.x, q2.c.x).join(q2, q1.c.x == q2.c.x).final())
SELECT anon_1.x AS anon_1_x, anon_2.x AS anon_2_x FROM (SELECT t1.x AS x FROM t1) AS anon_1 INNER JOIN (SELECT t1.x AS x FROM t1) AS anon_2 ON anon_1.x = anon_2.x FINAL

Which is obviously incorrect. But even it will render in proper place ClickHouse server will throw error:

:) select * from (select number as x from system.numbers limit 10) as a final join (select number as x from system.numbers limit 10) as b on a.x = b.x;

SELECT *
FROM 
(
    SELECT number AS x
    FROM system.numbers
    LIMIT 10
) AS a
FINAL
INNER JOIN 
(
    SELECT number AS x
    FROM system.numbers
    LIMIT 10
) AS b ON a.x = b.x

Received exception from server (version 20.3.2):
Code: 181. DB::Exception: Received from localhost:9000. DB::Exception: Illegal FINAL. 

0 rows in set. Elapsed: 0.005 sec. 

In both cases we will get an error.

Yes, with_hint can be used for FINAL rendering. But it's designed for other purposes. It is flexible (I believe that hints are escaped) but imho .final() looks way more natural.

@ods
Copy link
Contributor

ods commented May 25, 2020

In both cases we will get an error.

It does work when properly formed. At least the following test passes: https://github.com/ods/aiochsa/blob/master/tests/test_execute.py#L306-L332

@xzkostyan
Copy link
Owner

Oh, I see. Now I understand your point. #95

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.

None yet

4 participants