private OResult filter(OResult next) { next.getPropertyNames().stream().filter(s -> s.startsWith(OMatchExecutionPlanner.DEFAULT_ALIAS_PREFIX)) .forEach(((OResultInternal) next)::removeProperty); return next; }
private static List<String> checkRoot(final Set<ORID> iSourceRIDs, final OResult value, final ORecord iRootObject, String prefix) { List<String> result = new ArrayList<>(); for (String fieldName : value.getPropertyNames()) { Object fieldValue = value.getProperty(fieldName); result.addAll(checkObject(iSourceRIDs, fieldValue, iRootObject, prefix + "." + fieldName)); } return result; }
private void copy(OResult from, OResultInternal to) { for (String prop : from.getPropertyNames()) { to.setProperty(prop, from.getProperty(prop)); } }
@Override public Object execute(Object iThis, OIdentifiable iCurrentRecord, OCommandContext iContext, Object ioResult, Object[] iParams) { if (ioResult instanceof Map) { return ((Map<?, ?>) ioResult).keySet(); } if (ioResult instanceof ODocument) { return Arrays.asList(((ODocument) ioResult).fieldNames()); } if(ioResult instanceof OResult) { OResult res = (OResult) ioResult; return res.getPropertyNames(); } if (ioResult instanceof Collection) { List result = new ArrayList(); for (Object o : (Collection) ioResult) { result.addAll((Collection) execute(iThis, iCurrentRecord, iContext, o, iParams)); } return result; } return null; } }
@Override public Object execute(Object iThis, OIdentifiable iCurrentRecord, OCommandContext iContext, Object ioResult, Object[] iParams) { if (ioResult instanceof Map) { return ((Map<?, ?>) ioResult).values(); } if (ioResult instanceof ODocument) { return Arrays.asList(((ODocument) ioResult).fieldValues()); } if(ioResult instanceof OResult) { OResult res = (OResult) ioResult; return res.getPropertyNames().stream().map(field -> res.getProperty(field)).collect(Collectors.toList()); } if (ioResult instanceof Collection) { List result = new ArrayList(); for (Object o : (Collection) ioResult) { result.addAll((Collection) execute(iThis, iCurrentRecord, iContext, o, iParams)); } return result; } return null; } }
protected static boolean comparesValues(final Object iValue, final OResult iRecord, final boolean iConsiderIn) { // ODOCUMENT AS RESULT OF SUB-QUERY: GET THE FIRST FIELD IF ANY Set<String> firstFieldName = iRecord.getPropertyNames(); if (firstFieldName.size() == 1) { Object fieldValue = iRecord.getProperty(firstFieldName.iterator().next()); if (fieldValue != null) { if (iConsiderIn && OMultiValue.isMultiValue(fieldValue)) { for (Object o : OMultiValue.getMultiValueIterable(fieldValue, false)) { if (o != null && o.equals(iValue)) return true; } } return fieldValue.equals(iValue); } } return false; }
@Override protected Collection<OResult> unroll(OResult doc, OCommandContext iContext) { List<OResult> result = new ArrayList<>(); for (String s : doc.getPropertyNames()) { if (!s.startsWith(OMatchExecutionPlanner.DEFAULT_ALIAS_PREFIX)) { Object elem = doc.getProperty(s); if (elem instanceof OIdentifiable) { OResultInternal newelem = new OResultInternal(); newelem.setElement((OIdentifiable) elem); elem = newelem; } if (elem instanceof OResult) { result.add((OResult) elem); } //else...? TODO } } return result; }
@Override protected Collection<OResult> unroll(OResult doc, OCommandContext iContext) { List<OResult> result = new ArrayList<>(); for (String s : doc.getPropertyNames()) { Object elem = doc.getProperty(s); if (elem instanceof OIdentifiable) { OResultInternal newelem = new OResultInternal(); newelem.setElement((OIdentifiable) elem); elem = newelem; } if (elem instanceof OResult) { result.add((OResult) elem); } //else...? TODO } return result; }
default String toJSON() { if (isElement()) { return getElement().get().toJSON(); } StringBuilder result = new StringBuilder(); result.append("{"); boolean first = true; for (String prop : getPropertyNames()) { if (!first) { result.append(", "); } result.append(toJson(prop)); result.append(": "); result.append(toJson(getProperty(prop))); first = false; } result.append("}"); return result.toString(); }
/** * this is for subqueries, when a OResult is found <ul> <li>if it's a projection with a single column, the value is returned</li> * <li>if it's a document, the RID is returned</li> </ul> * * @param value * * @return */ private Object unboxOResult(Object value) { if (value instanceof List) { return ((List) value).stream().map(x -> unboxOResult(x)).collect(Collectors.toList()); } if (value instanceof OResult) { if (((OResult) value).isElement()) { return ((OResult) value).getIdentity().orElse(null); } Set<String> props = ((OResult) value).getPropertyNames(); if (props.size() == 1) { return ((OResult) value).getProperty(props.iterator().next()); } } return value; }
private OResultInternal copy(OResult item) { if (item == null) { return null; } OResultInternal result = new OResultInternal(); for (String prop : item.getPropertyNames()) { result.setProperty(prop, item.getProperty(prop)); } return result; }
private boolean evaluateAny(OResult currentRecord, OCommandContext ctx) { for (String s : currentRecord.getPropertyNames()) { Object leftVal = currentRecord.getProperty(s); Object rightVal = right.execute(currentRecord, ctx); //TODO collate if (operator.execute(leftVal, rightVal)) { return true; } } return false; }
private void buildNextRecord() { long begin = profilingEnabled ? System.nanoTime() : 0; try { if (currentTuple == null) { nextRecord = null; return; } nextRecord = new OResultInternal(); for (int i = 0; i < this.currentTuple.size(); i++) { OResult res = this.currentTuple.get(i); for (String s : res.getPropertyNames()) { nextRecord.setProperty(s, res.getProperty(s)); } if (!completedPrefetch.get(i)) { preFetches.get(i).add(res); if (!resultSets.get(i).hasNext()) { completedPrefetch.set(i, true); } } } } finally { if (profilingEnabled) { cost += (System.nanoTime() - begin); } } }
private Object handleStar(OResult iCurrentRecord, OCommandContext ctx) { Set<Object> result = new HashSet<>(); for (String prop : iCurrentRecord.getPropertyNames()) { Object val = iCurrentRecord.getProperty(prop); if (isOResult(val) || isValidIdentifiable(val)) { result.add(val); } else { if (val instanceof Iterable) { val = ((Iterable) val).iterator(); } if (val instanceof Iterator) { while (((Iterator) val).hasNext()) { Object sub = ((Iterator) val).next(); if (isOResult(sub) || isValidIdentifiable(sub)) { result.add(sub); } } } else if (val instanceof OResultSet) { while (((OResultSet) val).hasNext()) { result.add(((OResultSet) val).next()); } } } } return result; }
private OResult toTraverseResult(OResult item) { OTraverseResult res = null; if (item instanceof OTraverseResult) { res = (OTraverseResult) item; } else if (item.isElement() && item.getElement().get().getIdentity().isPersistent()) { res = new OTraverseResult(); res.setElement(item.getElement().get()); res.depth = 0; } else if (item.getPropertyNames().size() == 1) { Object val = item.getProperty(item.getPropertyNames().iterator().next()); if (val instanceof OIdentifiable) { res = new OTraverseResult(); res.setElement((OIdentifiable) val); res.depth = 0; res.setMetadata("$depth", 0); } } else { res = new OTraverseResult(); for (String key : item.getPropertyNames()) { res.setProperty(key, item.getProperty(key)); } for (String md : item.getMetadataKeys()) { res.setMetadata(md, item.getMetadata(md)); } } return res; }
public OResult next(OCommandContext ctx) { init(ctx); if (!downstream.hasNext()) { throw new IllegalStateException(); } String endPointAlias = getEndpointAlias(); Object prevValue = sourceRecord.getProperty(endPointAlias); OResultInternal next = downstream.next(); if (isEmptyOptional(prevValue)) { return sourceRecord; } if (!isEmptyOptional(next)) { if (prevValue != null && !equals(prevValue, next.getElement().get())) { return null; } } OResultInternal result = new OResultInternal(); for (String prop : sourceRecord.getPropertyNames()) { result.setProperty(prop, sourceRecord.getProperty(prop)); } result.setProperty(endPointAlias, next.getElement().map(x -> toResult(x)).orElse(null)); return result; }
private OResult copy(OResult nextItem) { OResultInternal result = new OResultInternal(); for (String prop : nextItem.getPropertyNames()) { result.setProperty(prop, nextItem.getProperty(prop)); } for (String md : nextItem.getMetadataKeys()) { result.setMetadata(md, nextItem.getMetadata(md)); } return result; } });
private Object apply(OExpression expression, OResult elem, OCommandContext ctx, int recursion) { OResultInternal result = new OResultInternal(); if (starItem != null || includeItems.size() == 0) { for (String property : elem.getPropertyNames()) { if (isExclude(property)) { continue; } result.setProperty(property, convert(tryExpand(expression, property, elem.getProperty(property), ctx, recursion))); } } if (includeItems.size() > 0) { //TODO manage wildcards! for (ONestedProjectionItem item : includeItems) { String alias = item.alias != null ? item.alias.getStringValue() : item.expression.getDefaultAlias().getStringValue(); Object value = item.expression.execute(elem, ctx); if (item.expansion != null) { value = item.expand(expression, alias, value, ctx, recursion - 1); } result.setProperty(alias, convert(value)); } } return result; }
public OResult next(OCommandContext ctx) { init(ctx); if (!downstream.hasNext()) { throw new IllegalStateException(); } String endPointAlias = getEndpointAlias(); OResultInternal nextR = downstream.next(); OIdentifiable nextElement = nextR.getElement().get(); Object prevValue = sourceRecord.getProperty(endPointAlias); if (prevValue != null && !equals(prevValue, nextElement)) { return null; } OResultInternal result = new OResultInternal(); for (String prop : sourceRecord.getPropertyNames()) { result.setProperty(prop, sourceRecord.getProperty(prop)); } result.setProperty(endPointAlias, toResult(nextElement)); if (edge.edge.item.getFilter().getDepthAlias() != null) { result.setProperty(edge.edge.item.getFilter().getDepthAlias(), nextR.getMetadata("$depth")); } if (edge.edge.item.getFilter().getPathAlias() != null) { result.setProperty(edge.edge.item.getFilter().getPathAlias(), nextR.getMetadata("$matchPath")); } return result; }
@Override public OResult next() { OResult result = lastFetched.next(); long begin = profilingEnabled ? System.nanoTime() : 0; try { if (result instanceof OUpdatableResult) { OResultInternal prevValue = new OResultInternal(); ORecord rec = result.getElement().get().getRecord(); prevValue.setProperty("@rid", rec.getIdentity()); prevValue.setProperty("@version", rec.getVersion()); if (rec instanceof ODocument) { prevValue.setProperty("@class", ((ODocument) rec).getSchemaClass().getName()); } if (!result.toElement().getIdentity().isNew()) { for (String propName : result.getPropertyNames()) { prevValue.setProperty(propName, OLiveQueryHookV2.unboxRidbags(result.getProperty(propName))); } } ((OUpdatableResult) result).previousValue = prevValue; } else { throw new OCommandExecutionException("Cannot fetch previous value: " + result); } return result; } finally { if (profilingEnabled) { cost += (System.nanoTime() - begin); } } }