use of io.confluent.ksql.parser.ParsingException in project ksql by confluentinc.
the class ParserUtil method visitIntegerLiteral.
public static Literal visitIntegerLiteral(final IntegerLiteralContext context) {
final Optional<NodeLocation> location = getLocation(context);
final long valueAsLong;
try {
valueAsLong = Long.parseLong(context.getText());
} catch (final NumberFormatException e) {
throw new ParsingException("Invalid numeric literal: " + context.getText(), location);
}
if (valueAsLong <= Integer.MAX_VALUE && valueAsLong >= Integer.MIN_VALUE) {
return new IntegerLiteral(location, (int) valueAsLong);
} else {
return new LongLiteral(location, valueAsLong);
}
}
use of io.confluent.ksql.parser.ParsingException in project ksql by confluentinc.
the class SqlTestReaderTest method shouldThrowOnInvalidStatement.
@Test
public void shouldThrowOnInvalidStatement() {
final String contents = "" + "CREATE foo;\n";
// When:
final SqlTestReader reader = SqlTestReader.of(contents);
final ParsingException parsingException = assertThrows(ParsingException.class, reader::next);
// Then:
assertThat(parsingException.getMessage(), is("line 1:8: no viable alternative at input 'CREATE foo'"));
}
use of io.confluent.ksql.parser.ParsingException in project ksql by confluentinc.
the class DirectiveParser method parse.
public static TestDirective parse(final Token comment) {
final NodeLocation loc = new NodeLocation(comment.getLine(), comment.getCharPositionInLine());
final Matcher matcher = DIRECTIVE_REGEX.matcher(comment.getText().trim());
if (!matcher.find()) {
throw new ParsingException("Expected directive matching pattern " + DIRECTIVE_REGEX + " but got " + comment, null, loc.getLineNumber(), loc.getColumnNumber());
}
final Type type = Type.from(matcher.group("type").toLowerCase());
final String contents = matcher.group("contents");
return new TestDirective(type, contents, loc);
}
use of io.confluent.ksql.parser.ParsingException in project ksql by confluentinc.
the class QueryLogger method log.
private static void log(final Level level, final Object message, final String query) {
try {
final String anonQuery = anonymizeQueries ? anonymizer.anonymize(query) : query;
final QueryGuid queryGuids = buildGuids(query, anonQuery);
logger.log(level, buildPayload(message, anonQuery, queryGuids));
} catch (ParsingException e) {
if (logger.isDebugEnabled()) {
Logger.getRootLogger().log(Level.DEBUG, String.format("Failed to parse a query in query logger, message: %s", message));
}
}
}
Aggregations