Search in sources :

Example 1 with InternalTypeInfo

use of org.apache.flink.table.runtime.typeutils.InternalTypeInfo in project flink by apache.

the class StreamExecDeduplicate method translateToPlanInternal.

@SuppressWarnings("unchecked")
@Override
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
    final ExecEdge inputEdge = getInputEdges().get(0);
    final Transformation<RowData> inputTransform = (Transformation<RowData>) inputEdge.translateToPlan(planner);
    final RowType inputRowType = (RowType) inputEdge.getOutputType();
    final InternalTypeInfo<RowData> rowTypeInfo = (InternalTypeInfo<RowData>) inputTransform.getOutputType();
    final TypeSerializer<RowData> rowSerializer = rowTypeInfo.createSerializer(planner.getExecEnv().getConfig());
    final OneInputStreamOperator<RowData, RowData> operator;
    if (isRowtime) {
        operator = new RowtimeDeduplicateOperatorTranslator(config, rowTypeInfo, rowSerializer, inputRowType, keepLastRow, generateUpdateBefore).createDeduplicateOperator();
    } else {
        operator = new ProcTimeDeduplicateOperatorTranslator(config, rowTypeInfo, rowSerializer, inputRowType, keepLastRow, generateUpdateBefore).createDeduplicateOperator();
    }
    final OneInputTransformation<RowData, RowData> transform = ExecNodeUtil.createOneInputTransformation(inputTransform, createTransformationMeta(DEDUPLICATE_TRANSFORMATION, config), operator, rowTypeInfo, inputTransform.getParallelism());
    final RowDataKeySelector selector = KeySelectorUtil.getRowDataSelector(uniqueKeys, rowTypeInfo);
    transform.setStateKeySelector(selector);
    transform.setStateKeyType(selector.getProducedType());
    return transform;
}
Also used : OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) Transformation(org.apache.flink.api.dag.Transformation) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) RowType(org.apache.flink.table.types.logical.RowType) InternalTypeInfo(org.apache.flink.table.runtime.typeutils.InternalTypeInfo) RowData(org.apache.flink.table.data.RowData) RowDataKeySelector(org.apache.flink.table.runtime.keyselector.RowDataKeySelector)

Example 2 with InternalTypeInfo

use of org.apache.flink.table.runtime.typeutils.InternalTypeInfo in project flink by apache.

the class StreamExecExchange method translateToPlanInternal.

@SuppressWarnings("unchecked")
@Override
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
    final Transformation<RowData> inputTransform = (Transformation<RowData>) getInputEdges().get(0).translateToPlan(planner);
    final StreamPartitioner<RowData> partitioner;
    final int parallelism;
    final InputProperty inputProperty = getInputProperties().get(0);
    final InputProperty.DistributionType distributionType = inputProperty.getRequiredDistribution().getType();
    switch(distributionType) {
        case SINGLETON:
            partitioner = new GlobalPartitioner<>();
            parallelism = 1;
            break;
        case HASH:
            // TODO Eliminate duplicate keys
            int[] keys = ((HashDistribution) inputProperty.getRequiredDistribution()).getKeys();
            InternalTypeInfo<RowData> inputType = (InternalTypeInfo<RowData>) inputTransform.getOutputType();
            RowDataKeySelector keySelector = KeySelectorUtil.getRowDataSelector(keys, inputType);
            partitioner = new KeyGroupStreamPartitioner<>(keySelector, DEFAULT_LOWER_BOUND_MAX_PARALLELISM);
            parallelism = ExecutionConfig.PARALLELISM_DEFAULT;
            break;
        default:
            throw new TableException(String.format("%s is not supported now!", distributionType));
    }
    final Transformation<RowData> transformation = new PartitionTransformation<>(inputTransform, partitioner);
    createTransformationMeta(EXCHANGE_TRANSFORMATION, config).fill(transformation);
    transformation.setParallelism(parallelism);
    transformation.setOutputType(InternalTypeInfo.of(getOutputType()));
    return transformation;
}
Also used : PartitionTransformation(org.apache.flink.streaming.api.transformations.PartitionTransformation) Transformation(org.apache.flink.api.dag.Transformation) TableException(org.apache.flink.table.api.TableException) InputProperty(org.apache.flink.table.planner.plan.nodes.exec.InputProperty) PartitionTransformation(org.apache.flink.streaming.api.transformations.PartitionTransformation) HashDistribution(org.apache.flink.table.planner.plan.nodes.exec.InputProperty.HashDistribution) InternalTypeInfo(org.apache.flink.table.runtime.typeutils.InternalTypeInfo) RowData(org.apache.flink.table.data.RowData) RowDataKeySelector(org.apache.flink.table.runtime.keyselector.RowDataKeySelector)

Example 3 with InternalTypeInfo

use of org.apache.flink.table.runtime.typeutils.InternalTypeInfo in project flink by apache.

the class StreamExecIntervalJoin method createProcTimeJoin.

