private Class<?> locateColumnType(AtomicExpression atomic) { String columnName = null; if(atomic.getKeyType().equals(TokenType.ID)){ columnName = parseEntityAttribute(atomic.getKey()); }else if(atomic.getValueType().equals(TokenType.ID)){ columnName = parseEntityAttribute(atomic.getValue()); } if(jdbcEntityDefinition.getInternal().getDisplayNameMap().containsKey(columnName)){ try { return jdbcEntityDefinition.getColumnType(columnName); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } }else{ return null; } }
private Class<?> locateColumnType(AtomicExpression atomic) { String columnName = null; if(atomic.getKeyType().equals(TokenType.ID)){ columnName = parseEntityAttribute(atomic.getKey()); }else if(atomic.getValueType().equals(TokenType.ID)){ columnName = parseEntityAttribute(atomic.getValue()); } if(jdbcEntityDefinition.getInternal().getDisplayNameMap().containsKey(columnName)){ try { return jdbcEntityDefinition.getColumnType(columnName); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } }else{ return null; } }
kv.setValue(postProcessNode(value.getText(),kv.getValueType())); if(kv.getValueType() != TokenType.LIST) kv.setValue(StringEscapeUtils.unescapeJava(kv.getValue()));
kv.setValue(postProcessNode(value.getText(),kv.getValueType())); if (kv.getValueType() != TokenType.LIST) { kv.setValue(StringEscapeUtils.unescapeJava(kv.getValue()));
ComparisonOperator op = ae.getOp(); TokenType keyType = ae.getKeyType(); TokenType valueType = ae.getValueType(); QualifierFilterEntity entry = new QualifierFilterEntity(fieldName,value,op,keyType,valueType);
ComparisonOperator op = ae.getOp(); TokenType keyType = ae.getKeyType(); TokenType valueType = ae.getValueType(); QualifierFilterEntity entry = new QualifierFilterEntity(fieldName, value, op, keyType, valueType);
private Criterion toAtomicCriterion(AtomicExpression atomic){ Class<?> columnType = locateColumnType(atomic); Object left = toColumn(atomic.getKeyType(), atomic.getKey(),atomic.getOp(),columnType); Object right = toColumn(atomic.getValueType(), atomic.getValue(), atomic.getOp(),columnType); SqlEnum op = toSqlEnum(atomic.getOp()); return new Criterion(left,right,op); }
private Criterion toAtomicCriterion(AtomicExpression atomic){ Class<?> columnType = locateColumnType(atomic); Object left = toColumn(atomic.getKeyType(), atomic.getKey(),atomic.getOp(),columnType); Object right = toColumn(atomic.getValueType(), atomic.getValue(), atomic.getOp(),columnType); SqlEnum op = toSqlEnum(atomic.getOp()); return new Criterion(left,right,op); }
@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 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 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()); }
@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()); }
Assert.assertEquals("(\"jame\",\"lebron\")", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("IN", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.LIST, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType()); Assert.assertEquals("(1,\"lebron\")", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("NOT IN", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.LIST, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType()); Assert.assertEquals("(1,\"lebron\")", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("NOT IN", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.LIST, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
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.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.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.assertEquals("james", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("IS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType()); Assert.assertEquals("james", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("IS NOT", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType()); Assert.assertEquals("1.234", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("IS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.NUMBER, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType()); Assert.assertEquals("1.234", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("IS NOT", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.NUMBER, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
Assert.assertEquals("@cluster", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey()); Assert.assertEquals("abc", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType()); Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals("@host", or.getANDExprList().get(0).getAtomicExprList().get(1).getKey()); Assert.assertEquals("dc123.xyz.com", or.getANDExprList().get(0).getAtomicExprList().get(1).getValue()); Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(1).getValueType()); Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(1).getOp().toString()); LOG.info(or.toString());
Assert.assertEquals("value\"content, and another content", 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()); Assert.assertEquals("(\"value\\\"content, and another content\",\"others item\")", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("IN", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.LIST, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType()); Assert.assertEquals("(\"value\\\"content, and another content\",\"others item\",-1.2345)", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("IN", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.LIST, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
Assert.assertEquals("null", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("IS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.NULL, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType()); Assert.assertEquals("NULL", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("IS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.NULL, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType()); Assert.assertEquals("null", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("IS NOT", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.NULL, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType()); Assert.assertEquals("NULL", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("IS NOT", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.NULL, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType()); Assert.assertEquals("NULL", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.NULL, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType()); Assert.assertEquals("NULL", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()); Assert.assertEquals("!=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString()); Assert.assertEquals(TokenType.NULL, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
@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()); }