-
Notifications
You must be signed in to change notification settings - Fork 215
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
Adding enum and range datatype support for postgres #5458
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Divyansh Bokadia <dbokadia@amazon.com> Adding enum and range datatype support for postgres Adding enum and range datatype support for postgres
05ae81a
to
147ce19
Compare
@@ -49,11 +50,19 @@ public enum ColumnType { | |||
XML(142, "xml"), | |||
UUID(2950, "uuid"), | |||
PG_LSN(3220, "pg_lsn"), | |||
PG_SNAPSHOT(5038, "pg_snapshot"), |
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.
Beyond this PR, why do we have this enum mapping? Is this not provided by the Posgres library itself?
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.
There is no such library which provides the type_id
of these data types.
@@ -22,6 +25,9 @@ public class PostgresStreamState { | |||
@JsonProperty("replicationSlotName") | |||
private String replicationSlotName; | |||
|
|||
@JsonProperty("enumColumnsMap") |
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.
Can we have a clearer name here? What exactly is this storing?
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.
It stores the table name against the set of all enum columns. That is why i went with this naming convention.
private static final NumericTypeHandler numericTypeHandler = new NumericTypeHandler(); | ||
private static final TemporalTypeHandler temporalTypeHandler = new TemporalTypeHandler(); | ||
|
||
private static final Map<PostgresDataType.DataCategory, PostgresDataTypeHandler> typeHandlers = Map.ofEntries( |
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'm curious why you moved away from Map.of
to ofEntries
? The original had a little less boilerplate code.
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.
Map.of
allows only 10 arguments, so I moved to Map.ofEntries
|
||
private Object parseRangeValue(PostgresDataType columnType,String columnName, String rangeString) { | ||
|
||
if(rangeString.equals("empty")) |
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 make "empty" a constant.
private static final String POSTGRES_TIMESTAMP_MAX_INFINITY = "9999-12-31 23:59:59"; | ||
private static final String POSTGRES_TIMESTAMPTZ_MIN_INFINITY = "1970-01-01 00:00:00+00"; | ||
private static final String POSTGRES_TIMESTAMPTZ_MAX_INFINITY = "9999-12-31 23:59:59+00"; | ||
public static final String POSTGRES_DATE_MIN_INFINITY = "1970-01-01"; |
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.
Why this change?
Map<String, Object> rangeMap = new HashMap<>(); | ||
if(!lowerBound.isEmpty()) { | ||
Object parsedLowerBound = numericTypeHandler.handle(columnType, columnName, lowerBound); | ||
rangeMap.put(lowerBoundInclusivity.equals("[") ? "gte" : "gt", parsedLowerBound); |
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.
Make "gte", "gt", "lte", "lt" constants as well.
@@ -91,6 +91,7 @@ public Map<String, String> getColumnDataTypes(final String fullTableName) { | |||
); | |||
} | |||
} | |||
return columnsToDataType; |
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.
Thanks for fixing these!
@@ -229,6 +234,88 @@ void getColumnDataTypes_whenColumnsExist_shouldReturnValidMapping() throws SQLEx | |||
assertThat(result, equalTo(expectedColumnTypes)); | |||
} | |||
|
|||
@Test | |||
void getEnumColumns_successfully_returns_enum_columns() throws SQLException { |
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.
Can you add a test for getColumnDataTypes
when enums are involved?
Description
enum
while storing.Issues Resolved
Contributes to #5309
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.