private TwoInputTransformation<RowData, RowData, RowData> createProcTimeJoin(Transformation<RowData> leftInputTransform, Transformation<RowData> rightInputTransform, InternalTypeInfo<RowData> returnTypeInfo, IntervalJoinFunction joinFunction, JoinSpec joinSpec, IntervalJoinSpec.WindowBounds windowBounds, ReadableConfig config) {
    InternalTypeInfo<RowData> leftTypeInfo = (InternalTypeInfo<RowData>) leftInputTransform.getOutputType();
    InternalTypeInfo<RowData> rightTypeInfo = (InternalTypeInfo<RowData>) rightInputTransform.getOutputType();
    ProcTimeIntervalJoin procJoinFunc = new ProcTimeIntervalJoin(joinSpec.getJoinType(), windowBounds.getLeftLowerBound(), windowBounds.getLeftUpperBound(), leftTypeInfo, rightTypeInfo, joinFunction);
    return ExecNodeUtil.createTwoInputTransformation(leftInputTransform, rightInputTransform, createTransformationMeta(INTERVAL_JOIN_TRANSFORMATION, config), new KeyedCoProcessOperator<>(procJoinFunc), returnTypeInfo, leftInputTransform.getParallelism());
}
Also used : RowData(org.apache.flink.table.data.RowData) ProcTimeIntervalJoin(org.apache.flink.table.runtime.operators.join.interval.ProcTimeIntervalJoin) InternalTypeInfo(org.apache.flink.table.runtime.typeutils.InternalTypeInfo)

Example 4 with InternalTypeInfo

use of org.apache.flink.table.runtime.typeutils.InternalTypeInfo in project flink by apache.

the class StreamExecMatch method translateToPlanInternal.

@SuppressWarnings("unchecked")
@Override
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
    final ExecEdge inputEdge = getInputEdges().get(0);
    final Transformation<RowData> inputTransform = (Transformation<RowData>) inputEdge.translateToPlan(planner);
    final RowType inputRowType = (RowType) inputEdge.getOutputType();
    checkOrderKeys(inputRowType);
    final EventComparator<RowData> eventComparator = createEventComparator(config, inputRowType);
    final Transformation<RowData> timestampedInputTransform = translateOrder(inputTransform, inputRowType);
    final Tuple2<Pattern<RowData, RowData>, List<String>> cepPatternAndNames = translatePattern(matchSpec, config.getTableConfig(), planner.getRelBuilder(), inputRowType);
    final Pattern<RowData, RowData> cepPattern = cepPatternAndNames.f0;
    // TODO remove this once it is supported in CEP library
    if (NFACompiler.canProduceEmptyMatches(cepPattern)) {
        throw new TableException("Patterns that can produce empty matches are not supported. There must be at least one non-optional state.");
    }
    // TODO remove this once it is supported in CEP library
    if (cepPattern.getQuantifier().hasProperty(Quantifier.QuantifierProperty.GREEDY)) {
        throw new TableException("Greedy quantifiers are not allowed as the last element of a Pattern yet. " + "Finish your pattern with either a simple variable or reluctant quantifier.");
    }
    if (matchSpec.isAllRows()) {
        throw new TableException("All rows per match mode is not supported yet.");
    }
    final int[] partitionKeys = matchSpec.getPartition().getFieldIndices();
    final SortSpec.SortFieldSpec timeOrderField = matchSpec.getOrderKeys().getFieldSpec(0);
    final LogicalType timeOrderFieldType = inputRowType.getTypeAt(timeOrderField.getFieldIndex());
    final boolean isProctime = TypeCheckUtils.isProcTime(timeOrderFieldType);
    final InternalTypeInfo<RowData> inputTypeInfo = (InternalTypeInfo<RowData>) inputTransform.getOutputType();
    final TypeSerializer<RowData> inputSerializer = inputTypeInfo.createSerializer(planner.getExecEnv().getConfig());
    final NFACompiler.NFAFactory<RowData> nfaFactory = NFACompiler.compileFactory(cepPattern, false);
    final MatchCodeGenerator generator = new MatchCodeGenerator(new CodeGeneratorContext(config.getTableConfig()), planner.getRelBuilder(), // nullableInput
    false, JavaScalaConversionUtil.toScala(cepPatternAndNames.f1), JavaScalaConversionUtil.toScala(Optional.empty()), CodeGenUtils.DEFAULT_COLLECTOR_TERM());
    generator.bindInput(inputRowType, CodeGenUtils.DEFAULT_INPUT1_TERM(), JavaScalaConversionUtil.toScala(Optional.empty()));
    final PatternProcessFunctionRunner patternProcessFunction = generator.generateOneRowPerMatchExpression((RowType) getOutputType(), partitionKeys, matchSpec.getMeasures());
    final CepOperator<RowData, RowData, RowData> operator = new CepOperator<>(inputSerializer, isProctime, nfaFactory, eventComparator, cepPattern.getAfterMatchSkipStrategy(), patternProcessFunction, null);
    final OneInputTransformation<RowData, RowData> transform = ExecNodeUtil.createOneInputTransformation(timestampedInputTransform, createTransformationMeta(MATCH_TRANSFORMATION, config), operator, InternalTypeInfo.of(getOutputType()), timestampedInputTransform.getParallelism());
    final RowDataKeySelector selector = KeySelectorUtil.getRowDataSelector(partitionKeys, inputTypeInfo);
    transform.setStateKeySelector(selector);
    transform.setStateKeyType(selector.getProducedType());
    if (inputsContainSingleton()) {
        transform.setParallelism(1);
        transform.setMaxParallelism(1);
    }
    return transform;
}
Also used : OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) Transformation(org.apache.flink.api.dag.Transformation) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) RowType(org.apache.flink.table.types.logical.RowType) LogicalType(org.apache.flink.table.types.logical.LogicalType) NFACompiler(org.apache.flink.cep.nfa.compiler.NFACompiler) RowData(org.apache.flink.table.data.RowData) RowDataKeySelector(org.apache.flink.table.runtime.keyselector.RowDataKeySelector) List(java.util.List) ArrayList(java.util.ArrayList) Pattern(org.apache.flink.cep.pattern.Pattern) TableException(org.apache.flink.table.api.TableException) CodeGeneratorContext(org.apache.flink.table.planner.codegen.CodeGeneratorContext) InternalTypeInfo(org.apache.flink.table.runtime.typeutils.InternalTypeInfo) MatchCodeGenerator(org.apache.flink.table.planner.codegen.MatchCodeGenerator) PatternProcessFunctionRunner(org.apache.flink.table.runtime.operators.match.PatternProcessFunctionRunner) CepOperator(org.apache.flink.cep.operator.CepOperator) SortSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.SortSpec)

