use of io.confluent.ksql.parser.KsqlParser in project ksql by confluentinc.
the class KsqlEngine method parseQueries.
// Visible for Testing
List<Pair<String, Statement>> parseQueries(final String queriesString, final Map<String, Object> overriddenProperties, final MetaStore tempMetaStore) {
try {
MetaStore tempMetaStoreForParser = tempMetaStore.clone();
// Parse and AST creation
KsqlParser ksqlParser = new KsqlParser();
List<SqlBaseParser.SingleStatementContext> parsedStatements = ksqlParser.getStatements(queriesString);
List<Pair<String, Statement>> queryList = new ArrayList<>();
for (SqlBaseParser.SingleStatementContext singleStatementContext : parsedStatements) {
Pair<Statement, DataSourceExtractor> statementInfo = ksqlParser.prepareStatement(singleStatementContext, tempMetaStoreForParser);
Statement statement = statementInfo.getLeft();
Pair<String, Statement> queryPair = buildSingleQueryAst(statement, getStatementString(singleStatementContext), tempMetaStore, tempMetaStoreForParser, overriddenProperties);
if (queryPair != null) {
queryList.add(queryPair);
}
}
return queryList;
} catch (Exception e) {
throw new ParseFailedException("Parsing failed on KsqlEngine msg:" + e.getMessage(), e);
}
}
use of io.confluent.ksql.parser.KsqlParser in project ksql by confluentinc.
the class KsqlResource method getStatementStrings.
public List<String> getStatementStrings(String ksqlString) {
List<SqlBaseParser.SingleStatementContext> statementContexts = new KsqlParser().getStatements(ksqlString);
List<String> result = new ArrayList<>(statementContexts.size());
for (SqlBaseParser.SingleStatementContext statementContext : statementContexts) {
// Taken from http://stackoverflow
// .com/questions/16343288/how-do-i-get-the-original-text-that-an-antlr4-rule-matched
CharStream charStream = statementContext.start.getInputStream();
result.add(charStream.getText(new Interval(statementContext.start.getStartIndex(), statementContext.stop.getStopIndex())));
}
return result;
}
Aggregations