-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[FLINK-37914][table] Add built-in OBJECT_UPDATE function #26806
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
base: master
Are you sure you want to change the base?
Conversation
56a3f1e
to
e437f51
Compare
.../flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/BaseExpressions.java
Outdated
Show resolved
Hide resolved
.../flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/BaseExpressions.java
Outdated
Show resolved
Hide resolved
...in/java/org/apache/flink/table/types/inference/strategies/ObjectUpdateInputTypeStrategy.java
Outdated
Show resolved
Hide resolved
...in/java/org/apache/flink/table/types/inference/strategies/ObjectUpdateInputTypeStrategy.java
Outdated
Show resolved
Hide resolved
...rc/main/java/org/apache/flink/table/types/inference/strategies/ObjectUpdateTypeStrategy.java
Outdated
Show resolved
Hide resolved
...rc/main/java/org/apache/flink/table/types/inference/strategies/ObjectUpdateTypeStrategy.java
Outdated
Show resolved
Hide resolved
...lanner/src/test/java/org/apache/flink/table/planner/functions/StructuredFunctionsITCase.java
Show resolved
Hide resolved
5a1cb17
to
336f2b3
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.
Last review comment. Almost there :-)
This function takes a structured object and updates specified fields with new values. | ||
The keys must be string literals that correspond to existing fields in the structured type. | ||
If a key does not exist in the input object, an exception will be thrown. | ||
If the value type is not compatible with the corresponding structured field type, |
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.
update this sentence everywhere
and values are the new values for those fields. At least one key-value pair must be provided. | ||
The total number of arguments must be odd (object + pairs of key-value arguments). | ||
|
||
The result type is the same structured type as the input, with the specified fields |
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.
The result type is the same structured type as the input, with the specified fields | |
The result type is the same structured type class, with the specified fields |
* <li>Validates that key arguments are non-null string literals | ||
* <li>Ensures field names are not repeated in the key-value pairs | ||
* <li>Ensures field names are part of the structured type's attributes | ||
* <li>Ensures field values match the expected types defined in the structured type |
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.
* <li>Ensures field values match the expected types defined in the structured type |
* | ||
* <ul> | ||
* <li>Extracting the field definitions from the input structured type | ||
* <li>Resolving the class from the structured type |
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.
* <li>Resolving the class from the structured type |
DataTypes.FIELD("b", DataTypes.CHAR(5).notNull()))) | ||
// Test update field to null | ||
.testResult( | ||
objectOf(Type1.class, "a", 42, "b", "Bob") |
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.
add a test where the object itself is null, e.g. OBJECT_UPDATED(CAST(NULL AS STRUCTURED<>), ...)
} | ||
|
||
public RowData eval(RowData rowData, Object... fieldNameAndValuePairs) { | ||
GenericRowData updatedRow = (GenericRowData) rowData; |
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.
return null if rowData is null.
What is the purpose of the change
This pull request implements the
OBJECT_UPDATE
built-in function as part of FLIP-520: Simplify StructuredType handling. The function allows users to update existing fields in structured objects by providing key-value pairs, enabling mutation operations on structured types in both SQL and Table API without requiring custom UDFs.Brief change log
ObjectUpdateInputTypeStrategy
for validating input arguments (structured object + key-value pairs)ObjectUpdateTypeStrategy
for inferring return types (same as input structured type)ObjectUpdateFunction
runtime function for performing field updatesOBJECT_UPDATE
toBuiltInFunctionDefinitions
with proper type inference strategiesobjectUpdate()
method on expressionsVerifying this change
This change added tests and can be verified as follows:
ObjectUpdateInputTypeStrategyTest
for input validation scenariosStructuredFunctionsITCase
for end-to-end SQL functionalityDoes this pull request potentially affect one of the following parts:
@Public(Evolving)
: yes (new built-in function)Documentation