@Test public void testFilterCaluses() { BrokerRequest brokerRequest = COMPILER.compileToBrokerRequest("select * from vegetables where a > 1"); Assert.assertEquals(brokerRequest.getFilterQuery().getColumn(), "a"); Assert.assertEquals(brokerRequest.getFilterQuery().getOperator(), FilterOperator.RANGE); Assert.assertEquals(brokerRequest.getFilterQuery().getValue().get(0), "(1\t\t*)"); Function func = brokerRequest.getPinotQuery().getFilterExpression().getFunctionCall(); Assert.assertEquals(func.getOperator(), FilterKind.GREATER_THAN.name()); Assert.assertEquals(func.getOperands().get(0).getIdentifier().getName(), "a"); Assert.assertEquals(func.getOperands().get(1).getLiteral().getLongValue(), 1); brokerRequest = COMPILER.compileToBrokerRequest("select * from vegetables where b < 100"); Assert.assertEquals(brokerRequest.getFilterQuery().getColumn(), "b"); Assert.assertEquals(brokerRequest.getFilterQuery().getOperator(), FilterOperator.RANGE); Assert.assertEquals(brokerRequest.getFilterQuery().getValue().get(0), "(*\t\t100)"); func = brokerRequest.getPinotQuery().getFilterExpression().getFunctionCall(); Assert.assertEquals(func.getOperator(), FilterKind.LESS_THAN.name()); Assert.assertEquals(func.getOperands().get(0).getIdentifier().getName(), "b"); Assert.assertEquals(func.getOperands().get(1).getLiteral().getLongValue(), 100); brokerRequest = COMPILER.compileToBrokerRequest("select * from vegetables where c >= 10"); Assert.assertEquals(brokerRequest.getFilterQuery().getColumn(), "c"); Assert.assertEquals(brokerRequest.getFilterQuery().getOperator(), FilterOperator.RANGE); Assert.assertEquals(brokerRequest.getFilterQuery().getValue().get(0), "[10\t\t*)"); func = brokerRequest.getPinotQuery().getFilterExpression().getFunctionCall(); Assert.assertEquals(func.getOperator(), FilterKind.GREATER_THAN_OR_EQUAL.name()); Assert.assertEquals(func.getOperands().get(0).getIdentifier().getName(), "c"); Assert.assertEquals(func.getOperands().get(1).getLiteral().getLongValue(), 10); brokerRequest = COMPILER.compileToBrokerRequest("select * from vegetables where d <= 50"); Assert.assertEquals(brokerRequest.getFilterQuery().getColumn(), "d"); Assert.assertEquals(brokerRequest.getFilterQuery().getOperator(), FilterOperator.RANGE); Assert.assertEquals(brokerRequest.getFilterQuery().getValue().get(0), "(*\t\t50]"); func = brokerRequest.getPinotQuery().getFilterExpression().getFunctionCall(); Assert.assertEquals(func.getOperator(), FilterKind.LESS_THAN_OR_EQUAL.name()); Assert.assertEquals(func.getOperands().get(0).getIdentifier().getName(), "d"); Assert.assertEquals(func.getOperands().get(1).getLiteral().getLongValue(), 50); brokerRequest = COMPILER.compileToBrokerRequest("select * from vegetables where e BETWEEN 70 AND 80"); Assert.assertEquals(brokerRequest.getFilterQuery().getColumn(), "e"); Assert.assertEquals(brokerRequest.getFilterQuery().getOperator(), FilterOperator.RANGE); Assert.assertEquals(brokerRequest.getFilterQuery().getValue().get(0), "[70\t\t80]"); func = brokerRequest.getPinotQuery().getFilterExpression().getFunctionCall(); Assert.assertEquals(func.getOperator(), FilterKind.BETWEEN.name()); Assert.assertEquals(func.getOperands().get(0).getIdentifier().getName(), "e"); Assert.assertEquals(func.getOperands().get(1).getLiteral().getLongValue(), 70); Assert.assertEquals(func.getOperands().get(2).getLiteral().getLongValue(), 80); }
@Override public BrokerRequest compileToBrokerRequest(String expression) throws Pql2CompilationException { try { CharStream charStream = new ANTLRInputStream(expression); PQL2Lexer lexer = new PQL2Lexer(charStream); lexer.setTokenFactory(new CommonTokenFactory(true)); lexer.removeErrorListeners(); lexer.addErrorListener(ERROR_LISTENER); TokenStream tokenStream = new UnbufferedTokenStream<CommonToken>(lexer); PQL2Parser parser = new PQL2Parser(tokenStream); parser.setErrorHandler(new BailErrorStrategy()); parser.removeErrorListeners(); parser.addErrorListener(ERROR_LISTENER); ParseTree parseTree = parser.root(); ParseTreeWalker walker = new ParseTreeWalker(); Pql2AstListener listener = new Pql2AstListener(expression); walker.walk(listener, parseTree); AstNode rootNode = listener.getRootNode(); BrokerRequest brokerRequest = new BrokerRequest(); rootNode.updateBrokerRequest(brokerRequest); if (ENABLE_PINOT_QUERY) { try { PinotQuery pinotQuery = new PinotQuery(); rootNode.updatePinotQuery(pinotQuery); if (VALIDATE_CONVERTER) { PinotQuery2BrokerRequestConverter converter = new PinotQuery2BrokerRequestConverter(); BrokerRequest tempBrokerRequest = converter.convert(pinotQuery); boolean result = BrokerRequestComparisonUtils.validate(brokerRequest, tempBrokerRequest); if (!result) { LOGGER.error("Pinot query to broker request conversion failed. PQL:{}", expression); if (FAIL_ON_CONVERSION_ERROR) { throw new Pql2CompilationException( "Pinot query to broker request conversion failed. PQL:" + expression); } } } brokerRequest.setPinotQuery(pinotQuery); } catch (Exception e) { LOGGER.error("Non fatal: Failed to populate pinot query and broker request. PQL:{}", expression, e); if (FAIL_ON_CONVERSION_ERROR) { throw e; } } } return brokerRequest; } catch (Pql2CompilationException e) { throw e; } catch (Exception e) { throw new Pql2CompilationException(ExceptionUtils.getStackTrace(e)); } }
Pql2Compiler implements AbstractCompiler { @Override public BrokerRequest compileToBrokerRequest(String expression) throws Pql2CompilationException { try { CharStream charStream = new ANTLRInputStream(expression); PQL2Lexer lexer = new PQL2Lexer(charStream); lexer.setTokenFactory(new CommonTokenFactory(true)); lexer.removeErrorListeners(); lexer.addErrorListener(ERROR_LISTENER); TokenStream tokenStream = new UnbufferedTokenStream<CommonToken>(lexer); PQL2Parser parser = new PQL2Parser(tokenStream); parser.setErrorHandler(new BailErrorStrategy()); parser.removeErrorListeners(); parser.addErrorListener(ERROR_LISTENER); ParseTree parseTree = parser.root(); ParseTreeWalker walker = new ParseTreeWalker(); Pql2AstListener listener = new Pql2AstListener(expression); walker.walk(listener, parseTree); AstNode rootNode = listener.getRootNode(); BrokerRequest brokerRequest = new BrokerRequest(); rootNode.updateBrokerRequest(brokerRequest); if (ENABLE_PINOT_QUERY) { try { PinotQuery pinotQuery = new PinotQuery(); rootNode.updatePinotQuery(pinotQuery); if (VALIDATE_CONVERTER) { PinotQuery2BrokerRequestConverter converter = new PinotQuery2BrokerRequestConverter(); BrokerRequest tempBrokerRequest = converter.convert(pinotQuery); boolean result = BrokerRequestComparisonUtils.validate(brokerRequest, tempBrokerRequest); if (!result) { LOGGER.error("Pinot query to broker request conversion failed. PQL:{}", expression); if (FAIL_ON_CONVERSION_ERROR) { throw new Pql2CompilationException( "Pinot query to broker request conversion failed. PQL:" + expression); } } } brokerRequest.setPinotQuery(pinotQuery); } catch (Exception e) { LOGGER.error("Non fatal: Failed to populate pinot query and broker request. PQL:{}", expression, e); if (FAIL_ON_CONVERSION_ERROR) { throw e; } } } return brokerRequest; } catch (Pql2CompilationException e) { throw e; } catch (Exception e) { throw new Pql2CompilationException(ExceptionUtils.getStackTrace(e)); } } }
Pql2Compiler implements AbstractCompiler { @Override public BrokerRequest compileToBrokerRequest(String expression) throws Pql2CompilationException { try { CharStream charStream = new ANTLRInputStream(expression); PQL2Lexer lexer = new PQL2Lexer(charStream); lexer.setTokenFactory(new CommonTokenFactory(true)); lexer.removeErrorListeners(); lexer.addErrorListener(ERROR_LISTENER); TokenStream tokenStream = new UnbufferedTokenStream<CommonToken>(lexer); PQL2Parser parser = new PQL2Parser(tokenStream); parser.setErrorHandler(new BailErrorStrategy()); parser.removeErrorListeners(); parser.addErrorListener(ERROR_LISTENER); ParseTree parseTree = parser.root(); ParseTreeWalker walker = new ParseTreeWalker(); Pql2AstListener listener = new Pql2AstListener(expression); walker.walk(listener, parseTree); AstNode rootNode = listener.getRootNode(); BrokerRequest brokerRequest = new BrokerRequest(); rootNode.updateBrokerRequest(brokerRequest); if (ENABLE_PINOT_QUERY) { try { PinotQuery pinotQuery = new PinotQuery(); rootNode.updatePinotQuery(pinotQuery); if (VALIDATE_CONVERTER) { PinotQuery2BrokerRequestConverter converter = new PinotQuery2BrokerRequestConverter(); BrokerRequest tempBrokerRequest = converter.convert(pinotQuery); boolean result = BrokerRequestComparisonUtils.validate(brokerRequest, tempBrokerRequest); if (!result) { LOGGER.error("Pinot query to broker request conversion failed. PQL:{}", expression); if (FAIL_ON_CONVERSION_ERROR) { throw new Pql2CompilationException( "Pinot query to broker request conversion failed. PQL:" + expression); } } } brokerRequest.setPinotQuery(pinotQuery); } catch (Exception e) { LOGGER.error("Non fatal: Failed to populate pinot query and broker request. PQL:{}", expression, e); if (FAIL_ON_CONVERSION_ERROR) { throw e; } } } return brokerRequest; } catch (Pql2CompilationException e) { throw e; } catch (Exception e) { throw new Pql2CompilationException(ExceptionUtils.getStackTrace(e)); } }  }
Pql2Compiler implements AbstractCompiler { @Override public BrokerRequest compileToBrokerRequest(String expression) throws Pql2CompilationException { try { CharStream charStream = new ANTLRInputStream(expression); PQL2Lexer lexer = new PQL2Lexer(charStream); lexer.setTokenFactory(new CommonTokenFactory(true)); lexer.removeErrorListeners(); lexer.addErrorListener(ERROR_LISTENER); TokenStream tokenStream = new UnbufferedTokenStream<CommonToken>(lexer); PQL2Parser parser = new PQL2Parser(tokenStream); parser.setErrorHandler(new BailErrorStrategy()); parser.removeErrorListeners(); parser.addErrorListener(ERROR_LISTENER); ParseTree parseTree = parser.root(); ParseTreeWalker walker = new ParseTreeWalker(); Pql2AstListener listener = new Pql2AstListener(expression); walker.walk(listener, parseTree); AstNode rootNode = listener.getRootNode(); BrokerRequest brokerRequest = new BrokerRequest(); rootNode.updateBrokerRequest(brokerRequest); if (ENABLE_PINOT_QUERY) { try { PinotQuery pinotQuery = new PinotQuery(); rootNode.updatePinotQuery(pinotQuery); if (VALIDATE_CONVERTER) { PinotQuery2BrokerRequestConverter converter = new PinotQuery2BrokerRequestConverter(); BrokerRequest tempBrokerRequest = converter.convert(pinotQuery); boolean result = BrokerRequestComparisonUtils.validate(brokerRequest, tempBrokerRequest); if (!result) { LOGGER.error("Pinot query to broker request conversion failed. PQL:{}", expression); if (FAIL_ON_CONVERSION_ERROR) { throw new Pql2CompilationException( "Pinot query to broker request conversion failed. PQL:" + expression); } } } brokerRequest.setPinotQuery(pinotQuery); } catch (Exception e) { LOGGER.error("Non fatal: Failed to populate pinot query and broker request. PQL:{}", expression, e); if (FAIL_ON_CONVERSION_ERROR) { throw e; } } } return brokerRequest; } catch (Pql2CompilationException e) { throw e; } catch (Exception e) { throw new Pql2CompilationException(ExceptionUtils.getStackTrace(e)); } }  @Override BrokerRequest compileToBrokerRequest(String expression); AstNode parseToAstNode(String expression); TransformExpressionTree compileToExpressionTree(String expression); static AstNode buildAst(String expression); }
Pql2Compiler implements AbstractCompiler { @Override public BrokerRequest compileToBrokerRequest(String expression) throws Pql2CompilationException { try { CharStream charStream = new ANTLRInputStream(expression); PQL2Lexer lexer = new PQL2Lexer(charStream); lexer.setTokenFactory(new CommonTokenFactory(true)); lexer.removeErrorListeners(); lexer.addErrorListener(ERROR_LISTENER); TokenStream tokenStream = new UnbufferedTokenStream<CommonToken>(lexer); PQL2Parser parser = new PQL2Parser(tokenStream); parser.setErrorHandler(new BailErrorStrategy()); parser.removeErrorListeners(); parser.addErrorListener(ERROR_LISTENER); ParseTree parseTree = parser.root(); ParseTreeWalker walker = new ParseTreeWalker(); Pql2AstListener listener = new Pql2AstListener(expression); walker.walk(listener, parseTree); AstNode rootNode = listener.getRootNode(); BrokerRequest brokerRequest = new BrokerRequest(); rootNode.updateBrokerRequest(brokerRequest); if (ENABLE_PINOT_QUERY) { try { PinotQuery pinotQuery = new PinotQuery(); rootNode.updatePinotQuery(pinotQuery); if (VALIDATE_CONVERTER) { PinotQuery2BrokerRequestConverter converter = new PinotQuery2BrokerRequestConverter(); BrokerRequest tempBrokerRequest = converter.convert(pinotQuery); boolean result = BrokerRequestComparisonUtils.validate(brokerRequest, tempBrokerRequest); if (!result) { LOGGER.error("Pinot query to broker request conversion failed. PQL:{}", expression); if (FAIL_ON_CONVERSION_ERROR) { throw new Pql2CompilationException( "Pinot query to broker request conversion failed. PQL:" + expression); } } } brokerRequest.setPinotQuery(pinotQuery); } catch (Exception e) { LOGGER.error("Non fatal: Failed to populate pinot query and broker request. PQL:{}", expression, e); if (FAIL_ON_CONVERSION_ERROR) { throw e; } } } return brokerRequest; } catch (Pql2CompilationException e) { throw e; } catch (Exception e) { throw new Pql2CompilationException(ExceptionUtils.getStackTrace(e)); } }  @Override BrokerRequest compileToBrokerRequest(String expression); AstNode parseToAstNode(String expression); TransformExpressionTree compileToExpressionTree(String expression); static AstNode buildAst(String expression); static boolean ENABLE_PINOT_QUERY; static boolean VALIDATE_CONVERTER; static boolean FAIL_ON_CONVERSION_ERROR; }