Search in sources :

Example 16 with IgniteException

use of org.apache.ignite.lang.IgniteException in project ignite-3 by apache.

the class ClientResourceRegistry method clean.

/**
 * Releases all resources.
 */
public void clean() {
    IgniteException ex = null;
    for (ClientResource r : res.values()) {
        try {
            r.release();
        } catch (Exception e) {
            if (ex == null) {
                ex = new IgniteException(e);
            } else {
                ex.addSuppressed(e);
            }
        }
    }
    res.clear();
    if (ex != null) {
        throw ex;
    }
}
Also used : IgniteException(org.apache.ignite.lang.IgniteException) IgniteException(org.apache.ignite.lang.IgniteException)

Example 17 with IgniteException

use of org.apache.ignite.lang.IgniteException in project ignite-3 by apache.

the class ClientTableCommon method readAndSetColumnValue.

private static void readAndSetColumnValue(ClientMessageUnpacker unpacker, Tuple tuple, Column col) {
    try {
        int type = getClientDataType(col.type().spec());
        Object val = unpacker.unpackObject(type);
        tuple.set(col.name(), val);
    } catch (MessageTypeException e) {
        throw new IgniteException("Incorrect value type for column '" + col.name() + "': " + e.getMessage(), e);
    }
}
Also used : IgniteException(org.apache.ignite.lang.IgniteException) MessageTypeException(org.msgpack.core.MessageTypeException)

Example 18 with IgniteException

use of org.apache.ignite.lang.IgniteException in project ignite-3 by apache.

the class QueryTemplate method map.

/**
 * Map.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 */
public ExecutionPlan map(MappingService mappingService, MappingQueryContext ctx) {
    ExecutionPlan executionPlan = this.executionPlan.get();
    if (executionPlan != null && Objects.equals(executionPlan.topologyVersion(), ctx.topologyVersion())) {
        return executionPlan;
    }
    List<Fragment> fragments = Commons.transform(this.fragments, fragment -> fragment.attach(ctx.cluster()));
    Exception ex = null;
    RelMetadataQuery mq = first(fragments).root().getCluster().getMetadataQuery();
    for (int i = 0; i < 3; i++) {
        try {
            ExecutionPlan executionPlan0 = new ExecutionPlan(ctx.topologyVersion(), map(mappingService, fragments, ctx, mq));
            if (executionPlan == null || executionPlan.topologyVersion() < executionPlan0.topologyVersion()) {
                this.executionPlan.compareAndSet(executionPlan, executionPlan0);
            }
            return executionPlan0;
        } catch (FragmentMappingException e) {
            if (ex == null) {
                ex = e;
            } else {
                ex.addSuppressed(e);
            }
            fragments = replace(fragments, e.fragment(), new FragmentSplitter(e.node()).go(e.fragment()));
        }
    }
    throw new IgniteException("Failed to map query.", ex);
}
Also used : RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) FragmentMappingException(org.apache.ignite.internal.sql.engine.metadata.FragmentMappingException) IgniteException(org.apache.ignite.lang.IgniteException) FragmentMappingException(org.apache.ignite.internal.sql.engine.metadata.FragmentMappingException) IgniteException(org.apache.ignite.lang.IgniteException)

Example 19 with IgniteException

use of org.apache.ignite.lang.IgniteException in project ignite-3 by apache.

the class DdlSqlToCommandConverter method deriveSchemaName.

/**
 * Derives a schema name from the compound identifier.
 */
private String deriveSchemaName(SqlIdentifier id, PlanningContext ctx) {
    String schemaName;
    if (id.isSimple()) {
        schemaName = ctx.schemaName();
    } else {
        SqlIdentifier schemaId = id.skipLast(1);
        if (!schemaId.isSimple()) {
            throw new IgniteException("Unexpected value of schemaName [" + "expected a simple identifier, but was " + schemaId + "; " + "querySql=\"" + ctx.query() + "\"]");
        }
        schemaName = schemaId.getSimple();
    }
    ensureSchemaExists(ctx, schemaName);
    return schemaName;
}
Also used : IgniteException(org.apache.ignite.lang.IgniteException) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier)

Example 20 with IgniteException

use of org.apache.ignite.lang.IgniteException in project ignite-3 by apache.

the class DdlSqlToCommandConverter method convertCreateTable.

/**
 * Converts a given CreateTable AST to a CreateTable command.
 *
 * @param createTblNode Root node of the given AST.
 * @param ctx           Planning context.
 */
