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

[core] Support TimestampToNumericPrimitiveCastRule in casting #3854

Merged
merged 9 commits into from
Aug 12, 2024

Conversation

xuzifu666
Copy link
Member

@xuzifu666 xuzifu666 commented Jul 30, 2024

Purpose

Follow up #3832 had support NumericPrimitive to Timestamp casting,this pr support Timestamp to NumericPrimitive casting.

Linked issue: close #xxx

Tests

CastExecutorTest##testTimestampToNumeric

API and Format

Documentation

@xuzifu666 xuzifu666 changed the title [core] Support TimestampToNumericPrimitiveCastRule in casing [core] Support TimestampToNumericPrimitiveCastRule in casting Jul 30, 2024
@Override
public CastExecutor<Timestamp, Number> create(DataType inputType, DataType targetType) {
if (inputType.is(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)) {
return value -> DateTimeUtils.unixTimestamp(value.getMillisecond());
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a case cast to and cast from.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK,had added cast to and from in test case @JingsongLi

@xuzifu666 xuzifu666 closed this Aug 6, 2024
@xuzifu666 xuzifu666 reopened this Aug 6, 2024
@xuzifu666 xuzifu666 closed this Aug 6, 2024
@xuzifu666 xuzifu666 reopened this Aug 6, 2024
@xuzifu666 xuzifu666 force-pushed the cast_timestamp_number branch from 6883e60 to 80e601a Compare August 8, 2024 06:54
@xuzifu666 xuzifu666 closed this Aug 8, 2024
@xuzifu666 xuzifu666 reopened this Aug 8, 2024
return value -> DateTimeUtils.unixTimestamp(value.getMillisecond());
} else if (inputType.is(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)) {
return value ->
DateTimeUtils.unixTimestamp(
Copy link
Contributor

Choose a reason for hiding this comment

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

For int, short, byte types, should not return long.

Copy link
Member Author

@xuzifu666 xuzifu666 Aug 12, 2024

Choose a reason for hiding this comment

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

Make sense,due to the number is hundreds million at least that Interge.Max also cannot hold the size,so I change to just handle Bigint condition in targetType and others return null. @JingsongLi

Copy link
Contributor

Choose a reason for hiding this comment

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

integer is OK?

Copy link
Contributor

Choose a reason for hiding this comment

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

And CastRulePredicate should be only target to int and bigint

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes,should support int and bigint,I would change it latter. Thanks for the reminder. @JingsongLi

Copy link
Contributor

@JingsongLi JingsongLi left a comment

Choose a reason for hiding this comment

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

+1

@JingsongLi JingsongLi merged commit cb13634 into apache:master Aug 12, 2024
9 of 10 checks passed
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.

2 participants