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

feat(query): add interval type #16990

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

TCeason
Copy link
Collaborator

@TCeason TCeason commented Dec 3, 2024

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

Support new datatype Interval.

It represent periods of time that can be added to or subtracted from DATE, TIMESTAMP.

:) DESCRIBE t

┌───────────────────────────────────────────────┐
│  Field │   Type   │  Null  │ Default │  Extra │
│ String │  String  │ String │  String │ String │
├────────┼──────────┼────────┼─────────┼────────┤
│ c      │ INTERVAL │ YES    │ NULL    │        │
└───────────────────────────────────────────────┘


:) insert into t values('1 month 1 day 1 hours');
:) select * from  t;
┌───────────────────────┐
│           c           │
│   Nullable(Interval)  │
├───────────────────────┤
│ 1 month               │
│ 1 month 1 day 1:00:00 │
│ 1 month 1 day 1:00:00 │
│ 1 month 1 day 1:00:00 │
└───────────────────────┘
4 rows read in 0.061 sec. Processed 4 rows, 68B (65.57 rows/s, 1.09 KiB/s)

Note: Since MySQL does not support the INTERVAL type, querying the INTERVAL type using the MySQL client will result in an error.

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@TCeason TCeason requested a review from drmingdrmer as a code owner December 3, 2024 13:00
@TCeason TCeason marked this pull request as draft December 3, 2024 13:01
@github-actions github-actions bot added the pr-feature this PR introduces a new feature to the codebase label Dec 3, 2024
Copy link
Member

@drmingdrmer drmingdrmer left a comment

Choose a reason for hiding this comment

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

The meta data part looks good to me. Do not forget to add a new version test:
image.png

Reviewed 4 of 42 files at r1.
Reviewable status: 4 of 42 files reviewed, all discussions resolved

@TCeason TCeason force-pushed the interval branch 5 times, most recently from b43edcf to add4db2 Compare December 4, 2024 02:35
@TCeason
Copy link
Collaborator Author

TCeason commented Dec 4, 2024

wait databendlabs/bendsql#517 merge

@TCeason TCeason marked this pull request as ready for review December 5, 2024 08:11
@TCeason TCeason marked this pull request as draft December 5, 2024 08:25
:) select to_interval('02:01'), to_interval('1 year 1 day 1 hour');

┌───────────────────────────────────────────────────────────┐
│ to_interval('02:01') │ to_interval('1 year 1 day 1 hour') │
│       Interval       │              Interval              │
├──────────────────────┼────────────────────────────────────┤
│ 2:01:00              │ 1year 1day 1:00:00                 │
└───────────────────────────────────────────────────────────┘
@TCeason TCeason force-pushed the interval branch 2 times, most recently from 17816e4 to 9e58cd9 Compare December 5, 2024 08:49
@rad-pat
Copy link

rad-pat commented Dec 5, 2024

@TCeason, when this is completed, will we be able to write such conversion as to_interval('454664 seconds') and get result Interval 5days 06:17:44 ? i.e. just pass conversion value in total seconds.

@TCeason
Copy link
Collaborator Author

TCeason commented Dec 5, 2024

when this is completed, will we be able to write such conversion as to_interval('454664 seconds') and get result Interval 5days 06:17:44 ? i.e. just pass conversion value in total seconds.

Yes, the results are quite similar. I’ve encountered a few issues currently, and I’ll add some similar tests later.

@rad-pat
Copy link

rad-pat commented Dec 5, 2024

Yes, the results are quite similar. I’ve encountered a few issues currently, and I’ll add some similar tests later.

Excellent, this will hopefully make it easy to wrap in SQLAlchemy for Python 👍

@TCeason
Copy link
Collaborator Author

TCeason commented Dec 6, 2024

databendlabs/bendsql#530

@TCeason TCeason marked this pull request as ready for review December 6, 2024 04:05
@TCeason TCeason requested a review from sundy-li December 6, 2024 04:05
EXTENSION_KEY.to_string(),
ARROW_EXT_TYPE_INTERVAL.to_string(),
);
ArrowDataType::LargeBinary
Copy link
Member

Choose a reason for hiding this comment

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

We can use FixedSizeBinary instead of LargeBinary, because the interval value has a fixed length, which will remove the offset and reduce the column size.

Copy link
Member

@drmingdrmer drmingdrmer left a comment

Choose a reason for hiding this comment

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

metadata part LGTM :lgtm:

Reviewed 2 of 33 files at r4.
Reviewable status: 6 of 72 files reviewed, 1 unresolved discussion (waiting on @sundy-li and @TCeason)

@TCeason
Copy link
Collaborator Author

TCeason commented Dec 6, 2024

Marking this as a draft: Compression support for FixedSizeBinaryColumn is required when using the fs storage type. Implementation is targeted for completion next week.

@TCeason TCeason marked this pull request as draft December 6, 2024 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Add Support for INTERVAL Data Type - Already Supported in Parquet & Arrow
4 participants