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

Allow writing table name as a string literal #52635

Merged

Conversation

hendrik-m
Copy link
Contributor

@hendrik-m hendrik-m commented Jul 26, 2023

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Add support for string literals as table name. Closes #52178

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

  • Motivation: Why is this function, table engine, etc. useful to ClickHouse users?
    Supporting string literals is more convenient to use as it does not require quoting.

  • Example use: A query or command.

clickhouse-local --query "SELECT * FROM 'dataset.avro'"

@CLAassistant
Copy link

CLAassistant commented Jul 26, 2023

CLA assistant check
All committers have signed the CLA.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jul 26, 2023
@tavplubix
Copy link
Member

Could you please update AST Fuzzer so it will replace table name identifiers with string literals sometimes?

@@ -188,6 +188,20 @@ bool ParserIdentifier::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
++pos;
return true;
}
else if (pos->type == TokenType::StringLiteral)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a complication: this code allows parsing a string literal as an identifier in every context. It can be undesirable. I expect to allow it only when we expect a table name.

ReadBufferFromMemory buf(pos->begin, pos->size());
String s;

readQuotedStringWithSQLStyle(s, buf);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a low-level function, but we also have ParserStringLiteral; maybe it will fit better.

@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-improvement Pull request with some product improvements label Jul 26, 2023
@robot-clickhouse-ci-2
Copy link
Contributor

robot-clickhouse-ci-2 commented Jul 26, 2023

This is an automated comment for commit b53084c with description of existing statuses. It's updated for the latest CI running
The full report is available here
The overall status of the commit is 🔴 failure

Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help🟢 success
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR🟢 success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process🟢 success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help🟢 success
Docker image for serversThe check to build and optionally push the mentioned image to docker hub🟢 success
Docs CheckBuilds and tests the documentation🟢 success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here🟢 success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integrational tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc🟢 success
Install packagesChecks that the built packages are installable in a clear environment🟢 success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests🟢 success
Mergeable CheckChecks if all other necessary checks are successful🟢 success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests🟢 success
Push to DockerhubThe check for building and pushing the CI related docker images to docker hub🟢 success
SQLancerFuzzing tests that detect logical bugs with SQLancer tool🟢 success
SqllogicRun clickhouse on the sqllogic test set against sqlite and checks that all statements are passed🟢 success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc🟢 success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc🔴 failure
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors🟢 success
Style CheckRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report🟢 success
Unit testsRuns the unit tests for different release types🟢 success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts🟢 success

@nikitamikhaylov
Copy link
Member

@hendrik-m Let's check tests failures.

@hendrik-m
Copy link
Contributor Author

Could you please update AST Fuzzer so it will replace table name identifiers with string literals sometimes?

I've checked and think this does not seem to be the right approach. In the AST the quotes are parsed and therefore gone. In order to fuzz quoting styles, the dump of the AST which happens here has to be extended to change the quoting style in FormatSettings at random. However the quoting style added for this PR only targets table names, so it gets a bit more complex:

  • add a writeTableIdentifier method to FormatSettings
  • add some indirection in ASTIdentifier::formatImplWithoutAlias so that ASTTableIdentifier calls writeTableIdentifier instead of writeIdentifier to write the table name
  • add a TableIdentifierQuotingStyle struct and option in FormatSettings which defaults to the same value used for IdentifierQuotingStyle, but allows an explicit overwrite to StringLiteral
  • extend formatForErrorMessage to optionally take FormatSettings (but disallow changing some of the essentials)
  • finally let fuzzing choose different quoting styles at random

@alexey-milovidov
Copy link
Member

Looks perfect :)

@alexey-milovidov alexey-milovidov self-assigned this Aug 3, 2023

```bash
./clickhouse local -q "SELECT * FROM file('reviews.tsv')"
./clickhouse-local -q "SELECT * FROM 'reviews.tsv'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JFYI, the reason why instead of clickhouse-local it was written as ./clickhouse local is as follows:

Our documentation engineers (all two of them) are using Mac.

In Mac, the ClickHouse installation script Install.cpp does not support creating symlinks and installing into /usr/bin/

But ClickHouse download script will put the clickhouse binary into the current directory, and it can be run without installation.

Although, I figured out, how to install ClickHouse on Mac here: https://github.com/ClickHouse/NoiSQL#quick-start---macos
we did not put it into the Install script because no one among the engineers is using Mac, so the development iterations for Mac installation can be long.

Your edit does not look right because it is unlikely that the symlink exists, but clickhouse is not installed in PATH.


try
{
readQuotedStringWithSQLStyle(s, in);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have tryReadQuotedStringInto - we can avoid throwing and catching exceptions here.

@alexey-milovidov alexey-milovidov merged commit e5d3e34 into ClickHouse:master Aug 4, 2023
275 of 279 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can be tested Allows running workflows for external contributors pr-improvement Pull request with some product improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow writing table name as a string literal.
6 participants