use of org.apache.ignite.cache.QueryIndex in project ignite by apache.
the class DynamicIndexAbstractBasicSelfTest method checkCreateColumnWithAlias.
/**
* Check index creation on aliased column.
*
* @param mode Mode.
* @param atomicityMode Atomicity mode.
* @param near Near flag.
* @throws Exception If failed.
*/
private void checkCreateColumnWithAlias(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
initialize(mode, atomicityMode, near);
assertSchemaException(new RunnableX() {
@Override
public void run() throws Exception {
QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_2_ESCAPED));
dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false);
}
}, IgniteQueryErrorCode.COLUMN_NOT_FOUND);
assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
QueryIndex idx = index(IDX_NAME_1, field(alias(FIELD_NAME_2_ESCAPED)));
dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false);
assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(alias(FIELD_NAME_2_ESCAPED)));
assertSimpleIndexOperations(SQL_SIMPLE_FIELD_2);
assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_2, SQL_ARG_1);
}
use of org.apache.ignite.cache.QueryIndex in project ignite by apache.
the class GridQueryParsingTest method buildCreateIndex.
/**
*
*/
private static GridSqlCreateIndex buildCreateIndex(String name, String tblName, String schemaName, boolean ifNotExists, QueryIndexType type, Object... flds) {
QueryIndex idx = new QueryIndex();
idx.setName(name);
assert !F.isEmpty(flds) && flds.length % 2 == 0;
LinkedHashMap<String, Boolean> trueFlds = new LinkedHashMap<>();
for (int i = 0; i < flds.length / 2; i++) trueFlds.put((String) flds[i * 2], (Boolean) flds[i * 2 + 1]);
idx.setFields(trueFlds);
idx.setIndexType(type);
GridSqlCreateIndex res = new GridSqlCreateIndex();
res.schemaName(schemaName);
res.tableName(tblName);
res.ifNotExists(ifNotExists);
res.index(idx);
return res;
}
use of org.apache.ignite.cache.QueryIndex in project ignite by apache.
the class CacheConfiguration method convert.
/**
* @param desc Type descriptor.
* @return Type metadata.
*/
private static QueryEntity convert(TypeDescriptor desc) {
QueryEntity entity = new QueryEntity();
// Key and val types.
entity.setKeyType(desc.keyClass().getName());
entity.setValueType(desc.valueClass().getName());
for (ClassProperty prop : desc.props.values()) entity.addQueryField(prop.fullName(), U.box(prop.type()).getName(), prop.alias());
entity.setKeyFields(desc.keyProps);
QueryIndex txtIdx = null;
Collection<QueryIndex> idxs = new ArrayList<>();
for (Map.Entry<String, GridQueryIndexDescriptor> idxEntry : desc.indexes().entrySet()) {
GridQueryIndexDescriptor idx = idxEntry.getValue();
if (idx.type() == QueryIndexType.FULLTEXT) {
assert txtIdx == null;
txtIdx = new QueryIndex();
txtIdx.setIndexType(QueryIndexType.FULLTEXT);
txtIdx.setFieldNames(idx.fields(), true);
txtIdx.setName(idxEntry.getKey());
} else {
Collection<String> grp = new ArrayList<>();
for (String fieldName : idx.fields()) grp.add(idx.descending(fieldName) ? fieldName + " desc" : fieldName);
QueryIndex sortedIdx = new QueryIndex();
sortedIdx.setIndexType(idx.type());
LinkedHashMap<String, Boolean> fields = new LinkedHashMap<>();
for (String f : idx.fields()) fields.put(f, !idx.descending(f));
sortedIdx.setFields(fields);
sortedIdx.setName(idxEntry.getKey());
idxs.add(sortedIdx);
}
}
if (desc.valueTextIndex()) {
if (txtIdx == null) {
txtIdx = new QueryIndex();
txtIdx.setIndexType(QueryIndexType.FULLTEXT);
txtIdx.setFieldNames(Arrays.asList(QueryUtils.VAL_FIELD_NAME), true);
} else
txtIdx.getFields().put(QueryUtils.VAL_FIELD_NAME, true);
}
if (txtIdx != null)
idxs.add(txtIdx);
if (!F.isEmpty(idxs))
entity.setIndexes(idxs);
return entity;
}
use of org.apache.ignite.cache.QueryIndex in project ignite by apache.
the class GridCacheQuerySqlFieldInlineSizeSelfTest method testGroupIndex.
/**
* @throws Exception If failed.
*/
public void testGroupIndex() throws Exception {
CacheConfiguration ccfg = defaultCacheConfiguration();
ccfg.setIndexedTypes(Integer.class, TestValueGroupIndex.class);
assertEquals(1, ccfg.getQueryEntities().size());
QueryEntity ent = (QueryEntity) ccfg.getQueryEntities().iterator().next();
assertEquals(1, ent.getIndexes().size());
QueryIndex idx = ent.getIndexes().iterator().next();
assertEquals(10, idx.getInlineSize());
}
use of org.apache.ignite.cache.QueryIndex in project ignite by apache.
the class GridCacheQuerySqlFieldInlineSizeSelfTest method testSingleFieldIndexes.
/**
* @throws Exception If failed.
*/
public void testSingleFieldIndexes() throws Exception {
CacheConfiguration ccfg = defaultCacheConfiguration();
ccfg.setIndexedTypes(Integer.class, TestValueSingleFieldIndexes.class);
assertEquals(1, ccfg.getQueryEntities().size());
QueryEntity ent = (QueryEntity) ccfg.getQueryEntities().iterator().next();
assertEquals(2, ent.getIndexes().size());
for (QueryIndex idx : ent.getIndexes()) {
if (idx.getFields().containsKey("val0"))
assertEquals(10, idx.getInlineSize());
else if (idx.getFields().containsKey("val1"))
assertEquals(20, idx.getInlineSize());
}
}
Aggregations