Search in sources :

Example 36 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class ParquetVectorizedInputFormat method clipParquetSchema.

/**
 * Clips `parquetSchema` according to `fieldNames`.
 */
private MessageType clipParquetSchema(GroupType parquetSchema) {
    Type[] types = new Type[projectedFields.length];
    if (isCaseSensitive) {
        for (int i = 0; i < projectedFields.length; ++i) {
            String fieldName = projectedFields[i];
            if (!parquetSchema.containsField(fieldName)) {
                LOG.warn("{} does not exist in {}, will fill the field with null.", fieldName, parquetSchema);
                types[i] = ParquetSchemaConverter.convertToParquetType(fieldName, projectedTypes[i]);
                unknownFieldsIndices.add(i);
            } else {
                types[i] = parquetSchema.getType(fieldName);
            }
        }
    } else {
        Map<String, Type> caseInsensitiveFieldMap = new HashMap<>();
        for (Type type : parquetSchema.getFields()) {
            caseInsensitiveFieldMap.compute(type.getName().toLowerCase(Locale.ROOT), (key, previousType) -> {
                if (previousType != null) {
                    throw new FlinkRuntimeException("Parquet with case insensitive mode should have no duplicate key: " + key);
                }
                return type;
            });
        }
        for (int i = 0; i < projectedFields.length; ++i) {
            Type type = caseInsensitiveFieldMap.get(projectedFields[i].toLowerCase(Locale.ROOT));
            if (type == null) {
                LOG.warn("{} does not exist in {}, will fill the field with null.", projectedFields[i], parquetSchema);
                type = ParquetSchemaConverter.convertToParquetType(projectedFields[i].toLowerCase(Locale.ROOT), projectedTypes[i]);
                unknownFieldsIndices.add(i);
            }
            // TODO clip for array,map,row types.
            types[i] = type;
        }
    }
    return Types.buildMessage().addFields(types).named("flink-parquet");
}
Also used : RowType(org.apache.flink.table.types.logical.RowType) GroupType(org.apache.parquet.schema.GroupType) MessageType(org.apache.parquet.schema.MessageType) LogicalType(org.apache.flink.table.types.logical.LogicalType) Type(org.apache.parquet.schema.Type) HashMap(java.util.HashMap) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException)

Example 37 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class ParquetColumnarRowSplitReader method clipParquetSchema.

/**
 * Clips `parquetSchema` according to `fieldNames`.
 */
private static MessageType clipParquetSchema(GroupType parquetSchema, String[] fieldNames, boolean caseSensitive) {
    Type[] types = new Type[fieldNames.length];
    if (caseSensitive) {
        for (int i = 0; i < fieldNames.length; ++i) {
            String fieldName = fieldNames[i];
            if (parquetSchema.getFieldIndex(fieldName) < 0) {
                throw new IllegalArgumentException(fieldName + " does not exist");
            }
            types[i] = parquetSchema.getType(fieldName);
        }
    } else {
        Map<String, Type> caseInsensitiveFieldMap = new HashMap<>();
        for (Type type : parquetSchema.getFields()) {
            caseInsensitiveFieldMap.compute(type.getName().toLowerCase(Locale.ROOT), (key, previousType) -> {
                if (previousType != null) {
                    throw new FlinkRuntimeException("Parquet with case insensitive mode should have no duplicate key: " + key);
                }
                return type;
            });
        }
        for (int i = 0; i < fieldNames.length; ++i) {
            Type type = caseInsensitiveFieldMap.get(fieldNames[i].toLowerCase(Locale.ROOT));
            if (type == null) {
                throw new IllegalArgumentException(fieldNames[i] + " does not exist");
            }
            // TODO clip for array,map,row types.
            types[i] = type;
        }
    }
    return Types.buildMessage().addFields(types).named("flink-parquet");
}
Also used : GroupType(org.apache.parquet.schema.GroupType) MessageType(org.apache.parquet.schema.MessageType) LogicalType(org.apache.flink.table.types.logical.LogicalType) Type(org.apache.parquet.schema.Type) HashMap(java.util.HashMap) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException)

Example 38 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class KubernetesStateHandleStoreTest method testReplaceFailedAndDiscardState.

