Skip to content

Support parametric arguments to FUNCTION for ClickHouse dialect #1315

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

Merged
merged 5 commits into from
Jun 23, 2024

Conversation

git-hulk
Copy link
Member

This closes #1301

@@ -4706,6 +4706,9 @@ impl fmt::Display for CloseCursor {
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct Function {
pub name: ObjectName,
/// The parameters to the function, including any options specified within the
/// delimiting parentheses.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we include a link to the clickhouse docs?

Copy link
Member Author

Choose a reason for hiding this comment

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

@iffyio Done

let mut parameters = FunctionArguments::None;
// ClickHouse aggregation support parametric functions like `quantile(0.5)(x)`
// which (0.5) is a parameter to the function.
if dialect_of!(self is ClickHouseDialect) && self.consume_token(&Token::LParen) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if dialect_of!(self is ClickHouseDialect) && self.consume_token(&Token::LParen) {
if dialect_of!(self is ClickHouseDialect | GenericDialect) && self.consume_token(&Token::LParen) {

we can include generic dialect if no conflicts

let args = self.parse_function_argument_list()?;
let mut args = self.parse_function_argument_list()?;
let mut parameters = FunctionArguments::None;
// ClickHouse aggregation support parametric functions like `quantile(0.5)(x)`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// ClickHouse aggregation support parametric functions like `quantile(0.5)(x)`
// ClickHouse aggregations support parametric functions like `quantile(0.5)(x)`

Comment on lines 558 to 560
fn parse_select_parametric_function() {
clickhouse().verified_stmt("SELECT quantile(0.5)(x) FROM t");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we extend the test asserting that the parameter and arguments lists do indeed show up in the parameters and args fields respectively (i.e not vice versa for example). Also we can include multiple items in both lists e.g quantile(0.5,0.6)(x,y)

@git-hulk
Copy link
Member Author

@iffyio Thanks for your review, all comments are resolved now.

@git-hulk git-hulk requested a review from iffyio June 22, 2024 13:50
Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

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

LGTM! cc @alamb

@alamb alamb changed the title Add support of the function parametric for ClickHouse dialect Support of the parametric arguments to FUNCTIONS for ClickHouse dialect Jun 23, 2024
@alamb alamb changed the title Support of the parametric arguments to FUNCTIONS for ClickHouse dialect Support of the parametric arguments to FUNCTION for ClickHouse dialect Jun 23, 2024
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @git-hulk and @iffyio

@alamb alamb changed the title Support of the parametric arguments to FUNCTION for ClickHouse dialect Support parametric arguments to FUNCTION for ClickHouse dialect Jun 23, 2024
}

/// Parse any extra set expressions that may be present in a query body
///
Copy link
Contributor

@alamb alamb Jun 23, 2024

Choose a reason for hiding this comment

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

I also pushed a commit to split up this function in e2ec2a6 to get the deeply nested tests to pass

This is the failure without this change: https://github.com/sqlparser-rs/sqlparser-rs/actions/runs/9632995493/job/26566863197


thread 'parse_deeply_nested_parens_hits_recursion_limits' has overflowed its stack
fatal runtime error: stack overflow
error: test failed, to rerun pass `--test sqlparser_common`

@coveralls
Copy link

coveralls commented Jun 23, 2024

Pull Request Test Coverage Report for Build 9633078247

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 67 of 68 (98.53%) changed or added relevant lines in 12 files are covered.
  • 1510 unchanged lines in 10 files lost coverage.
  • Overall coverage increased (+0.1%) to 89.008%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/parser/mod.rs 12 13 92.31%
Files with Coverage Reduction New Missed Lines %
src/lib.rs 1 12.64%
src/parser/alter.rs 2 66.67%
tests/sqlparser_sqlite.rs 4 98.36%
src/dialect/mod.rs 5 72.08%
tests/sqlparser_snowflake.rs 16 98.07%
src/ast/dml.rs 42 73.47%
tests/sqlparser_bigquery.rs 122 90.18%
src/ast/mod.rs 275 81.49%
src/parser/mod.rs 421 93.21%
tests/sqlparser_common.rs 622 89.6%
Totals Coverage Status
Change from base Build 9439708625: 0.1%
Covered Lines: 26276
Relevant Lines: 29521

💛 - Coveralls

@alamb alamb merged commit a685e11 into apache:main Jun 23, 2024
10 checks passed
@alamb
Copy link
Contributor

alamb commented Jun 23, 2024

Thanks again @git-hulk and @iffyio

@coveralls
Copy link

coveralls commented Jun 23, 2024

Pull Request Test Coverage Report for Build 9633103403

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 67 of 68 (98.53%) changed or added relevant lines in 12 files are covered.
  • 1510 unchanged lines in 10 files lost coverage.
  • Overall coverage increased (+0.1%) to 89.008%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/parser/mod.rs 12 13 92.31%
Files with Coverage Reduction New Missed Lines %
src/lib.rs 1 12.64%
src/parser/alter.rs 2 66.67%
tests/sqlparser_sqlite.rs 4 98.36%
src/dialect/mod.rs 5 72.08%
tests/sqlparser_snowflake.rs 16 98.07%
src/ast/dml.rs 42 73.47%
tests/sqlparser_bigquery.rs 122 90.18%
src/ast/mod.rs 275 81.49%
src/parser/mod.rs 421 93.21%
tests/sqlparser_common.rs 622 89.6%
Totals Coverage Status
Change from base Build 9439708625: 0.1%
Covered Lines: 26276
Relevant Lines: 29521

💛 - Coveralls

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.

Support Clickhouse parametric aggregation functions
4 participants