Search in sources :

Example 41 with Schema

use of org.h2.schema.Schema in project ignite by apache.

the class GridSqlQueryParser method parseCreateIndex.

/**
 * Parse {@code CREATE INDEX} statement.
 *
 * @param createIdx {@code CREATE INDEX} statement.
 * @see <a href="http://h2database.com/html/grammar.html#create_index">H2 {@code CREATE INDEX} spec.</a>
 */
private GridSqlCreateIndex parseCreateIndex(CreateIndex createIdx) {
    if (CREATE_INDEX_HASH.get(createIdx) || CREATE_INDEX_PRIMARY_KEY.get(createIdx) || CREATE_INDEX_UNIQUE.get(createIdx))
        throw new IgniteSQLException("Only SPATIAL modifier is supported for CREATE INDEX", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
    GridSqlCreateIndex res = new GridSqlCreateIndex();
    Schema schema = SCHEMA_COMMAND_SCHEMA.get(createIdx);
    String tblName = CREATE_INDEX_TABLE_NAME.get(createIdx);
    res.schemaName(schema.getName());
    res.tableName(tblName);
    res.ifNotExists(CREATE_INDEX_IF_NOT_EXISTS.get(createIdx));
    QueryIndex idx = new QueryIndex();
    idx.setName(CREATE_INDEX_NAME.get(createIdx));
    idx.setIndexType(CREATE_INDEX_SPATIAL.get(createIdx) ? QueryIndexType.GEOSPATIAL : QueryIndexType.SORTED);
    IndexColumn[] cols = CREATE_INDEX_COLUMNS.get(createIdx);
    LinkedHashMap<String, Boolean> flds = new LinkedHashMap<>(cols.length);
    for (IndexColumn col : CREATE_INDEX_COLUMNS.get(createIdx)) {
        int sortType = INDEX_COLUMN_SORT_TYPE.get(col);
        if ((sortType & SortOrder.NULLS_FIRST) != 0 || (sortType & SortOrder.NULLS_LAST) != 0)
            throw new IgniteSQLException("NULLS FIRST and NULLS LAST modifiers are not supported for index columns", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
        flds.put(INDEX_COLUMN_NAME.get(col), (sortType & SortOrder.DESCENDING) == 0);
    }
    idx.setFields(flds);
    res.index(idx);
    return res;
}
Also used : Schema(org.h2.schema.Schema) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) QueryIndex(org.apache.ignite.cache.QueryIndex) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint) IndexColumn(org.h2.table.IndexColumn) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ResultSet (java.sql.ResultSet)12 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 PreparedStatement (java.sql.PreparedStatement)9 Statement (java.sql.Statement)9 ArrayList (java.util.ArrayList)9 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)9 SimpleResultSet (org.h2.tools.SimpleResultSet)9 List (java.util.List)8 Schema (io.s4.schema.Schema)7 Connection (java.sql.Connection)7 SQLException (java.sql.SQLException)7 Property (io.s4.schema.Schema.Property)6 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 IgniteException (org.apache.ignite.IgniteException)4 IgniteSystemProperties.getString (org.apache.ignite.IgniteSystemProperties.getString)4 GridH2QueryContext (org.apache.ignite.internal.processors.query.h2.opt.GridH2QueryContext)4 GridSqlStatement (org.apache.ignite.internal.processors.query.h2.sql.GridSqlStatement)4 Schema (org.h2.schema.Schema)4 TypeLiteral (com.google.inject.TypeLiteral)3