Skip to content
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

Merged
merged 3 commits into from
Feb 12, 2025

Conversation

divbok
Copy link
Contributor

@divbok divbok commented Feb 4, 2025

Description

Adds the data type mapping support for Postgres stream processing

Issues Resolved

Contributes to #5309

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

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.

@divbok divbok force-pushed the postgres_data_type_mapping branch 2 times, most recently from 441070f to 3d58a1d Compare February 4, 2025 20:18
@oeyh oeyh changed the title Postgres data type mapping Postgres data type mapping in stream processing Feb 4, 2025
@@ -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(),
Copy link
Collaborator

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?

Copy link
Collaborator

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) {
Copy link
Collaborator

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.

Copy link
Contributor Author

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(),
Copy link
Collaborator

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?

Copy link
Collaborator

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

Copy link
Collaborator

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.

Copy link
Collaborator

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.

@divbok divbok force-pushed the postgres_data_type_mapping branch from 3d0d83d to 1f0cb70 Compare February 6, 2025 17:41
Copy link
Collaborator

@oeyh oeyh left a 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:
Copy link
Collaborator

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.

Copy link
Contributor Author

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if b == 0?

Copy link
Contributor Author

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

Copy link
Collaborator

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.

Copy link
Contributor Author

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

Copy link
Collaborator

@oeyh oeyh Feb 7, 2025

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(),
Copy link
Collaborator

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.

@divbok divbok force-pushed the postgres_data_type_mapping branch 3 times, most recently from e0ecc07 to fa7c849 Compare February 9, 2025 19:28
oeyh and others added 3 commits February 10, 2025 10:33
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>
@divbok divbok force-pushed the postgres_data_type_mapping branch from fa7c849 to 77a1bc3 Compare February 10, 2025 16:36
if (!columnType.isNetworkAddress()) {
throw new IllegalArgumentException("ColumnType is not Network Address: " + columnType);
}
return value.toString();
Copy link
Collaborator

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?

Copy link
Collaborator

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.

Copy link
Contributor Author

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) {
Copy link
Collaborator

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.

@oeyh oeyh merged commit 1a41705 into opensearch-project:main Feb 12, 2025
46 of 47 checks passed
@oeyh oeyh mentioned this pull request Feb 12, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants