-
Notifications
You must be signed in to change notification settings - Fork 100
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
Implemented CAST from VARBINARY to DATETIME in Babelfish. #3481
base: BABEL_3_X_DEV
Are you sure you want to change the base?
Implemented CAST from VARBINARY to DATETIME in Babelfish. #3481
Conversation
Signed-off-by: yashneet vinayak <yashneet@amazon.com>
Signed-off-by: yashneet vinayak <yashneet@amazon.com>
Signed-off-by: yashneet vinayak <yashneet@amazon.com>
Signed-off-by: yashneet vinayak <yashneet@amazon.com>
Signed-off-by: yashneet vinayak <yashneet@amazon.com>
Signed-off-by: yashneet vinayak <yashneet@amazon.com>
Signed-off-by: yashneet vinayak <yashneet@amazon.com>
Signed-off-by: yashneet vinayak <yashneet@amazon.com>
Update the antlr version to 4.13.2. This dramatically improves ANTLR parsing performance for certain queries, reducing their execution times by up to 40%. Note that this will require developers to have Java 11+ installed in order to develop locally. Also update the github actions to make it so that previous versions of Babelfish will be compiled using the original antlr-4.9.3 version. This is purely a fix for testing. Task: BABEL-5371 Signed-off-by: Jason Teng <jasonten@amazon.com>
Signed-off-by: yashneet vinayak <yashneet@amazon.com>
)" This reverts commit ff0a4d7.
Signed-off-by: yashneet vinayak <yashneet@amazon.com>
…tgresql#3067)"" This reverts commit 62123f0.
Signed-off-by: yashneet vinayak <yashneet@amazon.com>
Signed-off-by: yashneet vinayak <yashneet@amazon.com>
Pull Request Test Coverage Report for Build 13323779292Details
💛 - Coveralls |
@@ -312,6 +312,13 @@ LANGUAGE C VOLATILE STRICT PARALLEL SAFE; | |||
CREATE CAST (TIMESTAMP AS DATETIME) | |||
WITH FUNCTION sys.timestamp2datetime(TIMESTAMP) AS ASSIGNMENT; | |||
|
|||
CREATE OR REPLACE FUNCTION sys.varbinary2datetime(sys.BBF_VARBINARY) | |||
RETURNS 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.
Let's prepend proper schema everywhere
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.
Prepended sys where ever require.
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.
Here we should return sys.DATETIME
instead of 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.
Appended sys schema to the object.
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 we thoroughly tested all these functions and error scenarios?
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.
Testing of all scenarios done thoroughly
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.
I believe these tests are copied from 5_X. Have we matched the output?
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.
|
||
-- Test Varbinary to Datetime conversion using CAST | ||
-- Min value | ||
SELECT CAST(0xFFFF2E4600000000 AS 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.
Also add tests to test IMPLICIT casting
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.
Added test for this.
Signed-off-by: yashneet vinayak <yashneet@amazon.com>
7cfbf40
to
2df9e5d
Compare
AS 'babelfishpg_common', 'varbinary_datetime' | ||
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; | ||
|
||
CREATE CAST (sys.BBF_VARBINARY AS 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.
Here as well we should cast to sys.DATETIME instead of 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.
Appended sys schema to the object.
Signed-off-by: yashneet vinayak <yashneet@amazon.com>
Signed-off-by: yashneet vinayak <yashneet@amazon.com>
/* For 4 byte varbinary datetime range from 1900-01-01 00:00:00.000 to 1900-01-01 23:59:59:999*/ | ||
bool | ||
is_valid_datetime_for_4byte_varbinary(int64 total_usecs) | ||
{ | ||
return (total_usecs >= TSQL_DEFAULT_DATETIME && total_usecs <= MAX_4_BYTE_VARBINARY_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.
- This should be macro instead of function.
- If it is not getting used at multiple places then macro is also not needed.
Timestamp result; | ||
unsigned char *buffer = (unsigned char *)VARDATA_ANY(arg); | ||
|
||
/* TSQL datetime is 8 bytes */ |
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 mean input should be either 4 or 8 bytes, right? Lets update the comment.
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.
For testing, please make sure to add the below tests:
- NULLs tests, this is different to 0x00
- Boundary testing
- Overflows
- Coercive tests, eg instead of datetime use date or time which I assume have coercive casts
- MAX binary type testing
unsigned char *buffer = (unsigned char *)VARDATA_ANY(arg); | ||
|
||
/* TSQL datetime is 8 bytes */ | ||
if (size != sizeof(int64) && size != sizeof(int32)) |
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.
As spoken offline, Cast seems to accept multitude of binary lengths, I think MAX ones as well. Lets add support for all lens.
Are we not supporting binary casts? |
Description
Previously, Babelfish did not support casting from VARBINARY to DATETIME. We have now implemented this functionality to align with T-SQL's capabilities. This new feature allows users to cast VARBINARY data types to DATETIME.
Task: BABEL-3070
Signed-off-by: yashneet vinayak yashneet@amazon.com
Test Scenarios Covered
**Use case based -**Yes
**Boundary conditions -**Yes
**Arbitrary inputs -**Yes
**Negative test cases -**Yes
Minor version upgrade tests -
Major version upgrade tests -
Performance tests -
Tooling impact -
**Client tests -**Yes
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.