twalthr commented on a change in pull request #17642:
URL: https://github.com/apache/flink/pull/17642#discussion_r742614948
##########
File path:
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/DataType.java
##########
@@ -215,6 +217,28 @@ public static DataType projectFields(DataType dataType,
int[] indexes) {
return DataTypeUtils.projectRow(dataType, indexes);
}
+ /**
+ * Exclude fields with the provided {@code indexes} from the {@code
dataType}. This method
+ * behaves as the inverse method of {@link #projectFields(DataType,
int[])}.
+ *
+ * <p>Note: This method only excludes (possibly nested) fields in the
top-level row.
+ */
+ public static DataType excludeFields(DataType dataType, int[] indexes) {
+ // Convert indexes to set
+ Set<Integer> indexesSet = new HashSet<>();
+ for (int index : indexes) {
+ indexesSet.add(index);
+ }
+
+ // Compute projection
+ int[] projection =
+ IntStream.range(0, DataType.getFieldCount(dataType))
+ .filter(i -> !indexesSet.contains(i))
+ .toArray();
+
+ return DataTypeUtils.projectRow(dataType, projection);
Review comment:
nit: use `DataType.projectRow`?
##########
File path:
flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/DataTypeTest.java
##########
@@ -220,4 +220,21 @@ public void getFields() {
assertEquals(Collections.emptyList(),
DataType.getFields(ARRAY(INT())));
assertEquals(Collections.emptyList(), DataType.getFields(INT()));
}
+
+ @Test
+ public void excludeFields() {
Review comment:
nit: usually our test methods start with `test`. please also update the
methods above.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]