danny0405 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_r343011180
########## 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() { + return this.columns.toArray(new TableColumn[0]); } /** * Converts a table schema into a (nested) data type describing a {@link DataTypes#ROW(Field...)}. Review comment: Sure, thanks. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services