/** * Processes indexes based on query entity. * * @param qryEntity Query entity to process. * @param d Type descriptor to populate. * @throws IgniteCheckedException If failed to build index information. */ private static void processIndexes(QueryEntity qryEntity, QueryTypeDescriptorImpl d) throws IgniteCheckedException { if (!F.isEmpty(qryEntity.getIndexes())) { for (QueryIndex idx : qryEntity.getIndexes()) processIndex(idx, d); } }
/** * Comparing local fields and target fields. * * @param target Query entity for check. * @param conflicts Storage of conflicts. * @return Indexes which exist in target and not exist in local. */ @NotNull private Collection<QueryIndex> checkIndexes(QueryEntity target, StringBuilder conflicts) { HashSet<QueryIndex> indexesToAdd = new HashSet<>(); Map<String, QueryIndex> currentIndexes = new HashMap<>(); for (QueryIndex index : getIndexes()) { if (currentIndexes.put(index.getName(), index) != null) throw new IllegalStateException("Duplicate key"); } for (QueryIndex queryIndex : target.getIndexes()) { if(currentIndexes.containsKey(queryIndex.getName())) { checkEquals( conflicts, "index " + queryIndex.getName(), currentIndexes.get(queryIndex.getName()), queryIndex ); } else indexesToAdd.add(queryIndex); } return indexesToAdd; }
/** * Create data transfer object for given cache type metadata. * * @param q Actual cache query entities. */ private VisorQueryEntity(QueryEntity q) { assert q != null; keyType = q.getKeyType(); valType = q.getValueType(); keyFields = toList(q.getKeyFields()); LinkedHashMap<String, String> qryFields = q.getFields(); qryFlds = new LinkedHashMap<>(qryFields); aliases = U.copyMap(q.getAliases()); Collection<QueryIndex> qryIdxs = q.getIndexes(); grps = new ArrayList<>(qryIdxs.size()); for (QueryIndex qryIdx : qryIdxs) grps.add(new VisorQueryIndex(qryIdx)); tblName = q.getTableName(); keyFieldName = q.getKeyFieldName(); valFieldName = q.getValueFieldName(); }
Collection<QueryIndex> idxs = entity.getIndexes();
/** * @throws Exception If failed. */ @Test 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()); }
/** * Checks if given column can be removed from table using its {@link QueryEntity}. * * @param entity Query entity. * @param fieldName Name of the field of the key or value object. * @param colName Name of the column. * @return {@code null} if it's OK to remove the column and exception otherwise. */ public static SchemaOperationException validateDropColumn(QueryEntity entity, String fieldName, String colName) { if (F.eq(fieldName, entity.getKeyFieldName()) || KEY_FIELD_NAME.equalsIgnoreCase(fieldName)) return new SchemaOperationException("Cannot drop column \"" + colName + "\" because it represents an entire cache key"); if (F.eq(fieldName, entity.getValueFieldName()) || VAL_FIELD_NAME.equalsIgnoreCase(fieldName)) return new SchemaOperationException("Cannot drop column \"" + colName + "\" because it represents an entire cache value"); Set<String> keyFields = entity.getKeyFields(); if (keyFields != null && keyFields.contains(fieldName)) return new SchemaOperationException("Cannot drop column \"" + colName + "\" because it is a part of a cache key"); Collection<QueryIndex> indexes = entity.getIndexes(); if (indexes != null) { for (QueryIndex idxDesc : indexes) { if (idxDesc.getFields().containsKey(fieldName)) return new SchemaOperationException("Cannot drop column \"" + colName + "\" because an index exists (\"" + idxDesc.getName() + "\") that uses the column."); } } return null; }
boolean exists = false; for (QueryIndex idx : entity.getIndexes()) { if (F.eq(idx.getName(), op0.indexName())) { exists = true; List<QueryIndex> idxs = new ArrayList<>(entity.getIndexes()); Collection<QueryIndex> idxs = entity.getIndexes(); List<QueryIndex> newIdxs = new ArrayList<>(entity.getIndexes());
Collection<QueryIndex> indexes = qryEntity.getIndexes();
tblNames.add(e.getTableName()); for (QueryIndex idx : e.getIndexes()) idxNames.add(idx.getName()); return new SchemaOperationException(SchemaOperationException.CODE_TABLE_EXISTS, e.getTableName()); for (QueryIndex idx : e.getIndexes()) if (!idxNames.add(idx.getName())) return new SchemaOperationException(SchemaOperationException.CODE_INDEX_EXISTS, idx.getName());
/** * @throws Exception If failed. */ @Test 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()); } }
/** */ private int indexCnt(IgniteEx node, String cacheName) { DynamicCacheDescriptor desc = node.context().cache().cacheDescriptor(cacheName); int cnt = 0; if (desc != null) { QuerySchema schema = desc.schema(); if (schema != null) { for (QueryEntity entity : schema.entities()) cnt += entity.getIndexes().size(); } } return cnt; }
for (QueryIndex entityIdx : entity.getIndexes()) { String idxName = entityIdx.getName();
e.getIndexes(), out, (unused4, i) -> {
for (QueryIndex idx : entity.getIndexes()) idx.setName(indexName(tblName, idx)); for (QueryIndex idx : entity.getIndexes()) { QueryIndex normalIdx = new QueryIndex();
/** * Processes indexes based on query entity. * * @param qryEntity Query entity to process. * @param d Type descriptor to populate. * @throws IgniteCheckedException If failed to build index information. */ private static void processIndexes(QueryEntity qryEntity, QueryTypeDescriptorImpl d) throws IgniteCheckedException { if (!F.isEmpty(qryEntity.getIndexes())) { for (QueryIndex idx : qryEntity.getIndexes()) processIndex(idx, d); } }
/** * Comparing local fields and target fields. * * @param target Query entity for check. * @param conflicts Storage of conflicts. * @return Indexes which exist in target and not exist in local. */ @NotNull private Collection<QueryIndex> checkIndexes(QueryEntity target, StringBuilder conflicts) { HashSet<QueryIndex> indexesToAdd = new HashSet<>(); Map<String, QueryIndex> currentIndexes = new HashMap<>(); for (QueryIndex index : getIndexes()) { if (currentIndexes.put(index.getName(), index) != null) throw new IllegalStateException("Duplicate key"); } for (QueryIndex queryIndex : target.getIndexes()) { if(currentIndexes.containsKey(queryIndex.getName())) { checkEquals( conflicts, "index " + queryIndex.getName(), currentIndexes.get(queryIndex.getName()), queryIndex ); } else indexesToAdd.add(queryIndex); } return indexesToAdd; }
private void appendIndex(QueryEntity queryEntity, Index index, SchemaDefinitionContext context) { QueryIndex queryIndex = new QueryIndex(); queryIndex.setName( index.getName() ); queryIndex.setIndexType( QueryIndexType.SORTED ); LinkedHashMap<String, Boolean> fields = new LinkedHashMap<>(); for ( Iterator<Column> columnIterator = index.getColumnIterator(); columnIterator.hasNext(); ) { Column currentColumn = columnIterator.next(); fields.put( currentColumn.getName(), true ); } queryIndex.setFields( fields ); Set<QueryIndex> indexes = new HashSet<>( queryEntity.getIndexes() ); indexes.add( queryIndex ); queryEntity.setIndexes( indexes ); }
private void appendIndex(QueryEntity queryEntity, AssociationKeyMetadata associationKeyMetadata, SchemaDefinitionContext context) { QueryIndex queryIndex = new QueryIndex(); queryIndex.setIndexType( QueryIndexType.SORTED ); LinkedHashMap<String, Boolean> fields = new LinkedHashMap<>(); for ( String columnName : associationKeyMetadata.getRowKeyColumnNames() ) { String realColumnName = StringHelper.realColumnName( columnName ); queryEntity.addQueryField( realColumnName, STRING_CLASS_NAME, null ); //vk: why always String here? fields.put( realColumnName, true ); } queryIndex.setFields( fields ); queryIndex.setName( queryEntity.getTableName() + '_' + org.hibernate.ogm.util.impl.StringHelper.join( fields.keySet(), "_" ) ); Set<QueryIndex> indexes = new HashSet<>( queryEntity.getIndexes() ); indexes.add( queryIndex ); queryEntity.setIndexes( indexes ); }
/** * Create data transfer object for given cache type metadata. * * @param q Actual cache query entities. */ private VisorQueryEntity(QueryEntity q) { assert q != null; keyType = q.getKeyType(); valType = q.getValueType(); keyFields = toList(q.getKeyFields()); LinkedHashMap<String, String> qryFields = q.getFields(); qryFlds = new LinkedHashMap<>(qryFields); aliases = U.copyMap(q.getAliases()); Collection<QueryIndex> qryIdxs = q.getIndexes(); grps = new ArrayList<>(qryIdxs.size()); for (QueryIndex qryIdx : qryIdxs) grps.add(new VisorQueryIndex(qryIdx)); tblName = q.getTableName(); keyFieldName = q.getKeyFieldName(); valFieldName = q.getValueFieldName(); }
/** * Checks if given column can be removed from table using its {@link QueryEntity}. * * @param entity Query entity. * @param fieldName Name of the field of the key or value object. * @param colName Name of the column. * @return {@code null} if it's OK to remove the column and exception otherwise. */ public static SchemaOperationException validateDropColumn(QueryEntity entity, String fieldName, String colName) { if (F.eq(fieldName, entity.getKeyFieldName()) || KEY_FIELD_NAME.equalsIgnoreCase(fieldName)) return new SchemaOperationException("Cannot drop column \"" + colName + "\" because it represents an entire cache key"); if (F.eq(fieldName, entity.getValueFieldName()) || VAL_FIELD_NAME.equalsIgnoreCase(fieldName)) return new SchemaOperationException("Cannot drop column \"" + colName + "\" because it represents an entire cache value"); Set<String> keyFields = entity.getKeyFields(); if (keyFields != null && keyFields.contains(fieldName)) return new SchemaOperationException("Cannot drop column \"" + colName + "\" because it is a part of a cache key"); Collection<QueryIndex> indexes = entity.getIndexes(); if (indexes != null) { for (QueryIndex idxDesc : indexes) { if (idxDesc.getFields().containsKey(fieldName)) return new SchemaOperationException("Cannot drop column \"" + colName + "\" because an index exists (\"" + idxDesc.getName() + "\") that uses the column."); } } return null; }