@Override public Object visit(ASTJexlScript node, Object data) { ASTJexlScript newNode = new ASTJexlScript(ParserTreeConstants.JJTJEXLSCRIPT); newNode.image = node.image; for (int i = 0; i < node.jjtGetNumChildren(); i++) { Node newChild = (Node) node.jjtGetChild(i).jjtAccept(this, data); newNode.jjtAddChild(newChild, newIndex); newIndex++; newNode.jjtAddChild(newChild, newIndex); newIndex++; if (newNode.jjtGetNumChildren() == 0) { NotFoundQueryException qe = new NotFoundQueryException(DatawaveErrorCode.NO_ANYFIELD_EXPANSION_MATCH); log.warn(qe);
public ASTJexlScript applyRules(ASTJexlScript script) { return (ASTJexlScript) script.jjtAccept(this, this); }
@Override public Object visit(ASTJexlScript node, Object data) { node.childrenAccept(this, data); return data; }
/** {@inheritDoc} */ public Object visit(ASTJexlScript node, Object data) { int numChildren = node.jjtGetNumChildren(); Object result = null; for (int i = 0; i < numChildren; i++) { JexlNode child = node.jjtGetChild(i); result = child.jjtAccept(this, data); } return result; }
/** * {@inheritDoc} */ public Object evaluate(JexlContext context) { if (script.jjtGetNumChildren() < 1) { return null; } Interpreter interpreter = jexl.createInterpreter(context); interpreter.setFrame(script.createFrame((Object[]) null)); return interpreter.interpret(script.jjtGetChild(0)); }
/** * Create an ASTJexlScript with the provided child * * @param child * @return */ public static ASTJexlScript createScript(JexlNode child) { ASTJexlScript script = new ASTJexlScript(ParserTreeConstants.JJTJEXLSCRIPT); // Wrap the child in parens to be sure we don't misconstrue the intent // of the query JexlNode wrappedChild = wrap(child); script.jjtAddChild(wrappedChild, 0); wrappedChild.jjtSetParent(script); return script; }
/** * Creates an Expression from a String containing valid * JEXL syntax. This method parses the expression which * must contain either a reference or an expression. * @param expression A String containing valid JEXL syntax * @return An Expression object which can be evaluated with a JexlContext * @param info An info structure to carry debugging information if needed * @throws JexlException An exception can be thrown if there is a problem * parsing this expression, or if the expression is neither an * expression or a reference. */ public Expression createExpression(String expression, JexlInfo info) { // Parse the expression ASTJexlScript tree = parse(expression, info, null); if (tree.jjtGetNumChildren() > 1) { logger.warn("The JEXL Expression created will be a reference" + " to the first expression from the supplied script: \"" + expression + "\" "); } return createExpression(tree, expression); }
@Test public void testArbitraryNodeExpansionFailNoFlatten() throws Exception { ASTJexlScript queryTree = JexlASTHelper .parseJexlQuery("UUID == 'capone' && (filter:includeRegex(QUOTE,'.*kind.*') || QUOTE == 'kind' || BIRTH_DATE == '123')"); ShardQueryConfiguration config = EasyMock.createMock(ShardQueryConfiguration.class); MetadataHelper helper = EasyMock.createMock(MetadataHelper.class); HashSet indexedFields = new HashSet(); indexedFields.add("UUID"); indexedFields.add("QUOTE"); EasyMock.expect(config.getIndexedFields()).andReturn(indexedFields).anyTimes(); EasyMock.replay(config, helper); // find an orNode in the tree ExecutableExpansionVisitor visitor = new ExecutableExpansionVisitor(config, helper); Object data = visitor.visit(queryTree.jjtGetChild(0), null); EasyMock.verify(config, helper); Assert.assertFalse(data instanceof ExecutableExpansionVisitor.ExpansionTracker); }
Scope frame = new Scope("#0", "#1"); ASTJexlScript script = parse(expr, null, frame); JexlNode node = script.jjtGetChild(0); Interpreter interpreter = createInterpreter(context); interpreter.setFrame(script.createFrame(bean, value)); node.jjtAccept(interpreter, null); } catch (JexlException xjexl) {
public FunctionFilter(List<ASTFunctionNode> nodes) { ASTJexlScript script = new ASTJexlScript(ParserTreeConstants.JJTJEXLSCRIPT); if (nodes.size() > 1) { ASTAndNode andNode = new ASTAndNode(ParserTreeConstants.JJTANDNODE); children(script, andNode); children(andNode, nodes.toArray(new JexlNode[nodes.size()])); } else { children(script, nodes.get(0)); } String query = JexlStringBuildingVisitor.buildQuery(script); JexlArithmetic arithmetic = new DefaultArithmetic(); // Get a JexlEngine initialized with the correct JexlArithmetic for // this Document DatawaveJexlEngine engine = ArithmeticJexlEngines.getEngine(arithmetic); // Evaluate the JexlContext against the Script this.script = engine.createScript(query); }
/** * {@inheritDoc} * @since 2.1 */ public Callable<Object> callable(JexlContext context, Object... args) { final Interpreter interpreter = jexl.createInterpreter(context); interpreter.setFrame(script.createFrame(args)); return new Callable<Object>() { /** Use interpreter as marker for not having run. */ private Object result = interpreter; public Object call() throws Exception { if (result == interpreter) { result = interpreter.interpret(script); } return result; } }; }
/** * {@inheritDoc} * @since 2.1 */ public String[] getParameters() { return script.getParameters(); }
/** * {@inheritDoc} * @since 2.1 */ public String[] getLocalVariables() { return script.getLocalVariables(); }
scope = script.getScope();
/** {@inheritDoc} */ public Object visit(ASTJexlScript node, Object data) { int num = node.jjtGetNumChildren(); for (int i = 0; i < num; ++i) { JexlNode child = node.jjtGetChild(i); acceptStatement(child, data); } return data; }
@Test public void getCurrentField_fiTest() { EasyMock.expect(mockScript.jjtGetNumChildren()).andReturn(0).anyTimes(); replayAll(); // expected key structure Key key = new Key("row", "fi" + Constants.NULL + "field", "value" + Constants.NULL + "dataType" + Constants.NULL + "123.345.456"); filter = new TLDEventDataFilter(mockScript, mockAttributeFactory, false, null, null, -1, -1); String field = filter.getCurrentField(key); assertTrue(field.equals("field")); verifyAll(); }
@Test public void testArbitraryNodeExpansionFlatten() throws Exception { ASTJexlScript queryTree = JexlASTHelper .parseJexlQuery("UUID == 'capone' && (filter:includeRegex(QUOTE,'.*kind.*') || QUOTE == 'kind' || BIRTH_DATE == '123')"); ShardQueryConfiguration config = EasyMock.createMock(ShardQueryConfiguration.class); MetadataHelper helper = EasyMock.createMock(MetadataHelper.class); HashSet indexedFields = new HashSet(); indexedFields.add("UUID"); indexedFields.add("QUOTE"); EasyMock.expect(config.getIndexedFields()).andReturn(indexedFields).anyTimes(); EasyMock.replay(config, helper); // find an orNode in the tree ExecutableExpansionVisitor visitor = new ExecutableExpansionVisitor(config, helper); ASTJexlScript rebuilt = TreeFlatteningRebuildingVisitor.flatten(queryTree); visitor.visit(rebuilt.jjtGetChild(0), null); EasyMock.verify(config, helper); Assert.assertTrue(JexlStringBuildingVisitor.buildQuery(rebuilt).equals( "((QUOTE == 'kind') && UUID == 'capone') || ((filter:includeRegex(QUOTE, '.*kind.*') || BIRTH_DATE == '123') && UUID == 'capone')")); }
Scope frame = new Scope("#0"); ASTJexlScript script = parse(expr, null, frame); JexlNode node = script.jjtGetChild(0); Interpreter interpreter = createInterpreter(context); interpreter.setFrame(script.createFrame(bean)); return node.jjtAccept(interpreter, null); } catch (JexlException xjexl) {
ASTJexlScript jjtn000 = new ASTJexlScript(JJTJEXLSCRIPT); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000);