fix: Remove 'FORMAT JSON' from CREATE, DROP, ALTER and RENAME statements#242
Conversation
|
Thanks @jspeedz! Clean fix, correct approach — DDL statements don't support FORMAT. Merging. |
|
@isublimity @jspeedz In the previous implementation, the condition correctly handled queries starting with With the changes introduced in this PR, this behavior appears to be broken — the mentioned query types are now handled incorrectly, which affects our existing logic. @jspeedz Could you please consider adjusting the implementation so that it:
It might make sense to refine or extend the condition to cover both scenarios. |
@iTearo I just wrote a test to confirm a |
|
@jspeedz To reproduce the issue, you can use a test like this: $sql = $this->client->write('DROP TABLE IF EXISTS tbl ON CLUSTER clstr')->sql();
$this->assertEquals('DROP TABLE IF EXISTS tbl ON CLUSTER clstr FORMAT JSON', $sql);This test passes on version 1.6.0, but fails on master with the following error: We use a ClickHouse cluster, so our queries always contain The |
@iTearo This is as intended. The test I did was within this repository, executing the statement on a clickhouse server instance running in docker, instead of comparing the final statement strings (maybe I should commit / PR this test). Input and output formats are not used/supported for these DDL statements. See https://clickhouse.com/docs/interfaces/formats The Do the statements actually fail when executing them on a clickhouse server? If so, it might be a different clickhouse version than I am using, maybe? |
@jspeedz Statements are executing without errors, but |
|
Bacause the response from clustered and standalone Clickhouse is differ |
|
I think support for both cases - yours and mine - could be implemented |
@iTearo Ah yes, I see what you mean now, thanks. This needs a new PR! How about something like this? This should fix the original issue with |
|
@jspeedz I think we can simply add a str_starts_with($sql, 'CREATE TABLE')
|| str_starts_with($sql, 'DROP TABLE')
|| str_starts_with($sql, 'ALTER TABLE')
|| str_starts_with($sql, 'RENAME TABLE') |
@iTearo This will change the current behaviour though. I'm not 100% familiar with all available statements. I would have to be sure statements like I'll have to find some time to make the changes and rewrite those tests to cover all scenarios / statements so we can be confident they all work. |
|
Hi @jspeedz Thanks for these changes. I found at least two more statements that currently fail because of the FORMAT JSON added at the end: GRANT and REVOKE. In my opinion, it would be better to add this only for queries/statements that actually support the format, rather than maintaining a denylist. What do you think? |
Removes 'FORMAT JSON' from CREATE, DROP, ALTER and RENAME statements when executing queries 'ON CLUSTER'.
Specifying output format is only supported for SELECT and INSERT statements.
See: https://clickhouse.com/docs/interfaces/formats
Fixes: #241
This PR differs from #214, which is stale / conflicts with the latest version.
This PR only inverts the logic that does not work as intended, it does not add an extra parameter to the write() method like #214.
This change/fix works for my particular use-case. But do not know if I am missing something. Please discuss if this is the correct fix. We might want to make the 'FORMAT JSON' forced format statement optional as in #214. Or maybe we should allow-list SELECT/INSERT statements instead of deny-listing.