public Selection(String documentSelection, long fromTimestamp, long toTimestamp) throws ParseException { this.documentSelection = new DocumentSelector(documentSelection); this.fromTimestamp = fromTimestamp; this.toTimestamp = toTimestamp; }
/** * Returns true if the document referenced by this document operation is accepted by this selector * * @param op A document operation * @return True if the document is accepted. * @throws RuntimeException if the evaluation enters an illegal state */ public Result accepts(DocumentOperation op) { return accepts(new Context(op)); }
/** * Returns the list of different variables resulting in a true state for this * expression. * * @param op The document to evaluate. * @return True if the document is accepted. * @throws RuntimeException if the evaluation enters an illegal state */ public ResultList getMatchingResultList(DocumentOperation op) { return getMatchingResultList(new Context(op)); }
private String prepareGCSelection(ModelElement documentNode, String selStr) throws ParseException { DocumentSelector s = new DocumentSelector(selStr); boolean enableGC = false; if (documentNode != null) { enableGC = documentNode.getBooleanAttribute("garbage-collection", false); } if (!enableGC) { return null; } return s.toString(); }
private void validateSelectionExpression(String sel, String allowedType) { DocumentSelector s; try { s = new DocumentSelector(sel); } catch (ParseException e) { throw new IllegalArgumentException("Could not parse document routing selection: " + sel, e); } AllowedDocumentTypesChecker checker = new AllowedDocumentTypesChecker(allowedType); s.visit(checker); }
public DocumentSelectionConverter(String selection) throws ParseException, UnsupportedOperationException, IllegalArgumentException { this.selector = new DocumentSelector(selection); NowCheckVisitor nowChecker = new NowCheckVisitor(); selector.visit(nowChecker); if (nowChecker.requiresConversion()) { SelectionExpressionConverter converter = new SelectionExpressionConverter(); selector.visit(converter); this.queryExpressionMap = converter.getQueryMap(); } else { this.queryExpressionMap = null; } }
public void setWhereClause(String whereClause) throws ParseException { this.whereClause = whereClause; selector = null; if (whereClause != null && !whereClause.equals("")) { selector = new DocumentSelector(whereClause); } }
/** * Returns true if the entry matches the selection criteria given. */ public boolean match(Document doc, long timestamp) { if (timestamp < fromTimestamp) { return false; } if (timestamp > toTimestamp) { return false; } if (timestampSubset != null && !timestampSubset.contains(timestamp)) { return false; } if (documentSelection != null && doc != null && !documentSelection.accepts(new DocumentPut(doc)).equals(Result.TRUE)) { return false; } return true; }
public void applyTo(Document doc) { if (selector == null) { FieldPathIteratorHandler handler = getIteratorHandler(doc); doc.iterateNested(fieldPath, 0, handler); } else { ResultList results = selector.getMatchingResultList(new DocumentPut(doc)); ListIterator<ResultList.ResultPair> resultIter = results.getResults().listIterator(results.getResults().size()); while (resultIter.hasPrevious()) { ResultList.ResultPair rp = resultIter.previous(); if (rp.getResult() == Result.TRUE) { FieldPathIteratorHandler handler = getIteratorHandler(doc); handler.getVariables().clear(); handler.getVariables().putAll(rp.getVariables()); doc.iterateNested(fieldPath, 0, handler); } } } }
private static void validateDocumentSelectionSyntax(String expression) { try { new DocumentSelector(expression); } catch (ParseException e) { throw new BadRequestParameterException(SELECTION, String.format("Failed to parse expression given in 'selection'" + " parameter. Must be a complete and valid sub-expression. Error: %s", e.getMessage())); } }
return selector.accepts(((PutDocumentMessage)msg).getDocumentPut()) == Result.TRUE; return selector.accepts(((UpdateDocumentMessage)msg).getDocumentUpdate()) != Result.FALSE; return selector.accepts(removeMsg.getDocumentRemove()) != Result.FALSE; } else { return true; if (getMsg.getDocumentId().hasDocType()) { DocumentGet getOp = new DocumentGet(getMsg.getDocumentId()); return selector.accepts(getOp) != Result.FALSE; } else { return true;
@Override public void validate(VespaModel model, DeployState deployState) { for (AbstractSearchCluster cluster : model.getSearchClusters()) { if (cluster instanceof IndexedSearchCluster) { IndexedSearchCluster sc = (IndexedSearchCluster) cluster; String routingSelector = sc.getRoutingSelector(); if (routingSelector == null) continue; try { new DocumentSelector(routingSelector); } catch (com.yahoo.document.select.parser.ParseException e) { throw new IllegalArgumentException("Failed to parse routing selector for search cluster '" + sc.getClusterName() + "'", e); } } } } }
private static void addRoute(String clusterConfigId, String selector, DocumentrouteselectorpolicyConfig.Builder builder) { try { new DocumentSelector(selector); } catch (com.yahoo.document.select.parser.ParseException e) { throw new IllegalArgumentException("Failed to parse selector '" + selector + "' for route '" + clusterConfigId + "' in policy 'DocumentRouteSelector'."); } DocumentrouteselectorpolicyConfig.Route.Builder routeBuilder = new DocumentrouteselectorpolicyConfig.Route.Builder(); routeBuilder.name(clusterConfigId); routeBuilder.selector(selector); builder.route(routeBuilder); }
selector = new DocumentSelector(route.selector()); log.log(LogLevel.CONFIG, "Selector for route '" + route.name() + "' is '" + selector + "'."); } catch (com.yahoo.document.select.parser.ParseException e) {