private CreateTableCommand convertCreateTable(IgniteSqlCreateTable createTblNode, PlanningContext ctx) {
    CreateTableCommand createTblCmd = new CreateTableCommand();
    createTblCmd.schemaName(deriveSchemaName(createTblNode.name(), ctx));
    createTblCmd.tableName(deriveObjectName(createTblNode.name(), ctx, "tableName"));
    createTblCmd.ifTableExists(createTblNode.ifNotExists());
    if (createTblNode.createOptionList() != null) {
        for (SqlNode optNode : createTblNode.createOptionList().getList()) {
            IgniteSqlCreateTableOption opt = (IgniteSqlCreateTableOption) optNode;
            tblOptionProcessors.getOrDefault(opt.key(), UNSUPPORTED_OPTION_PROCESSOR).process(opt, ctx, createTblCmd);
        }
    }
    List<SqlKeyConstraint> pkConstraints = createTblNode.columnList().getList().stream().filter(SqlKeyConstraint.class::isInstance).map(SqlKeyConstraint.class::cast).collect(Collectors.toList());
    if (nullOrEmpty(pkConstraints)) {
        throw new IgniteException("Table without PRIMARY KEY is not supported");
    } else if (pkConstraints.size() > 1) {
        throw new IgniteException("Unexpected amount of primary key constraints [" + "expected at most one, but was " + pkConstraints.size() + "; " + "querySql=\"" + ctx.query() + "\"]");
    }
    Set<String> dedupSetPk = new HashSet<>();
    List<String> pkCols = pkConstraints.stream().map(pk -> pk.getOperandList().get(1)).map(SqlNodeList.class::cast).flatMap(l -> l.getList().stream()).map(SqlIdentifier.class::cast).map(SqlIdentifier::getSimple).filter(dedupSetPk::add).collect(Collectors.toList());
    createTblCmd.primaryKeyColumns(pkCols);
    List<SqlColumnDeclaration> colDeclarations = createTblNode.columnList().getList().stream().filter(SqlColumnDeclaration.class::isInstance).map(SqlColumnDeclaration.class::cast).collect(Collectors.toList());
    IgnitePlanner planner = ctx.planner();
    List<ColumnDefinition> cols = new ArrayList<>(colDeclarations.size());
    for (SqlColumnDeclaration col : colDeclarations) {
        if (!col.name.isSimple()) {
            throw new IgniteException("Unexpected value of columnName [" + "expected a simple identifier, but was " + col.name + "; " + "querySql=\"" + ctx.query() + "\"]");
        }
        String name = col.name.getSimple();
        if (col.dataType.getNullable() != null && col.dataType.getNullable() && dedupSetPk.contains(name)) {
            throw new IgniteException("Primary key cannot contain nullable column [col=" + name + "]");
        }
        RelDataType relType = planner.convert(col.dataType, !dedupSetPk.contains(name));
        dedupSetPk.remove(name);
        Object dflt = null;
        if (col.expression != null) {
            dflt = ((SqlLiteral) col.expression).getValue();
        }
        cols.add(new ColumnDefinition(name, relType, dflt));
    }
    if (!dedupSetPk.isEmpty()) {
        throw new IgniteException("Primary key constrain contains undefined columns: [cols=" + dedupSetPk + "]");
    }
    createTblCmd.columns(cols);
    return createTblCmd;
}
Also used : IgniteSqlCreateTableOption(org.apache.ignite.internal.sql.engine.sql.IgniteSqlCreateTableOption) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlColumnDeclaration(org.apache.calcite.sql.ddl.SqlColumnDeclaration) SqlKeyConstraint(org.apache.calcite.sql.ddl.SqlKeyConstraint) IgnitePlanner(org.apache.ignite.internal.sql.engine.prepare.IgnitePlanner) IgniteException(org.apache.ignite.lang.IgniteException) SqlNode(org.apache.calcite.sql.SqlNode) HashSet(java.util.HashSet)

Aggregations

IgniteException (org.apache.ignite.lang.IgniteException)39 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)10 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)10 NotNull (org.jetbrains.annotations.NotNull)10 Map (java.util.Map)9 MarshallerException (org.apache.ignite.internal.schema.marshaller.MarshallerException)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 HashMap (java.util.HashMap)7 List (java.util.List)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 NodeStoppingException (org.apache.ignite.lang.NodeStoppingException)7 HashSet (java.util.HashSet)6 CompletionException (java.util.concurrent.CompletionException)6 Row (org.apache.ignite.internal.schema.row.Row)6 NoSuchElementException (java.util.NoSuchElementException)5 Set (java.util.Set)5 UUID (java.util.UUID)5 Consumer (java.util.function.Consumer)5 Collectors (java.util.stream.Collectors)5