@Test
public void testReplaceFailedAndDiscardState() throws Exception {
    final FlinkRuntimeException updateException = new FlinkRuntimeException("Failed to update");
    new Context() {

        {
            runTest(() -> {
                leaderCallbackGrantLeadership();
                final KubernetesStateHandleStore<TestingLongStateHandleHelper.LongStateHandle> store = new KubernetesStateHandleStore<>(flinkKubeClient, LEADER_CONFIGMAP_NAME, longStateStorage, filter, LOCK_IDENTITY);
                store.addAndLock(key, state);
                final FlinkKubeClient anotherFlinkKubeClient = createFlinkKubeClientBuilder().setCheckAndUpdateConfigMapFunction((configMapName, function) -> {
                    throw updateException;
                }).build();
                final KubernetesStateHandleStore<TestingLongStateHandleHelper.LongStateHandle> anotherStore = new KubernetesStateHandleStore<>(anotherFlinkKubeClient, LEADER_CONFIGMAP_NAME, longStateStorage, filter, LOCK_IDENTITY);
                final TestingLongStateHandleHelper.LongStateHandle newState = new TestingLongStateHandleHelper.LongStateHandle(23456L);
                final StringResourceVersion resourceVersion = anotherStore.exists(key);
                assertThat(resourceVersion.isExisting(), is(true));
                try {
                    anotherStore.replace(key, resourceVersion, newState);
                    fail("We should get an exception when kube client failed to update.");
                } catch (Exception ex) {
                    assertThat(ex, FlinkMatchers.containsCause(updateException));
                }
                assertThat(anotherStore.getAllAndLock().size(), is(1));
                // The state do not change
                assertThat(anotherStore.getAndLock(key).retrieveState(), is(state));
                assertThat(TestingLongStateHandleHelper.getGlobalStorageSize(), is(2));
                assertThat(TestingLongStateHandleHelper.getDiscardCallCountForStateHandleByIndex(0), is(0));
                assertThat(TestingLongStateHandleHelper.getDiscardCallCountForStateHandleByIndex(1), is(1));
            });
        }
    };
}
Also used : Arrays(java.util.Arrays) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) Predicate(java.util.function.Predicate) FlinkMatchers(org.apache.flink.core.testutils.FlinkMatchers) Matchers.not(org.hamcrest.Matchers.not) Test(org.junit.Test) Collectors(java.util.stream.Collectors) StringResourceVersion(org.apache.flink.runtime.persistence.StringResourceVersion) List(java.util.List) JobID(org.apache.flink.api.common.JobID) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) FunctionUtils(org.apache.flink.util.function.FunctionUtils) PossibleInconsistentStateException(org.apache.flink.runtime.persistence.PossibleInconsistentStateException) StateHandleStore(org.apache.flink.runtime.persistence.StateHandleStore) TestingLongStateHandleHelper(org.apache.flink.runtime.persistence.TestingLongStateHandleHelper) Matchers.is(org.hamcrest.Matchers.is) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) KubernetesLeaderElector(org.apache.flink.kubernetes.kubeclient.resources.KubernetesLeaderElector) Comparator(java.util.Comparator) FlinkKubeClient(org.apache.flink.kubernetes.kubeclient.FlinkKubeClient) Before(org.junit.Before) TestingLongStateHandleHelper(org.apache.flink.runtime.persistence.TestingLongStateHandleHelper) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) StringResourceVersion(org.apache.flink.runtime.persistence.StringResourceVersion) FlinkKubeClient(org.apache.flink.kubernetes.kubeclient.FlinkKubeClient) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) PossibleInconsistentStateException(org.apache.flink.runtime.persistence.PossibleInconsistentStateException) Test(org.junit.Test)

Example 39 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class NFA method createDecisionGraph.

private OutgoingEdges<T> createDecisionGraph(ConditionContext context, ComputationState computationState, T event) {
    State<T> state = getState(computationState);
    final OutgoingEdges<T> outgoingEdges = new OutgoingEdges<>(state);
    final Stack<State<T>> states = new Stack<>();
    states.push(state);
    // First create all outgoing edges, so to be able to reason about the Dewey version
    while (!states.isEmpty()) {
        State<T> currentState = states.pop();
        Collection<StateTransition<T>> stateTransitions = currentState.getStateTransitions();
        // check all state transitions for each state
        for (StateTransition<T> stateTransition : stateTransitions) {
            try {
                if (checkFilterCondition(context, stateTransition.getCondition(), event)) {
                    // filter condition is true
                    switch(stateTransition.getAction()) {
                        case PROCEED:
                            // simply advance the computation state, but apply the current event
                            // to it
                            // PROCEED is equivalent to an epsilon transition
                            states.push(stateTransition.getTargetState());
                            break;
                        case IGNORE:
                        case TAKE:
                            outgoingEdges.add(stateTransition);
                            break;
                    }
                }
            } catch (Exception e) {
                throw new FlinkRuntimeException("Failure happened in filter function.", e);
            }
        }
    }
    return outgoingEdges;
}
Also used : FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) IOException(java.io.IOException) Stack(java.util.Stack)

Example 40 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class KubernetesUtilsTest method testParsePortRange.

@Test
public void testParsePortRange() {
    final Configuration cfg = new Configuration();
    cfg.set(BlobServerOptions.PORT, "50100-50200");
    try {
        KubernetesUtils.parsePort(cfg, BlobServerOptions.PORT);
        fail("Should fail with an exception.");
    } catch (FlinkRuntimeException e) {
        assertThat(e.getMessage(), containsString(BlobServerOptions.PORT.key() + " should be specified to a fixed port. Do not support a range of ports."));
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) Test(org.junit.Test)

Aggregations

FlinkRuntimeException (org.apache.flink.util.FlinkRuntimeException)78 IOException (java.io.IOException)28 Test (org.junit.Test)13 JobID (org.apache.flink.api.common.JobID)10 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 ExecutionException (java.util.concurrent.ExecutionException)7 Nonnull (javax.annotation.Nonnull)7 Configuration (org.apache.flink.configuration.Configuration)6 Collectors (java.util.stream.Collectors)5 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)5 JobResultStore (org.apache.flink.runtime.highavailability.JobResultStore)4 RocksDBException (org.rocksdb.RocksDBException)4 List (java.util.List)3 Map (java.util.Map)3 CheckpointMetrics (org.apache.flink.runtime.checkpoint.CheckpointMetrics)3 TaskStateSnapshot (org.apache.flink.runtime.checkpoint.TaskStateSnapshot)3 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)3 JobResult (org.apache.flink.runtime.jobmaster.JobResult)3