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-31102][table] Add ARRAY_REMOVE function. #22144
Conversation
hi @snuyanzin @twalthr after talking in #21947
so it is the time to implment other array functions. so i submit a new PR, could you help to review |
thanks for the contribution
|
@snuyanzin |
hi @snuyanzin could you have time to help review it |
if ((element == null && needle != null) | ||
|| (element != null && needle == null) | ||
|| (element != null | ||
&& needle != null | ||
&& !(boolean) equalityHandle.invoke(element, needle))) { |
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 could be simplified e.g. check for the negative case and continue
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 done @snuyanzin
.testResult( | ||
$("f3").arrayRemove(row(true, LocalDate.of(1990, 10, 14))), | ||
"ARRAY_REMOVE(f3, (TRUE, DATE '1990-10-14'))", | ||
new Row[] {Row.of(true, LocalDate.of(2022, 4, 20)), null}, | ||
DataTypes.ARRAY( | ||
DataTypes.ROW( | ||
DataTypes.BOOLEAN(), DataTypes.DATE())) | ||
.nullable()) | ||
.testResult( | ||
$("f3").arrayRemove(row(false, LocalDate.of(1990, 10, 14))), | ||
"ARRAY_REMOVE(f3, (FALSE, DATE '1990-10-14'))", | ||
new Row[] { | ||
Row.of(true, LocalDate.of(2022, 4, 20)), | ||
Row.of(true, LocalDate.of(1990, 10, 14)), | ||
null | ||
}, | ||
DataTypes.ARRAY( | ||
DataTypes.ROW( | ||
DataTypes.BOOLEAN(), DataTypes.DATE())) | ||
.nullable()) |
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.
Under the hood there are a lot of Flink jobs executed.
From one side testing is important but tests should be well chosen.
It seems e.g. one of this could be removed since they are very similar.
I guess up to 4-5 test cases should be enough.
WDYT?
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 agree with you @snuyanzin
These examples cover a variety of cases, and the rest of the functions don't have to cover as many cases as possible, but some of the early functions still need to cover as many cases as possible, so that users can see how to use them and find bugs.
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 done @snuyanzin
@flinkbot run azure |
hi @snuyanzin could you help review it again? |
.../flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/BaseExpressions.java
Outdated
Show resolved
Hide resolved
@snuyanzin rebase to fix the conflicts and reviews from you. |
7f7c7ba
to
d996a53
Compare
hi @snuyanzin could you help review it again? |
$("f0").arrayRemove( | ||
lit(null, DataTypes.SMALLINT()) | ||
.cast(DataTypes.INT())), | ||
"ARRAY_REMOVE(f0, cast(NULL AS INT))", |
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.
"ARRAY_REMOVE(f0, cast(NULL AS INT))", | |
"ARRAY_REMOVE(f0, CAST(NULL AS INT))", |
All SQL keywords should be in uppercase
$("f2").arrayRemove( | ||
lit(null, DataTypes.STRING()) | ||
.cast(DataTypes.STRING())), | ||
"ARRAY_REMOVE(f2, cast(NULL AS VARCHAR))", |
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.
"ARRAY_REMOVE(f2, cast(NULL AS VARCHAR))", | |
"ARRAY_REMOVE(f2, CAST(NULL AS VARCHAR))", |
All SQL keywords should be in uppercase
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.
ok, fixed, thanks
.nullable()) | ||
.testResult( | ||
$("f3").arrayRemove(null), | ||
"ARRAY_REMOVE(f3, null)", |
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.
"ARRAY_REMOVE(f3, null)", | |
"ARRAY_REMOVE(f3, NULL)", |
// ARRAY<ARRAY<INT>> | ||
.testResult( | ||
$("f5").arrayRemove(new Integer[] {0}), | ||
"ARRAY_REMOVE(f5, array[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.
"ARRAY_REMOVE(f5, array[0])", | |
"ARRAY_REMOVE(f5, ARRAY[0])", |
DataTypes.ROW( | ||
DataTypes.BOOLEAN(), DataTypes.DATE())) | ||
.nullable()) | ||
// ARRAY<INT> with null elements |
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.
// ARRAY<INT> with null elements | |
// ARRAY<INT> with NULL elements |
"ARRAY_REMOVE(f5, array[0])", | ||
new Integer[][] {new Integer[] {1, null, 3}, new Integer[] {1}}, | ||
DataTypes.ARRAY(DataTypes.ARRAY(DataTypes.INT()).nullable())) | ||
// ARRAY<Map<INT, STRING>> with null elements |
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.
// ARRAY<Map<INT, STRING>> with null elements | |
// ARRAY<MAP<INT, STRING>> with null elements |
.testResult( | ||
$("f2").arrayRemove("Hello"), | ||
"ARRAY_REMOVE(f2, 'Hello')", | ||
new String[] {"World"}, | ||
DataTypes.ARRAY(DataTypes.STRING()).notNull()) | ||
.testResult( | ||
$("f2").arrayRemove( | ||
lit(null, DataTypes.STRING()) | ||
.cast(DataTypes.STRING())), | ||
"ARRAY_REMOVE(f2, cast(NULL AS VARCHAR))", |
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 do not see a big difference between these tests and tests for int types... ARRAY_REMOVE
invokes same code for both.... Probably just one (int or varchar is enough)
hi @snuyanzin fix your reviews |
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 addressing comments
LGTM
will merge soon
hi @snuyanzin , will it be merged now? |
What is the purpose of the change
This is an implementation of ARRAY_REMOVE
Brief change log
ARRAY_REMOVE for Table API and SQL
See also
spark https://spark.apache.org/docs/latest/api/sql/index.html#array_remove
presto https://prestodb.io/docs/current/functions/array.html
postgresql https://www.postgresql.org/docs/12/functions-array.html#ARRAY-FUNCTIONS-TABLE
Verifying this change
This change added tests in CollectionFunctionsITCase
Does this pull request potentially affect one of the following parts:
Dependencies (does it add or upgrade a dependency): ( no)
The public API, i.e., is any changed class annotated with @public(Evolving): (yes )
The serializers: (no)
The runtime per-record code paths (performance sensitive): ( no)
Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: ( no)
The S3 file system connector: ( no)
Documentation
Does this pull request introduce a new feature? (yes)
If yes, how is the feature documented? (docs)