@Override public boolean apply(@Nullable Condition<TitanElement> condition) { if (condition instanceof PredicateCondition) { RelationType type = ((PredicateCondition<RelationType,TitanElement>)condition).getKey(); Preconditions.checkArgument(type!=null && type.isPropertyKey()); Iterables.addAll(indexCandidates,Iterables.filter(((InternalRelationType) type).getKeyIndexes(), new Predicate<IndexType>() { @Override public boolean apply(@Nullable IndexType indexType) { return indexType.getElement()==resultType; } })); } return true; } });
@Nullable @Override public Condition<TitanElement> apply(@Nullable Condition<TitanElement> condition) { Preconditions.checkArgument(condition instanceof PredicateCondition); PredicateCondition pc = (PredicateCondition) condition; PropertyKey key = (PropertyKey) pc.getKey(); return new PredicateCondition<String, TitanElement>(key2Field(index,key), pc.getPredicate(), pc.getValue()); } });
private static final Map.Entry<Condition,Collection<Object>> getEqualityConditionValues(Condition<TitanElement> condition, RelationType type) { for (Condition c : condition.getChildren()) { if (c instanceof Or) { Map.Entry<RelationType,Collection> orEqual = QueryUtil.extractOrCondition((Or)c); if (orEqual!=null && orEqual.getKey().equals(type) && !orEqual.getValue().isEmpty()) { return new AbstractMap.SimpleImmutableEntry(c,orEqual.getValue()); } } else if (c instanceof PredicateCondition) { PredicateCondition<RelationType, TitanRelation> atom = (PredicateCondition)c; if (atom.getKey().equals(type) && atom.getPredicate()==Cmp.EQUAL && atom.getValue()!=null) { return new AbstractMap.SimpleImmutableEntry(c,ImmutableList.of(atom.getValue())); } } } return null; }
public static Map.Entry<RelationType,Collection> extractOrCondition(Or<TitanRelation> condition) { RelationType masterType = null; List<Object> values = new ArrayList<Object>(); for (Condition c : condition.getChildren()) { if (!(c instanceof PredicateCondition)) return null; PredicateCondition<RelationType, TitanRelation> atom = (PredicateCondition)c; if (atom.getPredicate()!=Cmp.EQUAL) return null; Object value = atom.getValue(); if (value==null) return null; RelationType type = atom.getKey(); if (masterType==null) masterType=type; else if (!masterType.equals(type)) return null; values.add(value); } if (masterType==null) return null; assert !values.isEmpty(); return new AbstractMap.SimpleImmutableEntry(masterType,values); }
private PredicateCondition<PropertyKey, TitanElement> getEqualityCondition(Condition<TitanElement> condition) { if (condition instanceof PredicateCondition) { PredicateCondition<PropertyKey, TitanElement> pc = (PredicateCondition) condition; if (pc.getPredicate() == Cmp.EQUAL && TypeUtil.hasSimpleInternalVertexKeyIndex(pc.getKey())) return pc; } else if (condition instanceof And) { for (Condition<TitanElement> child : ((And<TitanElement>) condition).getChildren()) { PredicateCondition<PropertyKey, TitanElement> p = getEqualityCondition(child); if (p != null) return p; } } return null; }
@Nullable @Override public Condition<E> apply(@Nullable Condition<E> cond) { if (cond instanceof Not) { Condition<E> child = ((Not) cond).getChild(); Preconditions.checkArgument(child.getType() == Condition.Type.LITERAL); //verify QNF if (child instanceof PredicateCondition) { PredicateCondition<?, E> pc = (PredicateCondition) child; if (pc.getPredicate().hasNegation()) { return new PredicateCondition(pc.getKey(), pc.getPredicate().negate(), pc.getValue()); } } } return null; } });
private static final boolean coversAll(final MixedIndexType index, Condition<TitanElement> condition, IndexSerializer indexInfo) { if (condition.getType()==Condition.Type.LITERAL) { if (!(condition instanceof PredicateCondition)) return false; PredicateCondition<RelationType, TitanElement> atom = (PredicateCondition) condition; if (atom.getValue()==null) return false; Preconditions.checkArgument(atom.getKey().isPropertyKey()); PropertyKey key = (PropertyKey) atom.getKey(); ParameterIndexField[] fields = index.getFieldKeys(); ParameterIndexField match = null; for (int i = 0; i < fields.length; i++) { if (fields[i].getStatus()!= SchemaStatus.ENABLED) continue; if (fields[i].getFieldKey().equals(key)) match = fields[i]; } if (match==null) return false; return indexInfo.supports(index,match,atom.getPredicate()); } else { for (Condition<TitanElement> child : condition.getChildren()) { if (!coversAll(index,child,indexInfo)) return false; } return true; } }
type = atom.getKey(); Interval interval = constraintMap.get(type); newInterval = intersectConstraints(interval, type, atom.getPredicate(), atom.getValue());
PredicateCondition<String, TitanElement> atom = (PredicateCondition<String, TitanElement>) condition; Object value = atom.getValue(); String key = atom.getKey(); TitanPredicate titanPredicate = atom.getPredicate();
vertices = com.google.common.collect.Iterators.transform(newVertexIndexEntries.get(standardIndexKey.getValue(), standardIndexKey.getKey()).iterator(), new Function<TitanVertexProperty, TitanVertex>() { @Nullable @Override
And<E> conditions = new And<E>(constraints.size() + 4); for (PredicateCondition<String, E> atom : constraints) { RelationType type = getType(tx, atom.getKey());
PredicateCondition<String, ?> atom = (PredicateCondition) condition; Object value = atom.getValue(); String key = atom.getKey(); TitanPredicate titanPredicate = atom.getPredicate(); if (value instanceof Number) {
@Override public boolean apply(@Nullable Condition<TitanElement> condition) { if (condition instanceof PredicateCondition) { RelationType type = ((PredicateCondition<RelationType,TitanElement>)condition).getKey(); Preconditions.checkArgument(type!=null && type.isPropertyKey()); Iterables.addAll(indexCandidates,Iterables.filter(((InternalRelationType) type).getKeyIndexes(), new Predicate<IndexType>() { @Override public boolean apply(@Nullable IndexType indexType) { return indexType.getElement()==resultType; } })); } return true; } });
@Override public boolean apply(@Nullable Condition<TitanElement> condition) { if (condition instanceof PredicateCondition) { RelationType type = ((PredicateCondition<RelationType, TitanElement>)condition).getKey(); Preconditions.checkArgument(type!=null && type.isPropertyKey()); Iterables.addAll(indexCandidates, Iterables.filter(((InternalRelationType) type).getKeyIndexes(), new Predicate<IndexType>() { @Override public boolean apply(@Nullable IndexType indexType) { return indexType.getElement()==resultType; } })); } return true; } });
@Override public boolean apply(@Nullable Condition<TitanElement> condition) { if (condition instanceof PredicateCondition) { RelationType type = ((PredicateCondition<RelationType,TitanElement>)condition).getKey(); Preconditions.checkArgument(type!=null && type.isPropertyKey()); Iterables.addAll(indexCandidates,Iterables.filter(((InternalRelationType) type).getKeyIndexes(), new Predicate<IndexType>() { @Override public boolean apply(@Nullable IndexType indexType) { return indexType.getElement()==resultType; } })); } return true; } });
@Override public boolean apply(@Nullable Condition<TitanElement> condition) { if (condition instanceof PredicateCondition) { RelationType type = ((PredicateCondition<RelationType,TitanElement>)condition).getKey(); Preconditions.checkArgument(type!=null && type.isPropertyKey()); Iterables.addAll(indexCandidates,Iterables.filter(((InternalRelationType) type).getKeyIndexes(), new Predicate<IndexType>() { @Override public boolean apply(@Nullable IndexType indexType) { return indexType.getElement()==resultType; } })); } return true; } });
@Nullable @Override public Condition<TitanElement> apply(@Nullable Condition<TitanElement> condition) { Preconditions.checkArgument(condition instanceof PredicateCondition); PredicateCondition pc = (PredicateCondition) condition; PropertyKey key = (PropertyKey) pc.getKey(); return new PredicateCondition<String, TitanElement>(key2Field(index,key), pc.getPredicate(), pc.getValue()); } });
@Nullable @Override public Condition<TitanElement> apply(@Nullable Condition<TitanElement> condition) { Preconditions.checkArgument(condition instanceof PredicateCondition); PredicateCondition pc = (PredicateCondition) condition; PropertyKey key = (PropertyKey) pc.getKey(); return new PredicateCondition<String, TitanElement>(key2Field(index,key), pc.getPredicate(), pc.getValue()); } });
private PredicateCondition<PropertyKey, TitanElement> getEqualityCondition(Condition<TitanElement> condition) { if (condition instanceof PredicateCondition) { PredicateCondition<PropertyKey, TitanElement> pc = (PredicateCondition) condition; if (pc.getPredicate() == Cmp.EQUAL && TypeUtil.hasSimpleInternalVertexKeyIndex(pc.getKey())) return pc; } else if (condition instanceof And) { for (Condition<TitanElement> child : ((And<TitanElement>) condition).getChildren()) { PredicateCondition<PropertyKey, TitanElement> p = getEqualityCondition(child); if (p != null) return p; } } return null; }
private PredicateCondition<PropertyKey, TitanElement> getEqualityCondition(Condition<TitanElement> condition) { if (condition instanceof PredicateCondition) { PredicateCondition<PropertyKey, TitanElement> pc = (PredicateCondition) condition; if (pc.getPredicate() == Cmp.EQUAL && TypeUtil.hasSimpleInternalVertexKeyIndex(pc.getKey())) return pc; } else if (condition instanceof And) { for (Condition<TitanElement> child : ((And<TitanElement>) condition).getChildren()) { PredicateCondition<PropertyKey, TitanElement> p = getEqualityCondition(child); if (p != null) return p; } } return null; }