@Override public Object visit(ASTJexlScript node, Object data) { StringBuilder sb = (StringBuilder) data; for (int i = 0; i < node.jjtGetNumChildren(); ++i) { node.jjtGetChild(i).jjtAccept(this, sb); sb.append("; "); } // cutting of the last ';' is still legal jexl and lets me not have to modify // all the unit tests that don't expect a trailing ';' if (sb.length() > 0) { sb.setLength(sb.length() - "; ".length()); } return sb; }
/** * Returns whether or not all top level children are delayed. if this is the case * * @param jexlScript * @return */ private boolean allDelayed(ASTJexlScript jexlScript) { if (jexlScript.jjtGetNumChildren() == 0) { return false; } int delayedCount = 0; IsType delayedCheck = new IsType(ASTDelayedPredicate.class); for (int i = 0; i < jexlScript.jjtGetNumChildren(); i++) { JexlNode child = jexlScript.jjtGetChild(i); if (delayedCheck.apply(child)) { delayedCount++; } } return delayedCount == jexlScript.jjtGetNumChildren(); }
/** {@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; }
/** {@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; }
/** * 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); }
public Object visit(ASTJexlScript node, Object data) { int numChildren = node.jjtGetNumChildren();
@Override public Object visit(ASTJexlScript node, Object data) { if (traverse(data, fullTraversal)) { int i = 0; while (traverse(data, fullTraversal) && i < node.jjtGetNumChildren()) { data = node.jjtGetChild(i).jjtAccept(this, data); i++; } } return data; }
/** * {@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)); }
for (int i = 0; i < node.jjtGetNumChildren(); i++) { Node newChild = (Node) node.jjtGetChild(i).jjtAccept(this, data); if (newNode.jjtGetNumChildren() == 0) { NotFoundQueryException qe = new NotFoundQueryException(DatawaveErrorCode.NO_ANYFIELD_EXPANSION_MATCH); log.warn(qe);
@Override public Object visit(ASTJexlScript node, Object data) { setPushDown((PushDownVisitor) data); costEstimator = new CostEstimator(parentVisitor); if (log.isTraceEnabled()) log.trace("Setting cost estimator"); // don't rewrite yet ASTJexlScript newScript = new ASTJexlScript(ParserTreeConstants.JJTJEXLSCRIPT); // for this to work we should only have a single child Preconditions.checkArgument(node.jjtGetNumChildren() == 1); JexlNode child = node.jjtGetChild(0); if (ASTDelayedPredicate.instanceOf(child)) { child = child.jjtGetChild(0); child = (JexlNode) child.jjtAccept(this, data); child.jjtSetParent(newScript); newScript.jjtAddChild(child, 0); return newScript; } else return node; }
@Test public void getCurrentField_fiGroupingTest() { EasyMock.expect(mockScript.jjtGetNumChildren()).andReturn(0).anyTimes(); replayAll(); // expected key structure Key key = new Key("row", "fi" + Constants.NULL + "field.name", "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 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 getCurrentField_tfTest() { EasyMock.expect(mockScript.jjtGetNumChildren()).andReturn(0).anyTimes(); replayAll(); // expected key structure Key key = new Key("row", "tf", "dataType" + Constants.NULL + "123.234.345" + Constants.NULL + "value" + Constants.NULL + "field"); filter = new TLDEventDataFilter(mockScript, mockAttributeFactory, false, null, null, -1, -1); String field = filter.getCurrentField(key); assertTrue(field.equals("field")); verifyAll(); }
@Test public void getCurrentField_tfGroupingTest() { EasyMock.expect(mockScript.jjtGetNumChildren()).andReturn(0).anyTimes(); replayAll(); // expected key structure Key key = new Key("row", "tf", "dataType" + Constants.NULL + "123.234.345" + Constants.NULL + "value" + Constants.NULL + "field.name"); filter = new TLDEventDataFilter(mockScript, mockAttributeFactory, false, null, null, -1, -1); String field = filter.getCurrentField(key); assertTrue(field.equals("field")); verifyAll(); }
@Test public void getCurrentField_standardTest() { EasyMock.expect(mockScript.jjtGetNumChildren()).andReturn(0).anyTimes(); replayAll(); // expected key structure Key key = new Key("row", "column", "field" + Constants.NULL_BYTE_STRING + "value"); filter = new TLDEventDataFilter(mockScript, mockAttributeFactory, false, null, null, -1, -1); String field = filter.getCurrentField(key); assertEquals("field", field); verifyAll(); }
@Test public void getCurrentField_groupingTest() { EasyMock.expect(mockScript.jjtGetNumChildren()).andReturn(0).anyTimes(); replayAll(); // expected key structure Key key = new Key("row", "column", "field.part_1.part_2.part_3" + Constants.NULL_BYTE_STRING + "value"); filter = new TLDEventDataFilter(mockScript, mockAttributeFactory, false, null, null, -1, -1); String field = filter.getCurrentField(key); assertEquals("field", field); verifyAll(); }
@Test public void keep_emptyMapTest() { Map<String,Integer> fieldLimits = Collections.emptyMap(); EasyMock.expect(mockScript.jjtGetNumChildren()).andReturn(0).anyTimes(); replayAll(); // expected key structure Key key = new Key("row", "column", "field1" + Constants.NULL_BYTE_STRING + "value"); filter = new TLDEventDataFilter(mockScript, mockAttributeFactory, false, null, null, 1, -1, fieldLimits, "LIMIT_FIELD"); assertTrue(filter.keep(key)); assertNull(filter.getSeekRange(key, key.followingKey(PartialKey.ROW), false)); verifyAll(); }
fieldLimits.put("field1", 1); EasyMock.expect(mockScript.jjtGetNumChildren()).andReturn(0).anyTimes(); replayAll();
@Test public void setDocumentClearParseInfoTest() { EasyMock.expect(mockScript.jjtGetNumChildren()).andReturn(0).anyTimes(); replayAll(); // expected key structure Key key1 = new Key("row", "dataype" + Constants.NULL + "123.234.345", "field1" + Constants.NULL_BYTE_STRING + "value"); Key key2 = new Key("row", "dataype" + Constants.NULL + "123.234.345.1", "field1" + Constants.NULL_BYTE_STRING + "value"); Key key3 = new Key("row", "dataype" + Constants.NULL + "123.234.34567", "field1" + Constants.NULL_BYTE_STRING + "value"); filter = new TLDEventDataFilter(mockScript, mockAttributeFactory, false, null, null, -1, -1); filter.startNewDocument(key1); // set the lastParseInfo to this key filter.keep(key1); assertFalse(filter.getParseInfo(key2).isRoot()); filter.keep(key2); // breaking contract calling this on a new document without calling set document, do this to illustrate the potential problem assertFalse(filter.getParseInfo(key3).isRoot()); // property follow the contract by setting the context for the document first filter.startNewDocument(key2); assertTrue(filter.getParseInfo(key2).isRoot()); verifyAll(); }
fieldLimits.put("field1", 1); EasyMock.expect(mockScript.jjtGetNumChildren()).andReturn(0).anyTimes(); replayAll();