Search in sources :

Example 1 with CallContextMock

use of org.apache.flink.table.types.inference.utils.CallContextMock in project flink by apache.

the class InputTypeStrategiesTestBase method runTypeInference.

private TypeInferenceUtil.Result runTypeInference(List<DataType> actualArgumentTypes) {
    final FunctionDefinitionMock functionDefinitionMock = new FunctionDefinitionMock();
    functionDefinitionMock.functionKind = FunctionKind.SCALAR;
    final CallContextMock callContextMock = new CallContextMock();
    callContextMock.typeFactory = new DataTypeFactoryMock();
    callContextMock.functionDefinition = functionDefinitionMock;
    callContextMock.argumentDataTypes = actualArgumentTypes;
    callContextMock.argumentLiterals = IntStream.range(0, actualArgumentTypes.size()).mapToObj(i -> testSpec.literalPos != null && i == testSpec.literalPos).collect(Collectors.toList());
    callContextMock.argumentValues = IntStream.range(0, actualArgumentTypes.size()).mapToObj(i -> (testSpec.literalPos != null && i == testSpec.literalPos) ? Optional.ofNullable(testSpec.literalValue) : Optional.empty()).collect(Collectors.toList());
    callContextMock.argumentNulls = IntStream.range(0, actualArgumentTypes.size()).mapToObj(i -> false).collect(Collectors.toList());
    callContextMock.name = "f";
    callContextMock.outputDataType = Optional.empty();
    final TypeInferenceUtil.SurroundingInfo surroundingInfo;
    if (testSpec.surroundingStrategy != null) {
        final TypeInference outerTypeInference = TypeInference.newBuilder().inputTypeStrategy(testSpec.surroundingStrategy).outputTypeStrategy(TypeStrategies.MISSING).build();
        surroundingInfo = TypeInferenceUtil.SurroundingInfo.of("f_outer", functionDefinitionMock, outerTypeInference, 1, 0, callContextMock.isGroupedAggregation);
    } else {
        surroundingInfo = null;
    }
    return TypeInferenceUtil.runTypeInference(createTypeInference(), callContextMock, surroundingInfo);
}
Also used : CallContextMock(org.apache.flink.table.types.inference.utils.CallContextMock) DataTypeFactoryMock(org.apache.flink.table.types.utils.DataTypeFactoryMock) FunctionDefinitionMock(org.apache.flink.table.types.inference.utils.FunctionDefinitionMock)

Example 2 with CallContextMock

use of org.apache.flink.table.types.inference.utils.CallContextMock in project flink by apache.

the class TypeStrategiesTestBase method runTypeInference.

// --------------------------------------------------------------------------------------------
private TypeInferenceUtil.Result runTypeInference() {
    final FunctionDefinitionMock functionDefinitionMock = new FunctionDefinitionMock();
    functionDefinitionMock.functionKind = FunctionKind.SCALAR;
    final CallContextMock callContextMock = new CallContextMock();
    callContextMock.functionDefinition = functionDefinitionMock;
    callContextMock.argumentDataTypes = testSpec.inputTypes;
    callContextMock.name = "f";
    callContextMock.outputDataType = Optional.empty();
    callContextMock.isGroupedAggregation = testSpec.isGroupedAggregation;
    callContextMock.argumentLiterals = IntStream.range(0, testSpec.inputTypes.size()).mapToObj(i -> testSpec.literalPos != null && i == testSpec.literalPos).collect(Collectors.toList());
    callContextMock.argumentValues = IntStream.range(0, testSpec.inputTypes.size()).mapToObj(i -> (testSpec.literalPos != null && i == testSpec.literalPos) ? Optional.ofNullable(testSpec.literalValue) : Optional.empty()).collect(Collectors.toList());
    final TypeInference typeInference = TypeInference.newBuilder().inputTypeStrategy(InputTypeStrategies.WILDCARD).outputTypeStrategy(testSpec.strategy).build();
    return TypeInferenceUtil.runTypeInference(typeInference, callContextMock, null);
}
Also used : CallContextMock(org.apache.flink.table.types.inference.utils.CallContextMock) FunctionDefinitionMock(org.apache.flink.table.types.inference.utils.FunctionDefinitionMock)

Aggregations

CallContextMock (org.apache.flink.table.types.inference.utils.CallContextMock)2 FunctionDefinitionMock (org.apache.flink.table.types.inference.utils.FunctionDefinitionMock)2 DataTypeFactoryMock (org.apache.flink.table.types.utils.DataTypeFactoryMock)1