use of org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor in project ignite by apache.
the class H2TableDescriptor method createSystemIndexes.
/** {@inheritDoc} */
@Override
public ArrayList<Index> createSystemIndexes(GridH2Table tbl) {
ArrayList<Index> idxs = new ArrayList<>();
IndexColumn keyCol = tbl.indexColumn(KEY_COL, SortOrder.ASCENDING);
IndexColumn affCol = tbl.getAffinityKeyColumn();
if (affCol != null && H2Utils.equals(affCol, keyCol))
affCol = null;
GridH2RowDescriptor desc = tbl.rowDescriptor();
Index hashIdx = createHashIndex(tbl, "_key_PK_hash", H2Utils.treeIndexColumns(desc, new ArrayList<IndexColumn>(2), keyCol, affCol));
if (hashIdx != null)
idxs.add(hashIdx);
// Add primary key index.
Index pkIdx = idx.createSortedIndex(schema, "_key_PK", tbl, true, H2Utils.treeIndexColumns(desc, new ArrayList<IndexColumn>(2), keyCol, affCol), -1);
idxs.add(pkIdx);
if (type().valueClass() == String.class) {
try {
luceneIdx = new GridLuceneIndex(idx.kernalContext(), schema.offheap(), tbl.cacheName(), type);
} catch (IgniteCheckedException e1) {
throw new IgniteException(e1);
}
}
boolean affIdxFound = false;
GridQueryIndexDescriptor textIdx = type.textIndex();
if (textIdx != null) {
try {
luceneIdx = new GridLuceneIndex(idx.kernalContext(), schema.offheap(), tbl.cacheName(), type);
} catch (IgniteCheckedException e1) {
throw new IgniteException(e1);
}
}
// Locate index where affinity column is first (if any).
if (affCol != null) {
for (GridQueryIndexDescriptor idxDesc : type.indexes().values()) {
if (idxDesc.type() != QueryIndexType.SORTED)
continue;
String firstField = idxDesc.fields().iterator().next();
Column col = tbl.getColumn(firstField);
IndexColumn idxCol = tbl.indexColumn(col.getColumnId(), idxDesc.descending(firstField) ? SortOrder.DESCENDING : SortOrder.ASCENDING);
affIdxFound |= H2Utils.equals(idxCol, affCol);
}
}
// Add explicit affinity key index if nothing alike was found.
if (affCol != null && !affIdxFound) {
idxs.add(idx.createSortedIndex(schema, "AFFINITY_KEY", tbl, false, H2Utils.treeIndexColumns(desc, new ArrayList<IndexColumn>(2), affCol, keyCol), -1));
}
return idxs;
}
use of org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor in project ignite by apache.
the class H2TableDescriptor method createUserIndexes.
/**
* Get collection of user indexes.
*
* @return User indexes.
*/
public Collection<GridH2IndexBase> createUserIndexes() {
assert tbl != null;
ArrayList<GridH2IndexBase> res = new ArrayList<>();
for (GridQueryIndexDescriptor idxDesc : type.indexes().values()) {
GridH2IndexBase idx = createUserIndex(idxDesc);
res.add(idx);
}
return res;
}
use of org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor 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;
}
Aggregations