Search in sources :

Example 51 with TableException

use of org.apache.flink.table.api.TableException in project flink by apache.

the class BuiltInFunctionDefinitions method getDefinitions.

@Internal
public static List<BuiltInFunctionDefinition> getDefinitions() {
    final Field[] fields = BuiltInFunctionDefinitions.class.getFields();
    final List<BuiltInFunctionDefinition> list = new ArrayList<>(fields.length);
    for (Field field : fields) {
        if (FunctionDefinition.class.isAssignableFrom(field.getType())) {
            try {
                final BuiltInFunctionDefinition funcDef = (BuiltInFunctionDefinition) field.get(BuiltInFunctionDefinitions.class);
                list.add(Preconditions.checkNotNull(funcDef));
            } catch (IllegalAccessException e) {
                throw new TableException("The function definition for field " + field.getName() + " is not accessible.", e);
            }
        }
    }
    return list;
}
Also used : Field(java.lang.reflect.Field) TableException(org.apache.flink.table.api.TableException) ArrayList(java.util.ArrayList) Internal(org.apache.flink.annotation.Internal)

Example 52 with TableException

use of org.apache.flink.table.api.TableException in project flink by apache.

the class TableFactoryService method discoverFactories.

/**
 * Searches for factories using Java service providers.
 *
 * @return all factories in the classpath
 */
private static List<TableFactory> discoverFactories(Optional<ClassLoader> classLoader) {
    try {
        List<TableFactory> result = new LinkedList<>();
        ClassLoader cl = classLoader.orElse(Thread.currentThread().getContextClassLoader());
        ServiceLoader.load(TableFactory.class, cl).iterator().forEachRemaining(result::add);
        return result;
    } catch (ServiceConfigurationError e) {
        LOG.error("Could not load service provider for table factories.", e);
        throw new TableException("Could not load service provider for table factories.", e);
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) ServiceConfigurationError(java.util.ServiceConfigurationError) LinkedList(java.util.LinkedList)

Example 53 with TableException

use of org.apache.flink.table.api.TableException in project flink by apache.

the class UserDefinedFunctionHelper method createSpecializedFunction.

/**
 * Creates the runtime implementation of a {@link FunctionDefinition} as an instance of {@link
 * UserDefinedFunction}.
 *
 * @see SpecializedFunction
 */
public static UserDefinedFunction createSpecializedFunction(String functionName, FunctionDefinition definition, CallContext callContext, ClassLoader builtInClassLoader, @Nullable ReadableConfig configuration) {
    if (definition instanceof SpecializedFunction) {
        final SpecializedFunction specialized = (SpecializedFunction) definition;
        final SpecializedContext specializedContext = new SpecializedContext() {

            @Override
            public CallContext getCallContext() {
                return callContext;
            }

            @Override
            public ReadableConfig getConfiguration() {
                if (configuration == null) {
                    throw new TableException("Access to configuration is currently not supported for all kinds of calls.");
                }
                return configuration;
            }

            @Override
            public ClassLoader getBuiltInClassLoader() {
                return builtInClassLoader;
            }
        };
        final UserDefinedFunction udf = specialized.specialize(specializedContext);
        checkState(udf.getKind() == definition.getKind(), "Function kind must not change during specialization.");
        return udf;
    } else if (definition instanceof UserDefinedFunction) {
        return (UserDefinedFunction) definition;
    } else {
        throw new TableException(String.format("Could not find a runtime implementation for function definition '%s'.", functionName));
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) SpecializedContext(org.apache.flink.table.functions.SpecializedFunction.SpecializedContext)

Example 54 with TableException

use of org.apache.flink.table.api.TableException in project flink by apache.

the class DefaultExecutor method createPipeline.

@Override
public Pipeline createPipeline(List<Transformation<?>> transformations, ReadableConfig tableConfiguration, @Nullable String defaultJobName) {
    // reconfigure before a stream graph is generated
    executionEnvironment.configure(tableConfiguration);
    // create stream graph
    final RuntimeExecutionMode mode = getConfiguration().get(ExecutionOptions.RUNTIME_MODE);
    switch(mode) {
        case BATCH:
            configureBatchSpecificProperties();
            break;
        case STREAMING:
            break;
        case AUTOMATIC:
        default:
            throw new TableException(String.format("Unsupported runtime mode: %s", mode));
    }
    final StreamGraph streamGraph = executionEnvironment.generateStreamGraph(transformations);
    setJobName(streamGraph, defaultJobName);
    return streamGraph;
}
Also used : TableException(org.apache.flink.table.api.TableException) StreamGraph(org.apache.flink.streaming.api.graph.StreamGraph) RuntimeExecutionMode(org.apache.flink.api.common.RuntimeExecutionMode)

Example 55 with TableException

use of org.apache.flink.table.api.TableException in project flink by apache.

the class StructuredObjectConverter method open.

@Override
public void open(ClassLoader classLoader) {
    for (DataStructureConverter<Object, Object> fieldConverter : fieldConverters) {
        fieldConverter.open(classLoader);
    }
    try {
        final Class<?> compiledConverter = CompileUtils.compile(classLoader, generatedName, generatedCode);
        generatedConverter = (DataStructureConverter<RowData, T>) compiledConverter.getConstructor(RowData.FieldGetter[].class, DataStructureConverter[].class).newInstance(fieldGetters, fieldConverters);
    } catch (Throwable t) {
        throw new TableException("Error while generating structured type converter.", t);
    }
    generatedConverter.open(classLoader);
}
Also used : RowData(org.apache.flink.table.data.RowData) GenericRowData(org.apache.flink.table.data.GenericRowData) TableException(org.apache.flink.table.api.TableException)

Aggregations

TableException (org.apache.flink.table.api.TableException)163 RowData (org.apache.flink.table.data.RowData)35 RowType (org.apache.flink.table.types.logical.RowType)35 Transformation (org.apache.flink.api.dag.Transformation)28 ArrayList (java.util.ArrayList)27 ExecEdge (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge)24 LogicalType (org.apache.flink.table.types.logical.LogicalType)24 List (java.util.List)22 DataType (org.apache.flink.table.types.DataType)19 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)18 ValidationException (org.apache.flink.table.api.ValidationException)17 IOException (java.io.IOException)13 AggregateCall (org.apache.calcite.rel.core.AggregateCall)13 ValueLiteralExpression (org.apache.flink.table.expressions.ValueLiteralExpression)13 RowDataKeySelector (org.apache.flink.table.runtime.keyselector.RowDataKeySelector)13 Optional (java.util.Optional)11 Configuration (org.apache.flink.configuration.Configuration)11 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)11 Constructor (java.lang.reflect.Constructor)10 Arrays (java.util.Arrays)9