THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
...
Code Block | ||
---|---|---|
| ||
// Creates an index query for an index created with Java API. // 1. Specify index description at constructor. // 2. Index name is optional param, can try do best to find right index basing on specified Value.class in constructor and fields in conditions. // 3. Index conditions (joint with AND operation) with methods. QueryCursor<Cache.Entry<Long, Good>> cursor = ignite.cache("GOOD").query( IndexQuery.forTypenew IndexQuery<Long, Good>(Good.class, idxName?) // idxName is optional. .criteria(gt("ts", lastMidnightTs) ., lt("price", 123.0)) ); // Create index with SQL query: "CREATE INDEX GOOD_TS_DESC_PRICE_ASC_IDX on GOOD_TBL (ts DESC, price ASC)" // 1. Table name should be specified because it is possible to have the same index name for different tables (e.g., __key_PK). // 2. Index name is optional too (do our best to find right index to run the query). QueryCursor<Cache.Entry<Long, Good>> cursor = ignite.cache("GOOD").query( IndexQuery.forTablenew IndexQuery<Long, Good>("GOOD_TBL", "GOOD_TS_DESC_PRICE_ASC_IDX"?) // idxName is optional. .criteria(gt("ts", lastMidnightTs) ., lt("price", 123.0)) ); |
Classes to implement the API:
Code Block | ||
---|---|---|
| ||
// Public packages. // IndexQuery extends public IndexQuery<K, V> extends Query<Cache.Entry<K, V>> { private List<IndexCondition>List<IndexCriteria> idxCondscriteria = new ArrayList<>(); // Index description. private @Nullable String idxName; private @Nullable String valClass; private @Nullable String schemaName; public static IndexQuery forTypelt(Class<?>String valClassfield, String?Object idxNameval) { return new IndexQuery(valCls, idxName); } public static IndexQuery forTable(Class<?> valClass, String? schema, String? idxName) { return new IndexQuery(valClass, schema, idxName); } public IndexQuery lt(String field, Object val) { IndexCondition cond = RangeIndexCondition(); idxConds.add(field, val); criteria.add(IndexCriteriaBuilder.lt(field, val)); return this; } // Other methods are: // eq, notEq, gt, gte, lt, lte, between, in, notIn, min, max, predicate } // Internal packages. class IndexCriteriaBuilder { public static IndexCriteria lt(String field, Object val); } abstract class IndexConditionIndexCriteria extends Serializable { private final List<String> fields; } // min, max class MinMaxIndexConditionMinMaxIndexCriteria extends IndexCondition { private final boolean max; } // gt, gte, lt, lte, between class RangeIndexConditionRangeIndexCriteria extends IndexConditionIndexCriteria { private final @Nullable Object lower; private final @Nullable Object upper; private final boolean lowerInclusive; private final boolean upperInclusive; } // in, notIn, eq, notEq class InIndexConditionInIndexCriteria extends IndexConditionIndexCriteria { private final Object[] vals; // Flag for not-in condition. private final boolean inverse; } // predicate class PredicateIndexConditionPredicateIndexCriteria extends IndexConditionIndexCriteria { private IgnitePredicate<?> predicate; } |
...