Skip to content

Support Map literal syntax for DuckDB and Generic #1344

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
Jul 21, 2024

Conversation

goldmedal
Copy link
Contributor

Description

I added Map syntax of DuckDB for DuckDB and Generic dialects.
For example:

SELECT MAP {'key1': 10, 'key2': 20, 'key3': 30};

It will also be used by apache/datafusion#11434 for creating the scalar map.

@goldmedal
Copy link
Contributor Author

Gentle ping @alamb
Could you help me to trigger the CI workflow? Thanks.

@dharanad
Copy link

This is interesting PR.

@alamb
Copy link
Contributor

alamb commented Jul 20, 2024

Sorry -- I am behind on reviews. I triggered the worflow

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.

Thank you @goldmedal and @dharanad

@@ -1078,6 +1078,9 @@ impl<'a> Parser<'a> {
let expr = self.parse_subexpr(Self::PLUS_MINUS_PREC)?;
Ok(Expr::Prior(Box::new(expr)))
}
Keyword::MAP if self.peek_token() == Token::LBrace => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this also check dialect.support_map_literal_syntax()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds great. Thanks

@coveralls
Copy link

coveralls commented Jul 20, 2024

Pull Request Test Coverage Report for Build 10027832349

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

  • 90 of 102 (88.24%) changed or added relevant lines in 7 files are covered.
  • 1325 unchanged lines in 5 files lost coverage.
  • Overall coverage increased (+0.03%) to 89.222%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/dialect/duckdb.rs 1 2 50.0%
src/dialect/generic.rs 1 2 50.0%
src/dialect/mod.rs 1 2 50.0%
src/parser/mod.rs 16 17 94.12%
tests/sqlparser_common.rs 56 64 87.5%
Files with Coverage Reduction New Missed Lines %
tests/sqlparser_clickhouse.rs 4 98.45%
src/ast/query.rs 93 86.07%
src/ast/mod.rs 333 81.44%
src/parser/mod.rs 402 93.31%
tests/sqlparser_common.rs 493 89.61%
Totals Coverage Status
Change from base Build 9944212602: 0.03%
Covered Lines: 27128
Relevant Lines: 30405

💛 - Coveralls

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.

Looks good to me -- thanks you @goldmedal

cc @iffyio @jmhain

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!

src/ast/mod.rs Outdated
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct Map {
pub fields: Vec<MapField>,
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
pub fields: Vec<MapField>,
pub entries: Vec<MapEntry>,

we can probably use entry since field could be confused for the key part of the map?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @iffyio. Sounds great!

@alamb
Copy link
Contributor

alamb commented Jul 21, 2024

Thank you @goldmedal and @iffyio

I plan a release early this upcoming week for another reason, so this should be available shortly

@alamb alamb merged commit 48ea564 into apache:main Jul 21, 2024
10 checks passed
@goldmedal
Copy link
Contributor Author

Thanks, @alamb and @iffyio again.

@goldmedal goldmedal deleted the support-map-literal branch July 21, 2024 12:30
ayman-sigma pushed a commit to sigmacomputing/sqlparser-rs that referenced this pull request Nov 19, 2024
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.

5 participants