Skip to content

allow DateTimeField::Custom with EXTRACT in Postgres #1394

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 4 commits into from
Aug 26, 2024

Conversation

samuelcolvin
Copy link
Contributor

@samuelcolvin samuelcolvin commented Aug 22, 2024

I'm really not a fan of this dialect_of! stuff, it feels like I'm back writing some kind of odd Python. (I've changed this)

Follows #1191.

This will allow us to match postgres syntax:

postgres@localhost:postgres> select extract(seconds from '2 seconds'::interval);
╒══════════╕
│ extract  │
╞══════════╡
│ 2.000000 │
╘══════════╛
SELECT 1
Time: 0.007s
postgres@localhost:postgres> select extract('seconds' from '2 seconds'::interval);
╒══════════╕
│ extract  │
╞══════════╡
│ 2.000000 │
╘══════════╛
SELECT 1
Time: 0.007s
postgres@localhost:postgres> select extract(minutes from '2 seconds'::interval);
╒═════════╕
│ extract │
╞═════════╡
│ 0       │
╘═════════╛
SELECT 1
Time: 0.007s
postgres@localhost:postgres> select extract(ms from '2 seconds'::interval);
╒══════════╕
│ extract  │
╞══════════╡
│ 2000.000 │
╘══════════╛
SELECT 1
Time: 0.006s
postgres@localhost:postgres> select extract('ms' from '2 seconds'::interval);
╒══════════╕
│ extract  │
╞══════════╡
│ 2000.000 │
╘══════════╛
SELECT 1
Time: 0.006s

I guess all the unit names and abbreviations allowed by INTERVAL which I added in apache/arrow-rs#6211 are allowed, we should be able to use IntervalUnit in datafusion to process the custom value.

@coveralls
Copy link

coveralls commented Aug 22, 2024

Pull Request Test Coverage Report for Build 10512598473

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

  • 59 of 69 (85.51%) changed or added relevant lines in 6 files are covered.
  • 374 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.02%) to 89.156%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/dialect/generic.rs 2 4 50.0%
src/dialect/mod.rs 2 4 50.0%
src/dialect/postgresql.rs 2 4 50.0%
src/dialect/snowflake.rs 2 4 50.0%
tests/sqlparser_common.rs 49 51 96.08%
Files with Coverage Reduction New Missed Lines %
tests/sqlparser_clickhouse.rs 7 98.83%
src/ast/ddl.rs 63 86.32%
src/ast/query.rs 92 86.27%
src/parser/mod.rs 212 93.28%
Totals Coverage Status
Change from base Build 10418247467: 0.02%
Covered Lines: 28430
Relevant Lines: 31888

💛 - Coveralls

@samuelcolvin
Copy link
Contributor Author

I think this is good to go.

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

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 @samuelcolvin and @iffyio

@alamb alamb merged commit 222b7d1 into apache:main Aug 26, 2024
10 checks passed
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.

4 participants