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: type conversion between Values #2394

Merged
merged 14 commits into from
Sep 18, 2023

Conversation

QuenKar
Copy link
Contributor

@QuenKar QuenKar commented Sep 14, 2023

I hereby agree to the terms of the GreptimeDB CLA

What's changed and what's your intention?

main changes

  1. add try_cast() in datatype trait.
  2. implement the cast for date/time/timestamp/datetime types.
  3. implement primitive types u8,u16,u32,u64,i8,i16,i32,i64,f32,f64 cast.
  4. impl cast_with_opt method which supports two mode which can be set with CastOption for casting type(for cast failed: strict mode will return error and non-strict mode will return Null).

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.

Refer to a related PR or issue link (optional)

Closes #2376

@codecov
Copy link

codecov bot commented Sep 14, 2023

Codecov Report

Merging #2394 (357c0fc) into develop (342cc0a) will increase coverage by 0.01%.
The diff coverage is 85.09%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2394      +/-   ##
===========================================
+ Coverage    77.63%   77.65%   +0.01%     
===========================================
  Files          729      730       +1     
  Lines       115114   115885     +771     
===========================================
+ Hits         89374    89985     +611     
- Misses       25740    25900     +160     

@QuenKar QuenKar marked this pull request as draft September 14, 2023 09:33
@QuenKar QuenKar marked this pull request as ready for review September 14, 2023 14:25
@QuenKar
Copy link
Contributor Author

QuenKar commented Sep 15, 2023

should allow other types unconditionally convert to Value::Null?

@zhongzc
Copy link
Contributor

zhongzc commented Sep 15, 2023

Can you provide a function that detects whether one type can be cast to another?

@QuenKar QuenKar marked this pull request as draft September 15, 2023 09:55
@QuenKar QuenKar marked this pull request as ready for review September 18, 2023 08:19
Copy link
Contributor

@killme2008 killme2008 left a comment

Choose a reason for hiding this comment

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

Great work! Thank u.

src/common/time/src/date.rs Outdated Show resolved Hide resolved
src/common/time/src/datetime.rs Show resolved Hide resolved
src/datatypes/src/types/boolean_type.rs Show resolved Hide resolved
src/datatypes/src/types/cast.rs Show resolved Hide resolved
src/datatypes/src/types/interval_type.rs Outdated Show resolved Hide resolved
src/datatypes/src/types/time_type.rs Show resolved Hide resolved
Copy link
Contributor

@killme2008 killme2008 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@waynexia waynexia left a comment

Choose a reason for hiding this comment

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

Mostly LGTM

src/datatypes/src/types/dictionary_type.rs Outdated Show resolved Hide resolved
@waynexia waynexia added this pull request to the merge queue Sep 18, 2023
Merged via the queue into GreptimeTeam:develop with commit 5805e8d Sep 18, 2023
11 checks passed
paomian pushed a commit to paomian/greptimedb that referenced this pull request Oct 19, 2023
* feat: add cast() in datatype trait.

* feat: add cast for primitive type

* feat: add unit test cases

* test: add datetime/time cases.

* refactor: time_type cast function.

* chore: typos.

* refactor code.

* feat: add can_cast_type func.

* chore: rename cast to try_cast

* feat: impl cast_with_opt

* chore: pub use cast_with_opt

* chore: add timezone for test

* Update src/common/time/src/date.rs

Co-authored-by: dennis zhuang <[email protected]>

* chore: duration type

---------

Co-authored-by: dennis zhuang <[email protected]>
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.

Adds cast function to DataType/ConcreteDataType
5 participants