-
Notifications
You must be signed in to change notification settings - Fork 92
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
Reimplement datediff and dateadd in c to improve performance #1998
Merged
forestkeeper
merged 37 commits into
babelfish-for-postgresql:BABEL_3_X_DEV
from
amazon-aurora:jira-babel-4496
Nov 17, 2023
Merged
Changes from 10 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
f2376cb
Reimplement datediff and dateadd in c to improve performance
6fc01d1
Remove comments
5ee47a5
Updated upgrade files and fix day in date
26c4de4
Merge branch 'BABEL_3_X_DEV' into jira-babel-4496
2d4689d
Updated testing
ed0d56c
Fix function removal
602dfd9
Updated dependency file
e97b681
Change upgrade drop function call
8aa2cf1
Update error handling
4319c8a
Fix testing output diff
f2429fc
Fix datetime out of range message
781b906
Fix error messages
10a3058
Remove changes from upgrade script temp
33a7851
Merge branch 'BABEL_3_X_DEV' into jira-babel-4496
1d43425
Remove expected dependency
11d8e3b
Update expected tests
2a7588f
Fix rounding issue
6ba70a7
Add upgrade file functions
36f68c6
Drop functions to avoid error
0d7e504
Fix syntax error
3340558
Fix incorrect errcode
bf70129
Merge branch 'BABEL_3_X_DEV' into jira-babel-4496
a0cee91
Fix errocode output in test files
3d1e5a3
Resolve format_datetime mvu failure
cefaae3
Modify error calls in datediff
b85969c
Unify error calls and cleanup test files
d5f039f
Merge branch 'BABEL_3_X_DEV' into jira-babel-4496
0d37ae3
Add appropriate error codes
5ccd559
Fix merge conflict
1593b72
Updated expected output error messages
4256536
Updated output files with proper error codes
329a733
Update TestErrorHelperFunctionsUpgrade-vu-verify.out
77a21cf
Empty-Commit to restart test
7c5c9d8
Consolidate error messages and add test case
17147ba
Merge branch 'BABEL_3_X_DEV' into jira-babel-4496
81491c7
Remove datediff_internal_date from new schedules
f819833
Remove tests from schedule
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
#include "utils/datetime.h" | ||
#include "libpq/pqformat.h" | ||
#include "utils/timestamp.h" | ||
#include "parser/scansup.h" | ||
|
||
#include "fmgr.h" | ||
#include "miscadmin.h" | ||
|
@@ -63,6 +64,9 @@ PG_FUNCTION_INFO_V1(datetimeoffset_datetime2); | |
PG_FUNCTION_INFO_V1(datetimeoffset_scale); | ||
|
||
PG_FUNCTION_INFO_V1(get_datetimeoffset_tzoffset_internal); | ||
PG_FUNCTION_INFO_V1(dateadd_datetimeoffset); | ||
|
||
#define DTK_NANO 32 | ||
|
||
|
||
/* datetimeoffset_in() | ||
|
@@ -832,3 +836,86 @@ EncodeDatetimeoffsetTimezone(char *str, int tz, int style) | |
|
||
*tmp = '\0'; | ||
} | ||
|
||
Datum | ||
dateadd_datetimeoffset(PG_FUNCTION_ARGS) { | ||
text *field = PG_GETARG_TEXT_PP(0); | ||
int num = PG_GETARG_INT32(1); | ||
tsql_datetimeoffset *d = PG_GETARG_DATETIMEOFFSET(2); | ||
|
||
char *lowunits; | ||
int type, | ||
val; | ||
tsql_datetimeoffset *result; | ||
Interval *interval; | ||
|
||
lowunits = downcase_truncate_identifier(VARDATA_ANY(field), | ||
VARSIZE_ANY_EXHDR(field), | ||
false); | ||
|
||
type = DecodeUnits(0, lowunits, &val); | ||
|
||
if(strncmp(lowunits, "doy", 3) == 0 || strncmp(lowunits, "dayofyear", 9) == 0) { | ||
type = UNITS; | ||
val = DTK_DOY; | ||
} | ||
|
||
if(strncmp(lowunits, "nanosecond", 11) == 0) { | ||
type = UNITS; | ||
val = DTK_NANO; | ||
} | ||
if(strncmp(lowunits, "weekday", 7) == 0) { | ||
type = UNITS; | ||
val = DTK_DAY; | ||
} | ||
|
||
if(type == UNITS) { | ||
switch(val) { | ||
case DTK_YEAR: | ||
interval = (Interval *) DirectFunctionCall7(make_interval, num, 0, 0, 0, 0, 0, 0); | ||
break; | ||
case DTK_QUARTER: | ||
interval = (Interval *) DirectFunctionCall7(make_interval, 0, num * 3, 0, 0, 0, 0, 0); | ||
break; | ||
case DTK_MONTH: | ||
interval = (Interval *) DirectFunctionCall7(make_interval, 0, num, 0, 0, 0, 0, 0); | ||
break; | ||
case DTK_WEEK: | ||
interval = (Interval *) DirectFunctionCall7(make_interval, 0, 0, num, 0, 0, 0, 0); | ||
break; | ||
case DTK_DAY: | ||
case DTK_DOY: | ||
interval = (Interval *) DirectFunctionCall7(make_interval, 0, 0, 0, num, 0, 0, 0); | ||
break; | ||
case DTK_HOUR: | ||
interval = (Interval *) DirectFunctionCall7(make_interval, 0, 0, 0, 0, num, 0, 0); | ||
break; | ||
case DTK_MINUTE: | ||
interval = (Interval *) DirectFunctionCall7(make_interval, 0, 0, 0, 0, 0, num, 0); | ||
break; | ||
case DTK_SECOND: | ||
interval = (Interval *) DirectFunctionCall7(make_interval, 0, 0, 0, 0, 0, 0, Float8GetDatum(num)); | ||
break; | ||
case DTK_MILLISEC: | ||
interval = (Interval *) DirectFunctionCall7(make_interval, 0, 0, 0, 0, 0, 0, Float8GetDatum((float) num * 0.001)); | ||
break; | ||
case DTK_MICROSEC: | ||
interval = (Interval *) DirectFunctionCall7(make_interval, 0, 0, 0, 0, 0, 0, Float8GetDatum((float) num * 0.000001)); | ||
break; | ||
case DTK_NANO: | ||
interval = (Interval *) DirectFunctionCall7(make_interval, 0, 0, 0, 0, 0, 0, Float8GetDatum((float) num * 0.000000001)); | ||
break; | ||
default: | ||
elog(ERROR, "the datepart %s is not supported by function dateadd for datatype datetimeoffset", | ||
lowunits); | ||
break; | ||
} | ||
} else { | ||
elog(ERROR, "the datepart %s is not supported by function dateadd for datatype datetimeoffset", lowunits); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original msg on the script impl is :
|
||
} | ||
|
||
result = (tsql_datetimeoffset *) DirectFunctionCall2(datetimeoffset_pl_interval, DatetimeoffsetGetDatum(d), PointerGetDatum(interval)); | ||
|
||
CheckDatetimeoffsetRange(result); | ||
PG_RETURN_DATETIMEOFFSET(result); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the error msg is different
and could you combine too err out places together