KurtYoung commented on a change in pull request #10096:
[FLINK-14623][table-api] Add computed column information into TableSc…
URL: https://github.com/apache/flink/pull/10096#discussion_r343010581
##########
File path:
flink-table/flink-table-common/src/main/java/org/apache/flink/table/api/TableSchema.java
##########
@@ -209,18 +173,48 @@ public int getFieldCount() {
* @param fieldIndex the index of the field
*/
public Optional<String> getFieldName(int fieldIndex) {
- if (fieldIndex < 0 || fieldIndex >= fieldNames.length) {
+ if (fieldIndex < 0 || fieldIndex >= columns.size()) {
+ return Optional.empty();
+ }
+ return Optional.of(this.columns.get(fieldIndex).getName());
+ }
+
+ /**
+ * Returns the {@link TableColumn} instance for the given field index.
+ *
+ * @param fieldIndex the index of the field
+ */
+ public Optional<TableColumn> getTableColumn(int fieldIndex) {
+ if (fieldIndex < 0 || fieldIndex >= columns.size()) {
return Optional.empty();
}
- return Optional.of(fieldNames[fieldIndex]);
+ return Optional.of(this.columns.get(fieldIndex));
+ }
+
+ /**
+ * Returns the {@link TableColumn} instance for the given field name.
+ *
+ * @param fieldName the name of the field
+ */
+ public Optional<TableColumn> getTableColumn(String fieldName) {
+ return this.columns.stream()
+ .filter(column -> column.getName().equals(fieldName))
+ .findFirst();
+ }
+
+ /**
+ * Returns all the {@link TableColumn}s for this table schema.
+ */
+ public TableColumn[] getTableColumns() {
Review comment:
Keep it for backward compatibility...
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services