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;
}
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;
}
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;
}
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;
}
Aggregations