@Test public void testGroupByTopLimitBehavior() { BrokerRequest brokerRequest = COMPILER.compileToBrokerRequest("select count(*) from myTable group by dimA top 200"); Assert.assertEquals(brokerRequest.getGroupBy().getTopN(), 200); brokerRequest = COMPILER.compileToBrokerRequest("select count(*) from myTable group by dimA limit 300"); Assert.assertEquals(brokerRequest.getGroupBy().getTopN(), 300); brokerRequest = COMPILER.compileToBrokerRequest("select count(*) from myTable group by dimA"); Assert.assertEquals(brokerRequest.getGroupBy().getTopN(), 10); brokerRequest = COMPILER.compileToBrokerRequest("select count(*) from myTable group by dimA top 200 LIMIT 300"); Assert.assertEquals(brokerRequest.getGroupBy().getTopN(), 200); brokerRequest = COMPILER.compileToBrokerRequest("select count(*) from myTable group by dimA LIMIT 0"); Assert.assertEquals(brokerRequest.getGroupBy().getTopN(), 10); }
@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; }