Search in sources :

Example 1 with ParsingException

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);
    }
}
Also used : NodeLocation(io.confluent.ksql.parser.NodeLocation) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) ParsingException(io.confluent.ksql.parser.ParsingException) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral)

Example 2 with ParsingException

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'"));
}
Also used : ParsingException(io.confluent.ksql.parser.ParsingException) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 3 with ParsingException

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);
}
Also used : Type(io.confluent.ksql.test.parser.TestDirective.Type) NodeLocation(io.confluent.ksql.parser.NodeLocation) Matcher(java.util.regex.Matcher) ParsingException(io.confluent.ksql.parser.ParsingException)

Example 4 with ParsingException

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));
        }
    }
}
Also used : ParsingException(io.confluent.ksql.parser.ParsingException) QueryGuid(io.confluent.ksql.util.QueryGuid)

Aggregations

ParsingException (io.confluent.ksql.parser.ParsingException)4 NodeLocation (io.confluent.ksql.parser.NodeLocation)2 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)1 LongLiteral (io.confluent.ksql.execution.expression.tree.LongLiteral)1 Type (io.confluent.ksql.test.parser.TestDirective.Type)1 QueryGuid (io.confluent.ksql.util.QueryGuid)1 Matcher (java.util.regex.Matcher)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1