Search in sources :

Example 1 with CodeAnalyzerException

use of org.apache.flink.api.java.sca.CodeAnalyzerException in project flink by apache.

the class UdfOperatorUtils method analyzeSingleInputUdf.

public static void analyzeSingleInputUdf(SingleInputUdfOperator<?, ?, ?> operator, Class<?> udfBaseClass, String defaultName, Function udf, Keys<?> key) {
    final CodeAnalysisMode mode = operator.getExecutionEnvironment().getConfig().getCodeAnalysisMode();
    if (mode != CodeAnalysisMode.DISABLE && !udf.getClass().isAnnotationPresent(FunctionAnnotation.SkipCodeAnalysis.class)) {
        final String operatorName = operator.getName() != null ? operator.getName() : udfBaseClass.getSimpleName() + " at " + defaultName;
        try {
            final UdfAnalyzer analyzer = new UdfAnalyzer(udfBaseClass, udf.getClass(), operatorName, operator.getInputType(), null, operator.getResultType(), key, null, mode == CodeAnalysisMode.OPTIMIZE);
            final boolean success = analyzer.analyze();
            if (success) {
                if (mode == CodeAnalysisMode.OPTIMIZE && !operator.udfWithForwardedFieldsAnnotation(udf.getClass())) {
                    analyzer.addSemanticPropertiesHints();
                    operator.setSemanticProperties((SingleInputSemanticProperties) analyzer.getSemanticProperties());
                    operator.setAnalyzedUdfSemanticsFlag();
                } else if (mode == CodeAnalysisMode.HINT) {
                    analyzer.addSemanticPropertiesHints();
                }
                analyzer.printToLogger(LOG);
            }
        } catch (InvalidTypesException e) {
            LOG.debug("Unable to do code analysis due to missing type information.", e);
        } catch (CodeAnalyzerException e) {
            LOG.debug("Code analysis failed.", e);
        }
    }
}
Also used : UdfAnalyzer(org.apache.flink.api.java.sca.UdfAnalyzer) CodeAnalyzerException(org.apache.flink.api.java.sca.CodeAnalyzerException) CodeAnalysisMode(org.apache.flink.api.common.CodeAnalysisMode) InvalidTypesException(org.apache.flink.api.common.functions.InvalidTypesException) FunctionAnnotation(org.apache.flink.api.java.functions.FunctionAnnotation)

Example 2 with CodeAnalyzerException

use of org.apache.flink.api.java.sca.CodeAnalyzerException in project flink by apache.

the class UdfOperatorUtils method analyzeDualInputUdf.

public static void analyzeDualInputUdf(TwoInputUdfOperator<?, ?, ?, ?> operator, Class<?> udfBaseClass, String defaultName, Function udf, Keys<?> key1, Keys<?> key2) {
    final CodeAnalysisMode mode = operator.getExecutionEnvironment().getConfig().getCodeAnalysisMode();
    if (mode != CodeAnalysisMode.DISABLE && !udf.getClass().isAnnotationPresent(FunctionAnnotation.SkipCodeAnalysis.class)) {
        final String operatorName = operator.getName() != null ? operator.getName() : udfBaseClass.getSimpleName() + " at " + defaultName;
        try {
            final UdfAnalyzer analyzer = new UdfAnalyzer(udfBaseClass, udf.getClass(), operatorName, operator.getInput1Type(), operator.getInput2Type(), operator.getResultType(), key1, key2, mode == CodeAnalysisMode.OPTIMIZE);
            final boolean success = analyzer.analyze();
            if (success) {
                if (mode == CodeAnalysisMode.OPTIMIZE && !(operator.udfWithForwardedFieldsFirstAnnotation(udf.getClass()) || operator.udfWithForwardedFieldsSecondAnnotation(udf.getClass()))) {
                    analyzer.addSemanticPropertiesHints();
                    operator.setSemanticProperties((DualInputSemanticProperties) analyzer.getSemanticProperties());
                    operator.setAnalyzedUdfSemanticsFlag();
                } else if (mode == CodeAnalysisMode.HINT) {
                    analyzer.addSemanticPropertiesHints();
                }
                analyzer.printToLogger(LOG);
            }
        } catch (InvalidTypesException e) {
            LOG.debug("Unable to do code analysis due to missing type information.", e);
        } catch (CodeAnalyzerException e) {
            LOG.debug("Code analysis failed.", e);
        }
    }
}
Also used : UdfAnalyzer(org.apache.flink.api.java.sca.UdfAnalyzer) CodeAnalyzerException(org.apache.flink.api.java.sca.CodeAnalyzerException) CodeAnalysisMode(org.apache.flink.api.common.CodeAnalysisMode) InvalidTypesException(org.apache.flink.api.common.functions.InvalidTypesException) FunctionAnnotation(org.apache.flink.api.java.functions.FunctionAnnotation)

Aggregations

CodeAnalysisMode (org.apache.flink.api.common.CodeAnalysisMode)2 InvalidTypesException (org.apache.flink.api.common.functions.InvalidTypesException)2 FunctionAnnotation (org.apache.flink.api.java.functions.FunctionAnnotation)2 CodeAnalyzerException (org.apache.flink.api.java.sca.CodeAnalyzerException)2 UdfAnalyzer (org.apache.flink.api.java.sca.UdfAnalyzer)2