-
Notifications
You must be signed in to change notification settings - Fork 97
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
datepart function reimplementation #1959
datepart function reimplementation #1959
Conversation
#define DATEPART_MAX_VALUE 2958463 | ||
#define DATEPART_MIN_VALUE -53690 |
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.
what does these two number represent? add simple comment just like above
ALTER FUNCTION sys.datepart_internal RENAME TO datepart_internal_deprecated_3_5; | ||
|
||
CALL sys.babelfish_drop_deprecated_object('function', 'sys', 'datepart_internal_deprecated_3_5'); |
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.
Have defensive code, rename only if it exists with given argument types.
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.
You can take help from Rohit
Datum | ||
datepart_internal_datetimeoffset(PG_FUNCTION_ARGS) | ||
{ | ||
char *field = text_to_cstring(PG_GETARG_TEXT_PP(0)); |
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.
You can directly use PG_GETARG_CSTRING, applicable to everywhere else also
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.
This is not yet resolved
DateADT date_arg; | ||
date_arg = PG_GETARG_DATEADT(1); | ||
timestamp = DirectFunctionCall1(date_timestamp, date_arg); |
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.
DirectFunctionCall1 expects datum argument so we can directly pass PG_GETARG(1) to DirectFunctionCall1
if (timestamp == 0 && general_integer_datatype) | ||
{ | ||
/* Checking for the limits for general_integer_datatype */ | ||
if(df_tz > DATEPART_MAX_VALUE || df_tz < DATEPART_MIN_VALUE) | ||
{ | ||
ereport(ERROR, | ||
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), | ||
errmsg("Arithmetic overflow error converting expression to data type datetime."))); | ||
} |
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.
add test cases which will hit this error
Datum | ||
datepart_internal_datetimeoffset(PG_FUNCTION_ARGS) | ||
{ | ||
char *field = text_to_cstring(PG_GETARG_TEXT_PP(0)); |
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.
This is not yet resolved
|
||
ALTER FUNCTION sys.datepart_internal(PG_CATALOG.TEXT, anyelement, INTEGER) RENAME TO datepart_internal_deprecated_3_5; | ||
|
||
CALL sys.babelfish_drop_deprecated_object('function', 'sys', 'datepart_internal_deprecated_3_5'); |
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.
should be done at the end of script
SELECT DATEPART(day, CAST(-53690 AS float)); | ||
GO | ||
|
||
SELECT DATEPART(day, CAST(-53691 AS float)); |
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.
we still need to have test cases which covers min/max, NULL for all the data types and also with random field argument
SELECT DATEPART(second, CAST(256 AS tinyint)); | ||
GO | ||
~~START~~ | ||
int | ||
~~ERROR (Code: 220)~~ | ||
|
||
~~ERROR (Message: value for domain tinyint violates check constraint "tinyint_check")~~ |
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.
Is this the same T-SQL behaviour? I dont think so. Seems like some bug with casting 256 to TINYINT. Please confirm and file a bug if needed
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.
seems like every domain data type has this problem, for example, smallmoney
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.
This is a issue of cast function. For the datatypes, the overflow error message is thrown from the cast function before hitting the datepart functions. Will fiile a bug
5c67087
into
babelfish-for-postgresql:BABEL_3_X_DEV
PR implements fix for low performance with function sys. datepart_internal by re-implement in C Signed-off-by: Parikshit Sarode <[email protected]> Co-authored-by: Parikshit Sarode <[email protected]>
PR implements fix for low performance with function sys. datepart_internal by re-implement in C Signed-off-by: Parikshit Sarode <[email protected]> Co-authored-by: Parikshit Sarode <[email protected]>
PR implements fix for low performance with function sys. datepart_internal by re-implement in C Signed-off-by: Parikshit Sarode <[email protected]> Co-authored-by: Parikshit Sarode <[email protected]>
PR implements fix for low performance with function sys. datepart_internal by re-implement in C Signed-off-by: Parikshit Sarode <[email protected]> Co-authored-by: Parikshit Sarode <[email protected]>
PR implements fix for low performance with function sys. datepart_internal by re-implement in C Signed-off-by: Parikshit Sarode <[email protected]> Co-authored-by: Parikshit Sarode <[email protected]>
PR implements fix for low performance with function sys. datepart_internal by re-implement in C Signed-off-by: Parikshit Sarode <[email protected]> Co-authored-by: Parikshit Sarode <[email protected]>
PR implements fix for low performance with function sys. datepart_internal by re-implement in C Signed-off-by: Parikshit Sarode <[email protected]> Co-authored-by: Parikshit Sarode <[email protected]>
PR implements fix for low performance with function sys. datepart_internal by re-implement in C Signed-off-by: Parikshit Sarode <[email protected]> Co-authored-by: Parikshit Sarode <[email protected]>
PR implements fix for low performance with function sys. datepart_internal by re-implement in C Signed-off-by: Parikshit Sarode <[email protected]> Co-authored-by: Parikshit Sarode <[email protected]>
PR implements fix for low performance with function sys. datepart_internal by re-implement in C Signed-off-by: Parikshit Sarode <[email protected]> Co-authored-by: Parikshit Sarode <[email protected]>
PR implements fix for low performance with function sys. datepart_internal by re-implement in C Signed-off-by: Parikshit Sarode <[email protected]> Co-authored-by: Parikshit Sarode <[email protected]>
Description - Low performance with function sys. datepart_internal -- re-implement in
C
Queries with incorrect output that were present in the JDBC tests files
In datepart, some queries in tests were giving incorrect output and included in the tests file. For example,
Example 1
The correct output should have been 523 which is verified and fixed in this code. This incorrect test was present in test/JDBC/expected/babel_function.out among others
Example 2
The expected result should be 59
Example 3 -
Correct output should be 1 but it was written as 8 in test/JDBC/expected/datepart-vu-verify.out
When verified, the output of this query should be 1
Such outputs are corrected in the [BABEL-4302] - Low performance with function sys. datepart_internal -- re-implement in
C
. All queries are giving correct results as expected.The file test/JDBC/expected/babel_function.out has the following queries that should throw an error but some output is given
datepart queries should throw an error message for the following queries instead some output is given. These queries are present in the babel_functions.out in test/JDBC/expected/babel_function.out
Example 1-
BBF results
Expected results
When the first parameter in datepart is date, week, month, quarter, year, such error is expected.
Example 2-
BBF results
Expected results
Irrespective of the first parameter in datepart, such error is expected.
These are some few examples of incorrect behaviour
Signed-off-by: Parikshit Sarode [email protected]
Issues Resolved
Task: BABEL-4302,BABEL-979, BABEL-4366 issues related to datepart, BABEL-4582 issues related to datepart and not cast
Check List
By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.