use of io.confluent.ksql.metastore.TypeRegistry in project ksql by confluentinc.
the class SchemaParser method parse.
public TableElements parse(final String schema) {
if (schema.trim().isEmpty()) {
return TableElements.of();
}
final SqlBaseLexer lexer = new SqlBaseLexer(new CaseInsensitiveStream(CharStreams.fromString("(" + schema + ")")));
final CommonTokenStream tokStream = new CommonTokenStream(lexer);
final SqlBaseParser parser = new SqlBaseParser(tokStream);
final BaseErrorListener errorListener = new BaseErrorListener() {
@Override
public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol, final int line, final int charPositionInLine, final String msg, final RecognitionException e) {
throw new KsqlException(String.format("Error parsing schema \"%s\" at %d:%d: %s", schema, line, charPositionInLine, msg), e);
}
};
lexer.removeErrorListeners();
lexer.addErrorListener(errorListener);
parser.removeErrorListeners();
parser.addErrorListener(errorListener);
final SqlTypeParser typeParser = SqlTypeParser.create(typeRegistry);
final List<TableElement> elements = parser.tableElements().tableElement().stream().map(ctx -> new TableElement(getLocation(ctx), ColumnName.of(ParserUtil.getIdentifierText(ctx.identifier())), typeParser.getType(ctx.type()), ParserUtil.getColumnConstraints(ctx.columnConstraints()))).collect(Collectors.toList());
return TableElements.of(elements);
}
use of io.confluent.ksql.metastore.TypeRegistry in project ksql by confluentinc.
the class DeprecatedStatementsCheckerTest method parse.
private Statement parse(final String statementText) {
final TypeRegistry mockTypeRegistry = Mockito.mock(TypeRegistry.class);
final AstBuilder statementBuilder = new AstBuilder(mockTypeRegistry);
return statementBuilder.buildStatement(Iterables.getOnlyElement(STATEMENT_PARSER.parse(statementText)).getStatement());
}
Aggregations