@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; }
private static final boolean isQNFLiteral(Condition<?> condition) { if (condition.getType() != Condition.Type.LITERAL) return false; if (condition instanceof PredicateCondition) { return ((PredicateCondition) condition).getPredicate().isQNF(); } else return true; }
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); }
@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 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 static final boolean isQNFLiteralOrNot(Condition<?> condition) { if (condition instanceof Not) { Condition child = ((Not) condition).getChild(); if (!isQNFLiteral(child)) return false; else if (child instanceof PredicateCondition) { return !((PredicateCondition) child).getPredicate().hasNegation(); } else return true; } else return isQNFLiteral(condition); }
if (atom.getPredicate() == Cmp.EQUAL && atom.getValue() == null || (atom.getPredicate() == Cmp.NOT_EQUAL && atom.getValue() != null)) continue; //Ignore condition, its trivially satisfied TitanPredicate predicate = atom.getPredicate();
type = atom.getKey(); Interval interval = constraintMap.get(type); newInterval = intersectConstraints(interval, type, atom.getPredicate(), atom.getValue());
Object value = atom.getValue(); String key = atom.getKey(); TitanPredicate titanPredicate = atom.getPredicate();
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; } }
boolean coversAdditionalClause = false; for (Condition c : subcover) { double s = (c instanceof PredicateCondition && ((PredicateCondition)c).getPredicate()==Cmp.EQUAL)? EQUAL_CONDITION_SCORE:OTHER_CONDITION_SCORE; if (coveredClauses.contains(c)) s=s*ALREADY_MATCHED_ADJUSTOR;
Object value = atom.getValue(); String key = atom.getKey(); TitanPredicate titanPredicate = atom.getPredicate(); if (value instanceof Number) { Preconditions.checkArgument(titanPredicate instanceof Cmp, "Relation not supported on numeric types: " + titanPredicate);
@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 static final boolean isQNFLiteral(Condition<?> condition) { if (condition.getType() != Condition.Type.LITERAL) return false; if (condition instanceof PredicateCondition) { return ((PredicateCondition) condition).getPredicate().isQNF(); } else return true; }
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 static final boolean isQNFLiteralOrNot(Condition<?> condition) { if (condition instanceof Not) { Condition child = ((Not) condition).getChild(); if (!isQNFLiteral(child)) return false; else if (child instanceof PredicateCondition) { return !((PredicateCondition) child).getPredicate().hasNegation(); } else return true; } else return isQNFLiteral(condition); }
private static final boolean isQNFLiteralOrNot(Condition<?> condition) { if (condition instanceof Not) { Condition child = ((Not) condition).getChild(); if (!isQNFLiteral(child)) return false; else if (child instanceof PredicateCondition) { return !((PredicateCondition) child).getPredicate().hasNegation(); } else return true; } else return isQNFLiteral(condition); }
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; }