Example 5 with InternalTypeInfo

use of org.apache.flink.table.runtime.typeutils.InternalTypeInfo in project flink by apache.

the class StreamExecIntervalJoin method createRowTimeJoin.

private TwoInputTransformation<RowData, RowData, RowData> createRowTimeJoin(Transformation<RowData> leftInputTransform, Transformation<RowData> rightInputTransform, InternalTypeInfo<RowData> returnTypeInfo, IntervalJoinFunction joinFunction, JoinSpec joinSpec, IntervalJoinSpec.WindowBounds windowBounds, ReadableConfig config) {
    InternalTypeInfo<RowData> leftTypeInfo = (InternalTypeInfo<RowData>) leftInputTransform.getOutputType();
    InternalTypeInfo<RowData> rightTypeInfo = (InternalTypeInfo<RowData>) rightInputTransform.getOutputType();
    RowTimeIntervalJoin rowJoinFunc = new RowTimeIntervalJoin(joinSpec.getJoinType(), windowBounds.getLeftLowerBound(), windowBounds.getLeftUpperBound(), // allowedLateness
    0L, leftTypeInfo, rightTypeInfo, joinFunction, windowBounds.getLeftTimeIdx(), windowBounds.getRightTimeIdx());
    return ExecNodeUtil.createTwoInputTransformation(leftInputTransform, rightInputTransform, createTransformationMeta(INTERVAL_JOIN_TRANSFORMATION, config), new KeyedCoProcessOperatorWithWatermarkDelay<>(rowJoinFunc, rowJoinFunc.getMaxOutputDelay()), returnTypeInfo, leftInputTransform.getParallelism());
}
Also used : RowData(org.apache.flink.table.data.RowData) InternalTypeInfo(org.apache.flink.table.runtime.typeutils.InternalTypeInfo) RowTimeIntervalJoin(org.apache.flink.table.runtime.operators.join.interval.RowTimeIntervalJoin)

Aggregations

RowData (org.apache.flink.table.data.RowData)8 InternalTypeInfo (org.apache.flink.table.runtime.typeutils.InternalTypeInfo)8 Transformation (org.apache.flink.api.dag.Transformation)4 RowDataKeySelector (org.apache.flink.table.runtime.keyselector.RowDataKeySelector)4 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)3 ExecEdge (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge)3 TableException (org.apache.flink.table.api.TableException)2 LogicalType (org.apache.flink.table.types.logical.LogicalType)2 RowType (org.apache.flink.table.types.logical.RowType)2 Timestamp (java.sql.Timestamp)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1 BasicArrayTypeInfo (org.apache.flink.api.common.typeinfo.BasicArrayTypeInfo)1 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)1 CompositeType (org.apache.flink.api.common.typeutils.CompositeType)1 Tuple (org.apache.flink.api.java.tuple.Tuple)1 PojoTypeInfo (org.apache.flink.api.java.typeutils.PojoTypeInfo)1 TupleTypeInfoBase (org.apache.flink.api.java.typeutils.TupleTypeInfoBase)1