Skip to content

Commit b8bb16a

Browse files
authored
Add int32 support and change format of castVarchar (#26)
* add support to int32 type * fix fortmat of cast varchar
1 parent 8908635 commit b8bb16a

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

cpp/src/gandiva/function_registry_datetime.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,21 @@ std::vector<NativeFunction> GetDateTimeFunctionRegistry() {
123123
NativeFunction("seconds_to_timestamp", {}, DataTypeVector{int64()}, timestampusutc(),
124124
kResultNullIfNull, "seconds_to_timestamp_int64"),
125125

126+
NativeFunction("seconds_to_timestamp", {}, DataTypeVector{int32()}, timestampusutc(),
127+
kResultNullIfNull, "seconds_to_timestamp_int32"),
128+
126129
NativeFunction("millis_to_timestamp", {}, DataTypeVector{int64()}, timestampusutc(),
127130
kResultNullIfNull, "millis_to_timestamp_int64"),
131+
132+
NativeFunction("millis_to_timestamp", {}, DataTypeVector{int32()}, timestampusutc(),
133+
kResultNullIfNull, "millis_to_timestamp_int32"),
128134

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

138+
NativeFunction("micros_to_timestamp", {}, DataTypeVector{int32()}, timestampusutc(),
139+
kResultNullIfNull, "micros_to_timestamp_int32"),
140+
132141
NativeFunction("date_diff", {}, DataTypeVector{date32(), date32()}, int32(),
133142
kResultNullIfNull, "micros_to_timestamp_date32_date32"),
134143

cpp/src/gandiva/precompiled/arithmetic_ops.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,14 @@ CAST_UNARY_UTF8(castVARCHAR, int8, utf8, "%d", NOFMT, nothing)
220220
CAST_UNARY_UTF8(castVARCHAR, int16, utf8, "%d", NOFMT, nothing)
221221
CAST_UNARY_UTF8(castVARCHAR, int32, utf8, "%d", NOFMT, nothing)
222222
CAST_UNARY_UTF8(castVARCHAR, int64, utf8, "%ld", NOFMT, nothing)
223-
// CAST_UNARY_UTF8(castVARCHAR, float32, utf8, "%.*f", FMT, FLT_DIG)
224-
// CAST_UNARY_UTF8(castVARCHAR, float64, utf8, "%.*f", FMT, DBL_DIG)
225-
CAST_UNARY_UTF8(castVARCHAR, float32, utf8, "%g", NOFMT, nothing)
226-
CAST_UNARY_UTF8(castVARCHAR, float64, utf8, "%g", NOFMT, nothing)
223+
// We set to display the full precision of Float/Double, but this may still behave
224+
// differently with vanilla spark.
225+
CAST_UNARY_UTF8(castVARCHAR, float32, utf8, "%.*f", FMT, FLT_DIG)
226+
CAST_UNARY_UTF8(castVARCHAR, float64, utf8, "%.*f", FMT, DBL_DIG)
227+
// %g means converting floating-point number depending on the value and the precision.
228+
// It bahaves similar to the shortest representation.
229+
// CAST_UNARY_UTF8(castVARCHAR, float32, utf8, "%g", NOFMT, nothing)
230+
// CAST_UNARY_UTF8(castVARCHAR, float64, utf8, "%g", NOFMT, nothing)
227231

228232
#undef CAST_UNARY_UTF8
229233

cpp/src/gandiva/precompiled/time.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,16 +921,31 @@ gdv_timestamp seconds_to_timestamp_int64(gdv_int64 in) {
921921
return in * 1000000;
922922
}
923923

924+
FORCE_INLINE
925+
gdv_timestamp seconds_to_timestamp_int32(gdv_int32 in) {
926+
return (int64_t)in * 1000000;
927+
}
928+
924929
FORCE_INLINE
925930
gdv_timestamp millis_to_timestamp_int64(gdv_int64 in) {
926931
return in * 1000;
927932
}
928933

934+
FORCE_INLINE
935+
gdv_timestamp millis_to_timestamp_int32(gdv_int32 in) {
936+
return (int64_t)in * 1000;
937+
}
938+
929939
FORCE_INLINE
930940
gdv_timestamp micros_to_timestamp_int64(gdv_int64 in) {
931941
return in;
932942
}
933943

944+
FORCE_INLINE
945+
gdv_timestamp micros_to_timestamp_int32(gdv_int32 in) {
946+
return (int64_t)in;
947+
}
948+
934949
FORCE_INLINE
935950
gdv_int32 micros_to_timestamp_date32_date32(gdv_date32 left, gdv_date32 right) {
936951
return left - right;

0 commit comments

Comments
 (0)