Search in sources :

Example 1 with PhysicalColumn

use of org.apache.flink.table.api.TableColumn.PhysicalColumn in project flink by apache.

the class TableSchema method toSchema.

/**
 * Helps to migrate to the new {@link Schema} class.
 */
public Schema toSchema() {
    final Schema.Builder builder = Schema.newBuilder();
    columns.forEach(column -> {
        if (column instanceof PhysicalColumn) {
            final PhysicalColumn c = (PhysicalColumn) column;
            builder.column(c.getName(), c.getType());
        } else if (column instanceof MetadataColumn) {
            final MetadataColumn c = (MetadataColumn) column;
            builder.columnByMetadata(c.getName(), c.getType(), c.getMetadataAlias().orElse(null), c.isVirtual());
        } else if (column instanceof ComputedColumn) {
            final ComputedColumn c = (ComputedColumn) column;
            builder.columnByExpression(c.getName(), c.getExpression());
        } else {
            throw new IllegalArgumentException("Unsupported column type: " + column);
        }
    });
    watermarkSpecs.forEach(spec -> builder.watermark(spec.getRowtimeAttribute(), spec.getWatermarkExpr()));
    if (primaryKey != null) {
        builder.primaryKeyNamed(primaryKey.getName(), primaryKey.getColumns());
    }
    return builder.build();
}
Also used : MetadataColumn(org.apache.flink.table.api.TableColumn.MetadataColumn) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) PhysicalColumn(org.apache.flink.table.api.TableColumn.PhysicalColumn) ComputedColumn(org.apache.flink.table.api.TableColumn.ComputedColumn)

Aggregations

ComputedColumn (org.apache.flink.table.api.TableColumn.ComputedColumn)1 MetadataColumn (org.apache.flink.table.api.TableColumn.MetadataColumn)1 PhysicalColumn (org.apache.flink.table.api.TableColumn.PhysicalColumn)1 ResolvedSchema (org.apache.flink.table.catalog.ResolvedSchema)1