public static ComparisonOperator locateOperator(String op) { op = op.replaceAll("\\s+"," "); for (ComparisonOperator o : ComparisonOperator.values()) { if (op.toUpperCase().equals(o.storedOp)) { return o; } } throw new UnsupportedExpressionOperatorException(op); } }
@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()); }
protected static CompareOp getHBaseCompareOp(String comp) { return convertToHBaseCompareOp(ComparisonOperator.locateOperator(comp)); } }
@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()); }
public static ComparisonOperator locateOperator(String op){ op = op.replaceAll("\\s+"," "); for(ComparisonOperator o : ComparisonOperator.values()){ if(op.toUpperCase().equals(o._op)){ return o; } } throw new UnsupportedExpressionOperatorException(op); } }
protected static CompareOp getHBaseCompareOp(String comp) { return convertToHBaseCompareOp(ComparisonOperator.locateOperator(comp)); } }
@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 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 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 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 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 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 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()); }