Search in sources :

Example 86 with QueryIndex

use of org.apache.ignite.cache.QueryIndex 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)

Example 87 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class IgniteCachePrimitiveFieldsQuerySelfTest method cacheConfiguration.

/**
 * @param cacheName Cache name.
 * @return Cache configuration.
 */
private CacheConfiguration<Integer, IndexedType> cacheConfiguration(String cacheName) {
    CacheConfiguration<Integer, IndexedType> ccfg = new CacheConfiguration<>(cacheName);
    QueryEntity entity = new QueryEntity(Integer.class.getName(), IndexedType.class.getName());
    LinkedHashMap<String, String> fields = new LinkedHashMap<>();
    // Test will pass if we use java.lang.Integer instead of int.
    fields.put("iVal", "int");
    entity.setFields(fields);
    entity.setIndexes(F.asList(new QueryIndex("iVal")));
    ccfg.setQueryEntities(F.asList(entity));
    return ccfg;
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) LinkedHashMap(java.util.LinkedHashMap)

Example 88 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class IgniteCacheQueriesLoadTest1 method getTraderCfg.

/**
 * @param parentCfg Parent config.
 * @return Configuration.
 */
private static CacheConfiguration<Object, Object> getTraderCfg(CacheConfiguration<Object, Object> parentCfg) {
    CacheConfiguration<Object, Object> traderCfg = new CacheConfiguration<>(parentCfg);
    traderCfg.setName(TRADER_CACHE);
    String strCls = String.class.getCanonicalName();
    LinkedHashMap<String, String> qryFields = new LinkedHashMap<>();
    qryFields.put(ID, strCls);
    qryFields.put(FIRSTNAME, strCls);
    qryFields.put(SECONDNAME, strCls);
    qryFields.put(EMAIL, strCls);
    QueryEntity qryEntity = new QueryEntity();
    qryEntity.setValueType(TRADER);
    qryEntity.setKeyType(strCls);
    qryEntity.setFields(qryFields);
    LinkedHashMap<String, Boolean> grpIdx = new LinkedHashMap<>();
    grpIdx.put(FIRSTNAME, false);
    grpIdx.put(SECONDNAME, false);
    qryEntity.setIndexes(Arrays.asList(new QueryIndex(ID, true), new QueryIndex(grpIdx, QueryIndexType.FULLTEXT)));
    traderCfg.setQueryEntities(Collections.singleton(qryEntity));
    return traderCfg;
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) BinaryObject(org.apache.ignite.binary.BinaryObject) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) LinkedHashMap(java.util.LinkedHashMap)

Example 89 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class IgniteCacheQueriesLoadTest1 method getDepositHistoryCfg.

/**
 * @param parentCfg Parent config.
 * @return Configuration.
 */
private static CacheConfiguration<Object, Object> getDepositHistoryCfg(CacheConfiguration<Object, Object> parentCfg) {
    CacheConfiguration<Object, Object> depositHistCfg = new CacheConfiguration<>(parentCfg);
    depositHistCfg.setName(DEPOSIT_HISTORY_CACHE);
    String strCls = String.class.getCanonicalName();
    String dblCls = Double.class.getCanonicalName();
    String dtCls = Date.class.getCanonicalName();
    LinkedHashMap<String, String> qryFields = new LinkedHashMap<>();
    qryFields.put(ID, strCls);
    qryFields.put(DEPOSIT_ID, strCls);
    qryFields.put(BUSINESS_DAY, dtCls);
    qryFields.put(BALANCE, dblCls);
    QueryEntity qryEntity = new QueryEntity();
    qryEntity.setValueType(OPERATION);
    qryEntity.setKeyType(strCls);
    qryEntity.setFields(qryFields);
    qryEntity.setIndexes(Arrays.asList(new QueryIndex(ID, true), new QueryIndex(DEPOSIT_ID, true)));
    depositHistCfg.setQueryEntities(Collections.singleton(qryEntity));
    return depositHistCfg;
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) BinaryObject(org.apache.ignite.binary.BinaryObject) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

QueryIndex (org.apache.ignite.cache.QueryIndex)89 QueryEntity (org.apache.ignite.cache.QueryEntity)46 LinkedHashMap (java.util.LinkedHashMap)35 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)26 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)24 ArrayList (java.util.ArrayList)21 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)20 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)14 Ignite (org.apache.ignite.Ignite)13 CacheException (javax.cache.CacheException)10 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)10 IgniteException (org.apache.ignite.IgniteException)9 HashMap (java.util.HashMap)8 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)8 Map (java.util.Map)7 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)7 HashSet (java.util.HashSet)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 BinaryObject (org.apache.ignite.binary.BinaryObject)5 CountDownLatch (java.util.concurrent.CountDownLatch)4