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

Support date format with no separator #124

Merged
merged 1 commit into from
Jul 15, 2022
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
4 changes: 4 additions & 0 deletions cpp/src/gandiva/function_registry_datetime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ std::vector<NativeFunction> GetDateTimeFunctionRegistry() {
kResultNullInternal, "castTIMESTAMP_with_validation_check_utf8",
NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),

NativeFunction("castTIMESTAMP_withCarrying_withoutSep", {}, DataTypeVector{utf8()}, timestamp(),
kResultNullInternal, "castTIMESTAMP_withCarrying_withoutSep_utf8",
NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),

NativeFunction("castTIMESTAMP_withCarrying", {}, DataTypeVector{utf8()}, timestamp(),
kResultNullInternal, "castTIMESTAMP_withCarrying_utf8",
NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),
Expand Down
25 changes: 25 additions & 0 deletions cpp/src/gandiva/precompiled/time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,31 @@ gdv_timestamp castTIMESTAMP_with_validation_check_utf8(int64_t context, const ch
}


// Convert yyyyMMddHHmmss to yyyy-MM-dd HH:mm:ss
gdv_timestamp castTIMESTAMP_withCarrying_withoutSep_utf8(int64_t context, const char* input,
gdv_int32 length, bool in_valid,
bool* out_valid) {
char formated_input[19];
int i = 0, j = 0;
while (i < 19) {
if (i == 4 || i == 7) {
formated_input[i] = '-';
i++;
} else if (i == 10) {
formated_input[i] = ' ';
i++;
} else if (i == 13 || i == 16) {
formated_input[i] = ':';
i++;
} else {
formated_input[i] = input[j];
i++;
j++;
}
}
return castTIMESTAMP_withCarrying_utf8(context, formated_input, 19, in_valid, out_valid);
}

/*
* Input consists of mandatory and optional fields.
* Mandatory fields are year, month and day.
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/gandiva/precompiled/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ gdv_timestamp castTIMESTAMP_withCarrying_utf8(int64_t context, const char* input
gdv_timestamp castTIMESTAMP_with_validation_check_utf8(int64_t context, const char* input,
gdv_int32 length, bool in_valid,
bool* out_valid);
gdv_timestamp castTIMESTAMP_withCarrying_withoutSep_utf8(int64_t context, const char* input,
gdv_int32 length, bool in_valid,
bool* out_valid);

gdv_timestamp castTIMESTAMP_date64(gdv_date64);
gdv_timestamp castTIMESTAMP_int64(gdv_int64);
gdv_date64 castDATE_timestamp(gdv_timestamp);
Expand Down