@Override public String translateFieldName(Path path){ String attributeName = fieldsToAttributes.get(path); if(attributeName != null){ return attributeName; } Path last = path.suffix(1); attributeName = fieldsToAttributes.get(last); if(attributeName != null){ return attributeName; } return last.toString(); }
private Path toRelative(Path field, Path context) { Path abs = context.isEmpty() ? field : new Path(context, field); if (relativeTo.matchingPrefix(abs)) { return abs.suffix(-relativeTo.numSegments()); } else { throw new IllegalArgumentException("Cannot write " + abs + " relative to " + relativeTo); } } }
private Path removeContext(Path context, Path p, Path original) { if (context.isEmpty()) { return p; } else if (context.matchingPrefix(p)) { return p.suffix(-context.numSegments()); } else { return original; } } }
private Path toRelative(Path field, Path context) { Path abs = context.isEmpty() ? field : new Path(context, field); if (relativeTo.matchingPrefix(abs)) { return abs.suffix(-relativeTo.numSegments()); } else { throw new IllegalArgumentException("Cannot write " + abs + " relative to " + relativeTo); } } }
private Path removeContext(Path context, Path p, Path original) { if (context.isEmpty()) { return p; } else if (context.matchingPrefix(p)) { return p.suffix(-context.numSegments()); } else { return original; } } }
@Override protected Projection.Inclusion projectArray(Path p, QueryEvaluationContext ctx) { LOGGER.debug("Evaluating array query projection for {}", p); Path contextRoot = ctx.getPath(); QueryEvaluationContext nestedContext = ctx.getNestedContext(contextRoot.isEmpty() ? p : p.suffix(-contextRoot.numSegments())); if (query.evaluate(nestedContext)) { LOGGER.debug("query evaluates to true"); return isIncluded() ? Projection.Inclusion.explicit_inclusion : Projection.Inclusion.explicit_exclusion; } return isIncluded() ? Projection.Inclusion.explicit_exclusion : Projection.Inclusion.explicit_inclusion; } }
@Override protected Projection.Inclusion projectArray(Path p, QueryEvaluationContext ctx) { LOGGER.debug("Evaluating array query projection for {}", p); Path contextRoot = ctx.getPath(); QueryEvaluationContext nestedContext = ctx.getNestedContext(contextRoot.isEmpty() ? p : p.suffix(-contextRoot.numSegments())); if (query.evaluate(nestedContext)) { LOGGER.debug("query evaluates to true"); return isIncluded() ? Projection.Inclusion.explicit_inclusion : Projection.Inclusion.explicit_exclusion; } return isIncluded() ? Projection.Inclusion.explicit_exclusion : Projection.Inclusion.explicit_inclusion; } }
/** * Returns a map where the key is the array field name, and value is a * List<Path> listing the identity fields for that array */ public Map<Path, List<Path>> getArrayIdentities() { FieldCursor cursor = getFieldCursor(); Map<Path, List<Path>> idMap = new HashMap<>(); while (cursor.next()) { FieldTreeNode fn = cursor.getCurrentNode(); if (fn instanceof SimpleField) { for (FieldConstraint fc : ((SimpleField) fn).getConstraints()) { if (fc instanceof ArrayElementIdConstraint) { Path fieldName = cursor.getCurrentPath(); int lastAny = findLastAnyIndex(fieldName); if (lastAny != -1) { Path arrayName = fieldName.prefix(lastAny); Path idName = fieldName.suffix(-(lastAny + 1)); List<Path> ids = idMap.get(arrayName); if (ids == null) { idMap.put(arrayName, ids = new ArrayList<>()); } ids.add(idName); } } } } } return idMap; }
/** * Returns a map where the key is the array field name, and value is a * List<Path> listing the identity fields for that array */ public Map<Path, List<Path>> getArrayIdentities() { FieldCursor cursor = getFieldCursor(); Map<Path, List<Path>> idMap = new HashMap<>(); while (cursor.next()) { FieldTreeNode fn = cursor.getCurrentNode(); if (fn instanceof SimpleField) { for (FieldConstraint fc : ((SimpleField) fn).getConstraints()) { if (fc instanceof ArrayElementIdConstraint) { Path fieldName = cursor.getCurrentPath(); int lastAny = findLastAnyIndex(fieldName); if (lastAny != -1) { Path arrayName = fieldName.prefix(lastAny); Path idName = fieldName.suffix(-(lastAny + 1)); List<Path> ids = idMap.get(arrayName); if (ids == null) { idMap.put(arrayName, ids = new ArrayList<>()); } ids.add(idName); } } } } } return idMap; }
Path fieldPath = cursor.getCurrentPath(); Path contextRelativePath = contextPath.isEmpty() ? fieldPath : fieldPath.suffix(-contextPath.numSegments()); JsonNode fieldNode = cursor.getCurrentNode(); LOGGER.debug("projectObject context={} fieldPath={} contextRelativePath={}", contextPath, fieldPath, contextRelativePath);
@Override protected Boolean projectArray(Path p, QueryEvaluationContext ctx) { Path contextRoot = ctx.getPath(); QueryEvaluationContext nestedContext = ctx.getNestedContext(contextRoot.isEmpty() ? p : p.suffix(-contextRoot.numSegments())); if (query.evaluate(nestedContext)) { setLastMatch(true); return isIncluded() ? Boolean.TRUE : Boolean.FALSE; } return null; } }
/** * Get a reference to the path's hidden sub-field. * * This does not guarantee the sub-path exists. * * @param path * @return */ public static Path getHiddenForField(Path path) { if (path.getLast().equals(Path.ANY)) { return path.prefix(-2).mutableCopy().push(HIDDEN_SUB_PATH).push(path.suffix(2)); } return path.prefix(-1).mutableCopy().push(HIDDEN_SUB_PATH).push(path.getLast()); }
/** * Remove the context prefix from the field. If the field is under an array elemMatch, and if the field * shares the same prefix as the array field, remove that prefix. This is only useful if the field * and the array are in the same entity */ private Path removeContext(CompositeMetadata fieldEntity,Path fieldName) { if(contextField!=null&&fieldEntity==contextField.getFieldEntity()) { Path prefix=new Path(contextField.getEntityRelativeFieldName(),Path.ANYPATH); if(fieldName.numSegments()>=prefix.numSegments()) { Path fieldPrefix=fieldName.prefix(prefix.numSegments()); // Also include the * if(fieldPrefix.equals(prefix)) { // Remove fieldPrefix Path relativeFieldName=fieldName.suffix(-prefix.numSegments()); if(relativeFieldName.isEmpty()) relativeFieldName=new Path(Path.THIS); return relativeFieldName; } } } return fieldName; }
/** * Remove the context prefix from the field. If the field is under an array elemMatch, and if the field * shares the same prefix as the array field, remove that prefix. This is only useful if the field * and the array are in the same entity */ private Path removeContext(CompositeMetadata fieldEntity,Path fieldName) { if(contextField!=null&&fieldEntity==contextField.getFieldEntity()) { Path prefix=new Path(contextField.getEntityRelativeFieldName(),Path.ANYPATH); if(fieldName.numSegments()>=prefix.numSegments()) { Path fieldPrefix=fieldName.prefix(prefix.numSegments()); // Also include the * if(fieldPrefix.equals(prefix)) { // Remove fieldPrefix Path relativeFieldName=fieldName.suffix(-prefix.numSegments()); if(relativeFieldName.isEmpty()) relativeFieldName=new Path(Path.THIS); return relativeFieldName; } } } return fieldName; }
inContextSuffix = entityRelativeFieldNameWithContext.suffix(-i); break;
inContextSuffix = entityRelativeFieldNameWithContext.suffix(-i); break;
nestedFieldPrefix = arrName.suffix(-(closestArray.numSegments() + 1)).prefix(-1); QueryExpression em = iterate(q.getElemMatch(), newContext); nestedFieldPrefix = oldPrefix;
nestedFieldPrefix = arrName.suffix(-(closestArray.numSegments() + 1)).prefix(-1); QueryExpression em = iterate(q.getElemMatch(), newContext); nestedFieldPrefix = oldPrefix;