public boolean contains(JexlNode node) { boolean success = true; if (node instanceof ASTAndNode) for (int i = 0; i < node.jjtGetNumChildren(); i++) success &= this.jexlNodeListLowerBound.contains(node.jjtGetChild(i)) || this.jexlNodeListUpperBound.contains(node.jjtGetChild(i)); else if (node instanceof ASTEQNode) success = this.jexlNodeList.contains(node); else success = this.jexlNodeListLowerBound.contains(node) || this.jexlNodeListUpperBound.contains(node); return success; }
private JexlNode getOrNode(JexlNode node) { if (node instanceof ASTOrNode) { return node; } else if (node instanceof ASTReference) { return getOrNode(node.jjtGetChild(0)); } else if (node instanceof ASTReferenceExpression) { return getOrNode(node.jjtGetChild(0)); } return null; }
private JexlNode dereference(JexlNode node) { while (node.jjtGetNumChildren() == 1 && (node instanceof ASTReferenceExpression || node instanceof ASTReference)) { node = node.jjtGetChild(0); } return node; }
public static JexlNode dereference(JexlNode node) { while (node.jjtGetNumChildren() == 1 && (node instanceof ASTReference || node instanceof ASTReferenceExpression)) { node = node.jjtGetChild(0); } return node; }
private static void getERNodes(JexlNode node, List<ASTERNode> erNodes) { if (node instanceof ASTERNode) { erNodes.add((ASTERNode) node); } else { for (int i = 0; i < node.jjtGetNumChildren(); i++) { getERNodes(node.jjtGetChild(i), erNodes); } } }
public static List<JexlNode> getFunctionArguments(ASTFunctionNode function) { List<JexlNode> args = Lists.newArrayList(); for (int i = 0; i < function.jjtGetNumChildren(); i++) { JexlNode child = function.jjtGetChild(i); // Arguments for the function are inside of an ASTReference if (child.getClass().equals(ASTReference.class) && child.jjtGetNumChildren() == 1) { JexlNode grandchild = child.jjtGetChild(0); args.add(grandchild); } } return args; }
private static void getFunctionNodes(JexlNode node, List<ASTFunctionNode> functions) { if (null == node) { return; } if (node instanceof ASTFunctionNode) { functions.add((ASTFunctionNode) node); } else { for (int i = 0; i < node.jjtGetNumChildren(); i++) { getFunctionNodes(node.jjtGetChild(i), functions); } } }
private static void getEQNodes(JexlNode node, List<ASTEQNode> eqNodes) { if (node instanceof ASTEQNode) { eqNodes.add((ASTEQNode) node); } else { for (int i = 0; i < node.jjtGetNumChildren(); i++) { getEQNodes(node.jjtGetChild(i), eqNodes); } } }
private boolean containsChild(JexlNode node, ExecutableDeterminationVisitor.STATE state) { for (int i = 0; i < node.jjtGetNumChildren(); i++) { JexlNode child = node.jjtGetChild(i); if (state == ExecutableDeterminationVisitor.getState(child, config, indexedFields, indexOnlyFields, nonEventFields, false, null, helper)) { return true; } } return false; }
private static JexlNode trimReferenceNodes(JexlNode node) { if ((node instanceof ASTReference || node instanceof ASTReferenceExpression) && node.jjtGetNumChildren() == 1) return trimReferenceNodes(node.jjtGetChild(0)); return node; }
private static List<JexlNode> getLiterals(JexlNode node, List<JexlNode> literals) { if (isLiteral(node)) { literals.add(node); } else { for (int i = 0; i < node.jjtGetNumChildren(); i++) { literals = getLiterals(node.jjtGetChild(i), literals); } } return literals; }
public Object descend(JexlNode node, Object data) { if (node.jjtGetNumChildren() > 1) { QueryException qe = new QueryException(DatawaveErrorCode.MORE_THAN_ONE_CHILD, MessageFormat.format("Class: {0}", node.getClass().getSimpleName())); throw new DatawaveFatalQueryException(qe); } if (node.jjtGetNumChildren() == 1) { return node.jjtGetChild(0).jjtAccept(this, data); } else { return data; } }
@Override public Object visit(ASTOrNode node, Object data) { JexlNode retnode = (JexlNode) (super.visit(node, data)); // if only one member remaining, then return only that if (node.jjtGetNumChildren() == 0) { retnode = null; } else if (retnode.jjtGetNumChildren() == 1) { retnode = retnode.jjtGetChild(0); } return retnode; }
private static Map<String,Object> getAssignments(JexlNode node, Map<String,Object> assignments) { if (node instanceof ASTAssignment) { assignments.put(getIdentifier(node), getLiteralValue(node)); } else { for (int i = 0; i < node.jjtGetNumChildren(); i++) { assignments = getAssignments(node.jjtGetChild(i), assignments); } } return assignments; }
@Override public Object visit(ASTAndNode node, Object data) { JexlNode retnode = (JexlNode) (super.visit(node, data)); // if only one member remaining, then return only that if (node.jjtGetNumChildren() == 0) { retnode = null; } else if (retnode.jjtGetNumChildren() == 1) { retnode = retnode.jjtGetChild(0); } return retnode; }
@Override public Object visit(ASTNumberLiteral node, Object data) { JexlNode op = node.jjtGetParent(); if (op instanceof ASTEQNode) { JexlNode field = JexlNodes.otherChild(op, node).jjtGetChild(0); values.addLiteral(node.getLiteral().toString(), JexlASTHelper.deconstructIdentifier(field.image)); } return null; }
private JexlNode reparent(JexlNode in, JexlNode out) { int j = 0; for (int i = in.jjtGetNumChildren() - 1; i >= 0; i--) { JexlNode kid = in.jjtGetChild(i); kid = (JexlNode) kid.jjtAccept(this, null); out.jjtAddChild(kid, j++); kid.jjtSetParent(out); } return out; }
@Test public void testNormalizeLiteral() throws Throwable { LcNoDiacriticsType normalizer = new LcNoDiacriticsType(); ASTJexlScript script = JexlASTHelper.parseJexlQuery("F == 'aSTrInG'"); if (log.isDebugEnabled()) { PrintingVisitor.printQuery(script); } JexlNode literal = script.jjtGetChild(0).jjtGetChild(1).jjtGetChild(0); ASTReference ref = JexlASTHelper.normalizeLiteral(literal, normalizer); Assert.assertEquals("astring", ref.jjtGetChild(0).image); }
@Test public void antiMeridianTest1() throws Exception { String query = "geo:within_bounding_box(GEO_FIELD, '40_170', '50_-170')"; JexlNode node = JexlASTHelper.parseJexlQuery(query); JexlArgumentDescriptor argDesc = new GeoFunctionsDescriptor().getArgumentDescriptor((ASTFunctionNode) node.jjtGetChild(0).jjtGetChild(0)); JexlNode queryNode = argDesc.getIndexQuery(null, null, null, null); Assert.assertEquals("((GEO_FIELD >= '40.0_170.0' && GEO_FIELD <= '50.0_180') && (GEO_FIELD >= '40.0_-180' && GEO_FIELD <= '50.0_-170.0'))", JexlStringBuildingVisitor.buildQuery(queryNode)); }
@Test public void antiMeridianTest2() throws Exception { String query = "geo:within_bounding_box(LON_FIELD, LAT_FIELD, '170', '40', '-170', '50')"; JexlNode node = JexlASTHelper.parseJexlQuery(query); JexlArgumentDescriptor argDesc = new GeoFunctionsDescriptor().getArgumentDescriptor((ASTFunctionNode) node.jjtGetChild(0).jjtGetChild(0)); JexlNode queryNode = argDesc.getIndexQuery(null, null, null, null); Assert.assertEquals( "(((LON_FIELD >= '170.0' && LON_FIELD <= '180') && (LAT_FIELD >= '40.0' && LAT_FIELD <= '50.0')) && ((LON_FIELD >= '-180' && LON_FIELD <= '-170.0') && (LAT_FIELD >= '40.0' && LAT_FIELD <= '50.0')))", JexlStringBuildingVisitor.buildQuery(queryNode)); } }