-
Notifications
You must be signed in to change notification settings - Fork 43
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
[FLINK-35022][Connector/DynamoDB] Add TypeInformed DDB Element Converter as default element converter #136
base: main
Are you sure you want to change the base?
[FLINK-35022][Connector/DynamoDB] Add TypeInformed DDB Element Converter as default element converter #136
Conversation
Please change commit message to include the component: |
...main/java/org/apache/flink/connector/dynamodb/sink/DynamoDbTypeInformedElementConverter.java
Outdated
Show resolved
Hide resolved
...main/java/org/apache/flink/connector/dynamodb/sink/DynamoDbTypeInformedElementConverter.java
Outdated
Show resolved
Hide resolved
...main/java/org/apache/flink/connector/dynamodb/sink/DynamoDbTypeInformedElementConverter.java
Outdated
Show resolved
Hide resolved
.../java/org/apache/flink/connector/dynamodb/sink/DynamoDbTypeInformedElementConverterTest.java
Outdated
Show resolved
Hide resolved
.../java/org/apache/flink/connector/dynamodb/sink/DynamoDbTypeInformedElementConverterTest.java
Outdated
Show resolved
Hide resolved
...main/java/org/apache/flink/connector/dynamodb/sink/DynamoDbTypeInformedElementConverter.java
Outdated
Show resolved
Hide resolved
...main/java/org/apache/flink/connector/dynamodb/sink/DynamoDbTypeInformedElementConverter.java
Outdated
Show resolved
Hide resolved
...main/java/org/apache/flink/connector/dynamodb/sink/DynamoDbTypeInformedElementConverter.java
Outdated
Show resolved
Hide resolved
I have left a comment regarding the need for this on the Jira: https://issues.apache.org/jira/browse/FLINK-35022 |
c1c4bb6
to
a44f9a6
Compare
@dannycranmer Thanks for the feedback, I have addressed your comments. Alternatively I decided to follow an approach similar to |
58f0618
to
88fe1cc
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 the update @vahmed-hamdy. Left a few comments
...main/java/org/apache/flink/connector/dynamodb/sink/DynamoDbTypeInformedElementConverter.java
Outdated
Show resolved
Hide resolved
...main/java/org/apache/flink/connector/dynamodb/sink/DynamoDbTypeInformedElementConverter.java
Outdated
Show resolved
Hide resolved
...main/java/org/apache/flink/connector/dynamodb/sink/DynamoDbTypeInformedElementConverter.java
Outdated
Show resolved
Hide resolved
...main/java/org/apache/flink/connector/dynamodb/sink/DynamoDbTypeInformedElementConverter.java
Outdated
Show resolved
Hide resolved
@vahmed-hamdy can you also update the docs please? |
88fe1cc
to
2aee832
Compare
2aee832
to
edbf9f3
Compare
edbf9f3
to
086538d
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.
LGTM, thanks @vahmed-hamdy
@Override | ||
public void open(Sink.InitContext context) {} |
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.
nit: Do we need this? I think it has a no-op default implementation
if (typeInfo instanceof BasicTypeInfo) { | ||
return AttributeConverterProvider.defaultProvider() | ||
.converterFor(EnhancedType.of(typeInfo.getTypeClass())); | ||
} else if (typeInfo.equals(PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO)) { | ||
return getAttributeConverter( | ||
AttributeValueType.B, | ||
bytes -> | ||
bytes instanceof SdkBytes | ||
? AttributeValue.fromB((SdkBytes) bytes) | ||
: AttributeValue.fromB(SdkBytes.fromByteArray((byte[]) bytes))); | ||
} else if (typeInfo instanceof BasicArrayTypeInfo) { | ||
BasicArrayTypeInfo<AttributeT, ?> basicArrayTypeInfo = | ||
(BasicArrayTypeInfo<AttributeT, ?>) typeInfo; | ||
if (basicArrayTypeInfo.getComponentInfo().equals(BasicTypeInfo.STRING_TYPE_INFO)) { | ||
return getAttributeConverter( | ||
AttributeValueType.SS, | ||
array -> AttributeValue.fromSs(Arrays.asList((String[]) array))); | ||
} else if (basicArrayTypeInfo.getComponentInfo() instanceof NumericTypeInfo) { | ||
return getAttributeConverter( | ||
AttributeValueType.NS, | ||
array -> | ||
AttributeValue.fromNs( | ||
convertObjectArrayToStringList((Object[]) array))); | ||
} | ||
|
||
return new ArrayAttributeConverterProvider() | ||
.converterFor(EnhancedType.of(typeInfo.getTypeClass())); | ||
} else if (typeInfo instanceof ObjectArrayTypeInfo) { | ||
return getObjectArrayTypeConverter((ObjectArrayTypeInfo<AttributeT, ?>) typeInfo); | ||
} else if (typeInfo instanceof PrimitiveArrayTypeInfo) { | ||
PrimitiveArrayTypeInfo<AttributeT> primitiveArrayTypeInfo = | ||
(PrimitiveArrayTypeInfo<AttributeT>) typeInfo; | ||
if (primitiveArrayTypeInfo.getComponentType() instanceof NumericTypeInfo) { | ||
return getAttributeConverter( | ||
AttributeValueType.NS, | ||
array -> AttributeValue.fromNs(convertPrimitiveArrayToStringList(array))); | ||
} else { | ||
throw new IllegalArgumentException( | ||
String.format( | ||
"Unsupported primitive array typeInfo %s", | ||
primitiveArrayTypeInfo.getComponentType())); | ||
} |
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 considered using the .attributeConverterProviders()
method in the table schema builder and reusing the constructs we use to DDB Table API? It might be good to reuse code here instead of duplicating!
TableSchema.builder(...)
.attributeConverterProviders(
new ArrayAttributeConverterProvider(),
... (add any more here) ...,
AttributeConverterProvider.defaultProvider());
We have an example here:
https://github.com/apache/flink-connector-aws/blob/main/flink-connector-aws/flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/RowDataToAttributeValueConverter.java#L56-L72
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 the PR @vahmed-hamdy ! Added a comment
Purpose of the change
Add
DynamoDbTypeInformedElementConverter
to convert Elements to dynamoDb Sink using its provided type Info.Verifying this change
This change added tests and can be verified as follows:
Significant changes
(Please check any boxes [x] if the answer is "yes". You can first publish the PR and check them afterwards, for convenience.)
@Public(Evolving)
)