Search in sources :

Example 76 with DataType

use of org.apache.flink.table.types.DataType in project flink by apache.

the class TableSchemaTest method testPhysicalRowDataType.

@Test
public void testPhysicalRowDataType() {
    final TableSchema schema = TableSchema.builder().add(TableColumn.physical("f0", DataTypes.BIGINT())).add(TableColumn.metadata("f1", DataTypes.BIGINT(), true)).add(TableColumn.metadata("f2", DataTypes.BIGINT(), false)).add(TableColumn.physical("f3", DataTypes.STRING())).add(TableColumn.computed("f4", DataTypes.BIGINT(), "f0 + 1")).add(TableColumn.metadata("f5", DataTypes.BIGINT(), false)).build();
    final DataType expectedDataType = DataTypes.ROW(DataTypes.FIELD("f0", DataTypes.BIGINT()), DataTypes.FIELD("f3", DataTypes.STRING())).notNull();
    assertThat(schema.toPhysicalRowDataType(), equalTo(expectedDataType));
}
Also used : DataType(org.apache.flink.table.types.DataType) Test(org.junit.Test)

Example 77 with DataType

use of org.apache.flink.table.types.DataType in project flink by apache.

the class TableSchemaTest method testPersistedRowDataType.

@Test
public void testPersistedRowDataType() {
    final TableSchema schema = TableSchema.builder().add(TableColumn.physical("f0", DataTypes.BIGINT())).add(TableColumn.metadata("f1", DataTypes.BIGINT(), true)).add(TableColumn.metadata("f2", DataTypes.BIGINT(), false)).add(TableColumn.physical("f3", DataTypes.STRING())).add(TableColumn.computed("f4", DataTypes.BIGINT(), "f0 + 1")).add(TableColumn.metadata("f5", DataTypes.BIGINT(), false)).build();
    final DataType expectedDataType = DataTypes.ROW(DataTypes.FIELD("f0", DataTypes.BIGINT()), DataTypes.FIELD("f2", DataTypes.BIGINT()), DataTypes.FIELD("f3", DataTypes.STRING()), DataTypes.FIELD("f5", DataTypes.BIGINT())).notNull();
    assertThat(schema.toPersistedRowDataType(), equalTo(expectedDataType));
}
Also used : DataType(org.apache.flink.table.types.DataType) Test(org.junit.Test)

Example 78 with DataType

use of org.apache.flink.table.types.DataType in project flink by apache.

the class CommonExecLegacySink method translateToTransformation.

/**
 * Translates {@link TableSink} into a {@link Transformation}.
 *
 * @param withChangeFlag Set to true to emit records with change flags.
 * @return The {@link Transformation} that corresponds to the translated {@link TableSink}.
 */
@SuppressWarnings("unchecked")
private Transformation<T> translateToTransformation(PlannerBase planner, ExecNodeConfig config, boolean withChangeFlag) {
    // if no change flags are requested, verify table is an insert-only (append-only) table.
    if (!withChangeFlag && needRetraction) {
        throw new TableException("Table is not an append-only table. " + "Use the toRetractStream() in order to handle add and retract messages.");
    }
    final ExecEdge inputEdge = getInputEdges().get(0);
    final Transformation<RowData> inputTransform = (Transformation<RowData>) inputEdge.translateToPlan(planner);
    final RowType inputRowType = (RowType) inputEdge.getOutputType();
    final RowType convertedInputRowType = checkAndConvertInputTypeIfNeeded(inputRowType);
    final DataType resultDataType = tableSink.getConsumedDataType();
    if (CodeGenUtils.isInternalClass(resultDataType)) {
        return (Transformation<T>) inputTransform;
    } else {
        final int rowtimeIndex = getRowtimeIndex(inputRowType);
        final DataType physicalOutputType = TableSinkUtils.inferSinkPhysicalDataType(resultDataType, convertedInputRowType, withChangeFlag);
        final TypeInformation<T> outputTypeInfo = SinkCodeGenerator.deriveSinkOutputTypeInfo(tableSink, physicalOutputType, withChangeFlag);
        final CodeGenOperatorFactory<T> converterOperator = SinkCodeGenerator.generateRowConverterOperator(new CodeGeneratorContext(config.getTableConfig()), convertedInputRowType, tableSink, physicalOutputType, withChangeFlag, "SinkConversion", rowtimeIndex);
        final String description = "SinkConversion To " + resultDataType.getConversionClass().getSimpleName();
        return ExecNodeUtil.createOneInputTransformation(inputTransform, createFormattedTransformationName(description, "SinkConversion", config), createFormattedTransformationDescription(description, config), converterOperator, outputTypeInfo, inputTransform.getParallelism());
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) Transformation(org.apache.flink.api.dag.Transformation) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) CodeGeneratorContext(org.apache.flink.table.planner.codegen.CodeGeneratorContext) RowType(org.apache.flink.table.types.logical.RowType) RowData(org.apache.flink.table.data.RowData) DataType(org.apache.flink.table.types.DataType)

Example 79 with DataType

use of org.apache.flink.table.types.DataType in project flink by apache.

the class WritingMetadataSpec method apply.

@Override
public void apply(DynamicTableSink tableSink) {
    if (tableSink instanceof SupportsWritingMetadata) {
        DataType consumedDataType = TypeConversions.fromLogicalToDataType(consumedType);
        ((SupportsWritingMetadata) tableSink).applyWritableMetadata(metadataKeys, consumedDataType);
    } else {
        throw new TableException(String.format("%s does not support SupportsWritingMetadata.", tableSink.getClass().getName()));
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) SupportsWritingMetadata(org.apache.flink.table.connector.sink.abilities.SupportsWritingMetadata) DataType(org.apache.flink.table.types.DataType)

Example 80 with DataType

use of org.apache.flink.table.types.DataType in project flink by apache.

the class BatchExecLegacySink method checkAndConvertInputTypeIfNeeded.

@Override
protected RowType checkAndConvertInputTypeIfNeeded(RowType inputRowType) {
    final DataType resultDataType = tableSink.getConsumedDataType();
    validateType(resultDataType);
    return inputRowType;
}
Also used : DataType(org.apache.flink.table.types.DataType)

Aggregations

DataType (org.apache.flink.table.types.DataType)260 Test (org.junit.Test)72 RowType (org.apache.flink.table.types.logical.RowType)59 LogicalType (org.apache.flink.table.types.logical.LogicalType)58 RowData (org.apache.flink.table.data.RowData)54 List (java.util.List)38 FieldsDataType (org.apache.flink.table.types.FieldsDataType)32 ValidationException (org.apache.flink.table.api.ValidationException)31 ArrayList (java.util.ArrayList)29 Collectors (java.util.stream.Collectors)24 AtomicDataType (org.apache.flink.table.types.AtomicDataType)24 Map (java.util.Map)23 Internal (org.apache.flink.annotation.Internal)23 TableException (org.apache.flink.table.api.TableException)23 HashMap (java.util.HashMap)22 GenericRowData (org.apache.flink.table.data.GenericRowData)22 Row (org.apache.flink.types.Row)22 TableSchema (org.apache.flink.table.api.TableSchema)20 TypeConversions.fromLogicalToDataType (org.apache.flink.table.types.utils.TypeConversions.fromLogicalToDataType)19 ResolvedSchema (org.apache.flink.table.catalog.ResolvedSchema)18