Skip to content

Commit

Permalink
Add int32 support and change format of castVarchar (#26)
Browse files Browse the repository at this point in the history
* add support to int32 type

* fix fortmat of cast varchar
  • Loading branch information
rui-mo authored and zhztheplayer committed Feb 28, 2022
1 parent 6799b38 commit 9a4876e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
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 @@ -164,12 +164,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 @@ -300,10 +300,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)
// %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 @@ -990,16 +990,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

0 comments on commit 9a4876e

Please sign in to comment.