use of io.confluent.ksql.util.DataSourceExtractor in project ksql by confluentinc.
the class KsqlParser method buildAst.
/**
* Builds an AST from the given query string.
*/
public List<Statement> buildAst(String sql, MetaStore metaStore) {
try {
ParserRuleContext tree = getParseTree(sql);
SqlBaseParser.StatementsContext statementsContext = (SqlBaseParser.StatementsContext) tree;
List<Statement> astNodes = new ArrayList<>();
for (SqlBaseParser.SingleStatementContext statementContext : statementsContext.singleStatement()) {
DataSourceExtractor dataSourceExtractor = new DataSourceExtractor(metaStore);
dataSourceExtractor.extractDataSources(statementContext);
Node root = new AstBuilder(dataSourceExtractor).visit(statementContext);
Statement statement = (Statement) root;
astNodes.add(statement);
}
return astNodes;
} catch (Exception e) {
// if we fail, parse with LL mode
throw new ParseFailedException(e.getMessage(), e);
}
}
use of io.confluent.ksql.util.DataSourceExtractor in project ksql by confluentinc.
the class KsqlParser method prepareStatement.
public Pair<Statement, DataSourceExtractor> prepareStatement(SqlBaseParser.SingleStatementContext statementContext, MetaStore metaStore) {
DataSourceExtractor dataSourceExtractor = new DataSourceExtractor(metaStore);
dataSourceExtractor.extractDataSources(statementContext);
AstBuilder astBuilder = new AstBuilder(dataSourceExtractor);
Node root = astBuilder.visit(statementContext);
Statement statement = (Statement) root;
return new Pair<>(statement, dataSourceExtractor);
}
use of io.confluent.ksql.util.DataSourceExtractor 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);
}
}
Aggregations