if (node != null) { ORExpression newORExpr = new ORExpression(); for (ANDExpression left : orExprLeft.getANDExprList()) { for (ANDExpression right : orExprRight.getANDExprList()) { ANDExpression tmp = new ANDExpression(); tmp.getAtomicExprList().addAll(left.getAtomicExprList()); tmp.getAtomicExprList().addAll(right.getAtomicExprList()); newORExpr.getANDExprList().add(tmp); if (node != null) { ORExpression newORExpr = new ORExpression(); for (ANDExpression andExpr : orExprLeft.getANDExprList()) { newORExpr.getANDExprList().add(andExpr); for (ANDExpression andExpr : orExprRight.getANDExprList()) { newORExpr.getANDExprList().add(andExpr);
for (ANDExpression andExpr : orExpr.getANDExprList()) { partitionKeyValueMap.clear(); for (AtomicExpression ae : andExpr.getAtomicExprList()) {
@Override public Criterion build() { Criterion orCriterion = null; for(ANDExpression andExpression:expression.getANDExprList()){ Criterion andCriterion = null; for(AtomicExpression atomicExpression : andExpression.getAtomicExprList()){ Criterion atomicCriterion = toAtomicCriterion(atomicExpression); if(andCriterion == null){ andCriterion = atomicCriterion; }else{ andCriterion = andCriterion.and(atomicCriterion); } } if(andCriterion!=null){ if(orCriterion == null){ orCriterion = andCriterion; }else{ orCriterion = orCriterion.or(andCriterion); } } } return orCriterion; }
@Override public Criterion build() { Criterion orCriterion = null; for(ANDExpression andExpression:expression.getANDExprList()){ Criterion andCriterion = null; for(AtomicExpression atomicExpression : andExpression.getAtomicExprList()){ Criterion atomicCriterion = toAtomicCriterion(atomicExpression); if(andCriterion == null){ andCriterion = atomicCriterion; }else{ andCriterion = andCriterion.and(atomicCriterion); } } if(andCriterion!=null){ if(orCriterion == null){ orCriterion = andCriterion; }else{ orCriterion = orCriterion.or(andCriterion); } } } return orCriterion; }
@Test public void testContainQuery() { String query = "@name contains \"jame\""; EagleQueryParser parser = new EagleQueryParser(query); ORExpression or = null; try { or = parser.parse(); } catch (EagleQueryParseException ex) { Assert.fail(ex.getMessage()); } Assert.assertTrue(or.getANDExprList().size() == 1); Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size()); Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey()); Assert.assertEquals("jame", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("CONTAINS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType()); }
@Test public void testNumberQuery() { String query = "@field1 >= -1.234"; EagleQueryParser parser = new EagleQueryParser(query); ORExpression or = null; try { or = parser.parse(); } catch (EagleQueryParseException ex) { Assert.fail(ex.getMessage()); } Assert.assertTrue(or.getANDExprList().size() == 1); Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size()); Assert.assertEquals("@field1", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey()); Assert.assertEquals(-1.234, Double.parseDouble(or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()), 0.0001); Assert.assertEquals(">=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.NUMBER, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType()); }
@Test public void testCompareAtomicExpression() { String query = "EXP{@mapProgress} < EXP{@reduceProgress}"; EagleQueryParser parser = new EagleQueryParser(query); ORExpression or = null; try { or = parser.parse(); } catch (EagleQueryParseException ex) { Assert.fail(ex.getMessage()); } Assert.assertTrue(or.getANDExprList().size() == 1); Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size()); Assert.assertEquals("mapProgress", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey()); Assert.assertEquals("reduceProgress", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("<", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals("(mapProgress<reduceProgress)", or.toString()); }
@Test public void testComplexExpressionWithNestedBrace() { String query = "EXP{((@a + @b) / @c) + @d}< 0.005"; EagleQueryParser parser = new EagleQueryParser(query); ORExpression or = null; try { or = parser.parse(); } catch (EagleQueryParseException ex) { Assert.fail(ex.getMessage()); } Assert.assertTrue(or.getANDExprList().size() == 1); Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size()); Assert.assertEquals("((a + b) / c) + d", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey()); Assert.assertEquals("0.005", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("<", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals("(((a + b) / c) + d<0.005)", or.toString()); }
@Test public void testSingleExpression() { String query = "@cluster=\"a\""; EagleQueryParser parser = new EagleQueryParser(query); ORExpression or = null; try { or = parser.parse(); } catch (EagleQueryParseException ex) { Assert.fail(ex.getMessage()); } Assert.assertTrue(or.getANDExprList().size() == 1); Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size()); Assert.assertEquals("@cluster", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey()); Assert.assertEquals("a", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); LOG.info(or.toString()); Assert.assertEquals("(@cluster=\"a\")", or.toString()); }
@Test public void testLessOrEqualExpression() { String query = "@field1<=\"1\""; EagleQueryParser parser = new EagleQueryParser(query); ORExpression or = null; try { or = parser.parse(); } catch (EagleQueryParseException ex) { Assert.fail(ex.getMessage()); } Assert.assertTrue(or.getANDExprList().size() == 1); Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size()); Assert.assertEquals("@field1", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey()); Assert.assertEquals("1", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("<=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); LOG.info(or.toString()); Assert.assertEquals("(@field1<=\"1\")", or.toString()); }
@Test public void testSimpleWildcardMatchQuery() { String expected = "-[]/{}()*+?.\\^$|"; String query = "@user=\"-[]/{}()*+?.\\\\^$|\""; System.out.println(query); EagleQueryParser parser = new EagleQueryParser(query); ORExpression or = null; try { or = parser.parse(); } catch (EagleQueryParseException ex) { Assert.fail(ex.getMessage()); } Assert.assertTrue(or.getANDExprList().size() == 1); Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size()); Assert.assertEquals("@user", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey()); Assert.assertEquals(expected, or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); LOG.info(or.toString()); Assert.assertEquals("(@user=\""+expected+"\")", or.toString()); }
@Test public void testGreaterOrEqualExpression() { String query = "@field1>=\"1\""; EagleQueryParser parser = new EagleQueryParser(query); ORExpression or = null; try { or = parser.parse(); } catch (EagleQueryParseException ex) { Assert.fail(ex.getMessage()); } Assert.assertTrue(or.getANDExprList().size() == 1); Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size()); Assert.assertEquals("@field1", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey()); Assert.assertEquals("1", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals(">=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType()); LOG.info(or.toString()); Assert.assertEquals("(@field1>=\"1\")", or.toString()); }
@Test public void testCompareArithmeticExpressionWithNumeric() { String query = "EXP{(@mapProgress + @reduceProgress) / (@endTime - @startTime)} < 0.005"; EagleQueryParser parser = new EagleQueryParser(query); ORExpression or = null; try { or = parser.parse(); } catch (EagleQueryParseException ex) { Assert.fail(ex.getMessage()); } Assert.assertTrue(or.getANDExprList().size() == 1); Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size()); Assert.assertEquals("(mapProgress + reduceProgress) / (endTime - startTime)", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey()); Assert.assertEquals("0.005", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("<", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); LOG.info(or.toString()); Assert.assertEquals("((mapProgress + reduceProgress) / (endTime - startTime)<0.005)", or.toString()); }
@Test public void testLessThanExpression() { String query = "@field1<\"1\""; EagleQueryParser parser = new EagleQueryParser(query); ORExpression or = null; try { or = parser.parse(); } catch (EagleQueryParseException ex) { Assert.fail(ex.getMessage()); } Assert.assertTrue(or.getANDExprList().size() == 1); Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size()); Assert.assertEquals("@field1", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey()); Assert.assertEquals("1", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("<", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); LOG.info(or.toString()); Assert.assertEquals("(@field1<\"1\")", or.toString()); }
@Test public void testGreaterThanExpression() { String query = "@field1>\"1\""; EagleQueryParser parser = new EagleQueryParser(query); ORExpression or = null; try { or = parser.parse(); } catch (EagleQueryParseException ex) { Assert.fail(ex.getMessage()); } Assert.assertTrue(or.getANDExprList().size() == 1); Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size()); Assert.assertEquals("@field1", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey()); Assert.assertEquals("1", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals(">", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); LOG.info(or.toString()); Assert.assertEquals("(@field1>\"1\")", or.toString()); }
@Test public void testEmptyString() { String query = "@name = \"\""; EagleQueryParser parser = new EagleQueryParser(query); ORExpression or = null; try { or = parser.parse(); } catch (EagleQueryParseException ex) { Assert.fail(ex.getMessage()); } Assert.assertNotNull(or); Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey()); Assert.assertEquals("", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType()); }
ANDExpression andExpr = new ANDExpression(); andExpr.getAtomicExprList().add(kv); orExpr.getANDExprList().add(andExpr); _stack.push(orExpr);
Assert.fail(ex.getMessage()); Assert.assertTrue(or.getANDExprList().size() == 1); Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size()); Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey()); Assert.assertEquals("jame", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("NOT CONTAINS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType()); Assert.fail(ex.getMessage()); Assert.assertTrue(or.getANDExprList().size() == 1); Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size()); Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey()); Assert.assertEquals("jame", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("NOT CONTAINS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType()); Assert.fail(ex.getMessage()); Assert.assertTrue(or.getANDExprList().size() == 1); Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size()); Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey()); Assert.assertEquals("jame", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("NOT CONTAINS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
@Test public void testComplexExpressionWithConditionAndNestedBrace() { String query = "(EXP{(@a + @b) / ((@c + @d)*(@e)/(@d))} > EXP{@c + @d}) AND (EXP{@e + @f} > EXP{@h + @i})"; EagleQueryParser parser = new EagleQueryParser(query); ORExpression or = null; try { or = parser.parse(); } catch (EagleQueryParseException ex) { Assert.fail(ex.getMessage()); } Assert.assertTrue(or.getANDExprList().size() == 1); ANDExpression and = or.getANDExprList().get(0); Assert.assertEquals(2, and.getAtomicExprList().size()); Assert.assertEquals("(a + b) / ((c + d)*(e)/(d))>c + d", and.getAtomicExprList().get(0).toString()); Assert.assertEquals("e + f>h + i", and.getAtomicExprList().get(1).toString()); AtomicExpression leftExpression = and.getAtomicExprList().get(0); Assert.assertEquals("(a + b) / ((c + d)*(e)/(d))", leftExpression.getKey()); Assert.assertEquals(">", leftExpression.getOp().toString()); Assert.assertEquals("c + d", leftExpression.getValue()); AtomicExpression rightExpression = and.getAtomicExprList().get(1); Assert.assertEquals("e + f", rightExpression.getKey()); Assert.assertEquals(">", rightExpression.getOp().toString()); Assert.assertEquals("h + i",rightExpression.getValue()); }
@Test public void testComplexExpressionWithAndCondition() { String query = "(EXP{@a + @b} > 3) AND (@b >10)"; EagleQueryParser parser = new EagleQueryParser(query); ORExpression or = null; try { or = parser.parse(); } catch (EagleQueryParseException ex) { Assert.fail(ex.getMessage()); } Assert.assertTrue(or.getANDExprList().size() == 1); ANDExpression and = or.getANDExprList().get(0); Assert.assertEquals(2, and.getAtomicExprList().size()); Assert.assertEquals("a + b>3", and.getAtomicExprList().get(0).toString()); Assert.assertEquals("@b>10", and.getAtomicExprList().get(1).toString()); AtomicExpression leftExpression = and.getAtomicExprList().get(0); Assert.assertEquals("a + b", leftExpression.getKey()); Assert.assertEquals(TokenType.EXP, leftExpression.getKeyType()); Assert.assertEquals(">", leftExpression.getOp().toString()); Assert.assertEquals("3", leftExpression.getValue()); Assert.assertEquals(TokenType.NUMBER, leftExpression.getValueType()); AtomicExpression rightExpression = and.getAtomicExprList().get(1); Assert.assertEquals("@b", rightExpression.getKey()); Assert.assertEquals(TokenType.ID, rightExpression.getKeyType()); Assert.assertEquals(">", rightExpression.getOp().toString()); Assert.assertEquals("10",rightExpression.getValue()); Assert.assertEquals(TokenType.NUMBER, rightExpression.getValueType()); }