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

Add int32 support and change format of castVarchar #26

Merged
merged 2 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cpp/src/gandiva/function_registry_datetime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,21 @@ std::vector<NativeFunction> GetDateTimeFunctionRegistry() {
NativeFunction("seconds_to_timestamp", {}, DataTypeVector{int64()}, timestampusutc(),
kResultNullIfNull, "seconds_to_timestamp_int64"),

NativeFunction("seconds_to_timestamp", {}, DataTypeVector{int32()}, timestampusutc(),
kResultNullIfNull, "seconds_to_timestamp_int32"),

NativeFunction("millis_to_timestamp", {}, DataTypeVector{int64()}, timestampusutc(),
kResultNullIfNull, "millis_to_timestamp_int64"),

NativeFunction("millis_to_timestamp", {}, DataTypeVector{int32()}, timestampusutc(),
kResultNullIfNull, "millis_to_timestamp_int32"),

NativeFunction("micros_to_timestamp", {}, DataTypeVector{int64()}, timestampusutc(),
kResultNullIfNull, "micros_to_timestamp_int64"),

NativeFunction("micros_to_timestamp", {}, DataTypeVector{int32()}, timestampusutc(),
kResultNullIfNull, "micros_to_timestamp_int32"),

NativeFunction("date_diff", {}, DataTypeVector{date32(), date32()}, int32(),
kResultNullIfNull, "micros_to_timestamp_date32_date32"),

Expand Down
12 changes: 8 additions & 4 deletions cpp/src/gandiva/precompiled/arithmetic_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,14 @@ CAST_UNARY_UTF8(castVARCHAR, int8, utf8, "%d", NOFMT, nothing)
CAST_UNARY_UTF8(castVARCHAR, int16, utf8, "%d", NOFMT, nothing)
CAST_UNARY_UTF8(castVARCHAR, int32, utf8, "%d", NOFMT, nothing)
CAST_UNARY_UTF8(castVARCHAR, int64, utf8, "%ld", NOFMT, nothing)
// CAST_UNARY_UTF8(castVARCHAR, float32, utf8, "%.*f", FMT, FLT_DIG)
// CAST_UNARY_UTF8(castVARCHAR, float64, utf8, "%.*f", FMT, DBL_DIG)
CAST_UNARY_UTF8(castVARCHAR, float32, utf8, "%g", NOFMT, nothing)
CAST_UNARY_UTF8(castVARCHAR, float64, utf8, "%g", NOFMT, nothing)
// We set to display the full precision of Float/Double, but this may still behave
// differently with vanilla spark.
CAST_UNARY_UTF8(castVARCHAR, float32, utf8, "%.*f", FMT, FLT_DIG)
CAST_UNARY_UTF8(castVARCHAR, float64, utf8, "%.*f", FMT, DBL_DIG)
Copy link
Author

Choose a reason for hiding this comment

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

@zhouyuan Please take a look at this, thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

can you please make a note here? this is required as Spark has some different behavior as gandiva

Copy link
Author

Choose a reason for hiding this comment

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

note was added

// %g means converting floating-point number depending on the value and the precision.
// It bahaves similar to the shortest representation.
// CAST_UNARY_UTF8(castVARCHAR, float32, utf8, "%g", NOFMT, nothing)
// CAST_UNARY_UTF8(castVARCHAR, float64, utf8, "%g", NOFMT, nothing)

#undef CAST_UNARY_UTF8

Expand Down
15 changes: 15 additions & 0 deletions cpp/src/gandiva/precompiled/time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -921,16 +921,31 @@ gdv_timestamp seconds_to_timestamp_int64(gdv_int64 in) {
return in * 1000000;
}

FORCE_INLINE
gdv_timestamp seconds_to_timestamp_int32(gdv_int32 in) {
return (int64_t)in * 1000000;
}

FORCE_INLINE
gdv_timestamp millis_to_timestamp_int64(gdv_int64 in) {
return in * 1000;
}

FORCE_INLINE
gdv_timestamp millis_to_timestamp_int32(gdv_int32 in) {
return (int64_t)in * 1000;
}

FORCE_INLINE
gdv_timestamp micros_to_timestamp_int64(gdv_int64 in) {
return in;
}

FORCE_INLINE
gdv_timestamp micros_to_timestamp_int32(gdv_int32 in) {
return (int64_t)in;
}

FORCE_INLINE
gdv_int32 micros_to_timestamp_date32_date32(gdv_date32 left, gdv_date32 right) {
return left - right;
Expand Down