-
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
Postgres data type mapping in stream processing #5410
Postgres data type mapping in stream processing #5410
Conversation
441070f
to
3d58a1d
Compare
@@ -176,7 +176,7 @@ public void run() { | |||
private void transformEvent(final Event event, final String fullTableName) { | |||
Map<String, String> columnDataTypeMap = dbTableMetadata.getTableColumnDataTypeMap().get(fullTableName); | |||
for (Map.Entry<String, Object> entry : event.toMap().entrySet()) { | |||
final Object data = DataTypeHelper.getDataByColumnType(MySQLDataType.byDataType(columnDataTypeMap.get(entry.getKey())), entry.getKey(), | |||
final Object data = MySQLDataTypeHelper.getDataByColumnType(MySQLDataType.byDataType(columnDataTypeMap.get(entry.getKey())), entry.getKey(), |
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 class looks like generic but you are using MysqlDataTypeHelper here. Is this class specific to Mysql rds?
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's not specific for MySQL. Will add Postgres data type mapping here for export in a separate PR. This PR is for stream part.
@@ -23,11 +24,21 @@ public TableMetadata(String tableName, String databaseName, List<String> columnN | |||
this(tableName, databaseName, columnNames, primaryKeys, Collections.emptyMap(), Collections.emptyMap()); | |||
} | |||
|
|||
public TableMetadata(String tableName, String databaseName, List<String> columnNames, List<String> columnTypes, List<String> primaryKeys) { |
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.
Probably a builder pattern fits better here instead of multiple overloaded constructors. Just an idea. Feel free to ignore it if you think it doesn't add much value here.
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.
Made the change
@@ -158,7 +158,7 @@ private Map<String, Object> mapDataType(final Map<String, Object> rowData, final | |||
Map<String, String> columnDataTypeMap = dbTableMetadata.getTableColumnDataTypeMap().get(fullTableName); | |||
Map<String, Object> rowDataAfterMapping = new HashMap<>(); | |||
for (Map.Entry<String, Object> entry : rowData.entrySet()) { | |||
final Object data = DataTypeHelper.getDataByColumnType(MySQLDataType.byDataType(columnDataTypeMap.get(entry.getKey())), entry.getKey(), | |||
final Object data = MySQLDataTypeHelper.getDataByColumnType(MySQLDataType.byDataType(columnDataTypeMap.get(entry.getKey())), entry.getKey(), |
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 may be my understanding of the overall approach here but I got the same question here. This class looks like generic but you are using MysqlDataTypeHelper here. Is this class specific to Mysql rds?
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 ResyncWorker is specific for MySQL
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.
Then may be using a better name (or better package to segregate things related to Mysql under one) - will make this obvious.
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 add MySql to the class name.
3d0d83d
to
1f0cb70
Compare
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 working on this! A few comments below
case DOUBLE_PRECISION: | ||
return Double.parseDouble(textValue); | ||
case NUMERIC: | ||
case MONEY: |
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 it possible to convert Money to an object (map) with two fields currency
and amount
? I think that's a better representation.
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.
Sure
|
||
// Case 1: Solve for y when x = 0 | ||
double x1 = 0.0; | ||
double y1 = c == 0 ? 0 : -c / b; |
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 if b == 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.
a and b will never be zero as stated in the docs.
https://www.postgresql.org/docs/16/datatype-geometric.html#DATATYPE-LINE
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 says a and b will not be both zero at the same time.
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.
Lines are represented by the linear equation Ax + By + C = 0, where A and B are not both zero
. Am I inferring this wrong? If so, I can change my approach
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.
A and B are not both zero
I think this means A and B are not zero at the same time. B can still be zero if A is not and similarly the other way around. So you can still. have A = 0 so By + C = 0, or B = 0 so Ax + C = 0.
@@ -158,7 +158,7 @@ private Map<String, Object> mapDataType(final Map<String, Object> rowData, final | |||
Map<String, String> columnDataTypeMap = dbTableMetadata.getTableColumnDataTypeMap().get(fullTableName); | |||
Map<String, Object> rowDataAfterMapping = new HashMap<>(); | |||
for (Map.Entry<String, Object> entry : rowData.entrySet()) { | |||
final Object data = DataTypeHelper.getDataByColumnType(MySQLDataType.byDataType(columnDataTypeMap.get(entry.getKey())), entry.getKey(), | |||
final Object data = MySQLDataTypeHelper.getDataByColumnType(MySQLDataType.byDataType(columnDataTypeMap.get(entry.getKey())), entry.getKey(), |
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 add MySql to the class name.
e0ecc07
to
fa7c849
Compare
Signed-off-by: Hai Yan <oeyh@amazon.com>
Data type mapping for postgres Data type mapping for postgres stream Data type mapping for postgres stream Data type mapping for postgres stream Data type mapping for postgres stream Data type mapping for postgres stream Signed-off-by: Divyansh Bokadia <dbokadia@amazon.com>
Signed-off-by: Divyansh Bokadia <dbokadia@amazon.com>
fa7c849
to
77a1bc3
Compare
if (!columnType.isNetworkAddress()) { | ||
throw new IllegalArgumentException("ColumnType is not Network Address: " + columnType); | ||
} | ||
return value.toString(); |
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 thought we are converting Json to a map so that it will be an object in OpenSearch documents. But on the other hand, users can configure parse_json processor to parse it if necessary. Is it consistent with how we handle json in MySQL data type mapping?
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 referring to the JsonTypeHandler. Somehow added at the wrong place.
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.
Yes in MySQL data type mapping it is left as a json string, it is not being converted to an object.
} | ||
} | ||
|
||
private PGpoint[] getPointsOnLine(PGline line) { |
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 making these changes.
Description
Adds the data type mapping support for Postgres stream processing
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.