Java 类com.facebook.presto.sql.parser.ParsingException 实例源码

项目:presto    文件:CreateViewTask.java   
private String getFormattedSql(CreateView statement)
{
    Query query = statement.getQuery();
    String sql = formatSql(query);

    // verify round-trip
    Statement parsed;
    try {
        parsed = sqlParser.createStatement(sql);
    }
    catch (ParsingException e) {
        throw new PrestoException(INTERNAL_ERROR, "Formatted query does not parse: " + query);
    }
    if (!query.equals(parsed)) {
        throw new PrestoException(INTERNAL_ERROR, "Query does not round-trip: " + query);
    }

    return sql;
}
项目:presto    文件:Failures.java   
@Nullable
private static ErrorCode toErrorCode(@Nullable Throwable throwable)
{
    if (throwable == null) {
        return null;
    }

    if (throwable instanceof PrestoException) {
        return ((PrestoException) throwable).getErrorCode();
    }
    if (throwable instanceof Failure && ((Failure) throwable).getErrorCode() != null) {
        return ((Failure) throwable).getErrorCode();
    }
    if (throwable instanceof ParsingException || throwable instanceof SemanticException) {
        return SYNTAX_ERROR.toErrorCode();
    }
    if (throwable.getCause() != null) {
        return toErrorCode(throwable.getCause());
    }
    return INTERNAL_ERROR.toErrorCode();
}
项目:presto    文件:StatementAnalyzer.java   
private Query parseView(String view, QualifiedObjectName name, Table node)
{
    try {
        Statement statement = sqlParser.createStatement(view);
        return checkType(statement, Query.class, "parsed view");
    }
    catch (ParsingException e) {
        throw new SemanticException(VIEW_PARSE_ERROR, node, "Failed parsing stored view '%s': %s", name, e.getMessage());
    }
}
项目:presto    文件:Console.java   
private static Optional<Object> getParsedStatement(String statement)
{
    try {
        return Optional.of((Object) SQL_PARSER.createStatement(statement));
    }
    catch (ParsingException e) {
        return Optional.empty();
    }
}
项目:presto    文件:BinaryLiteral.java   
public BinaryLiteral(Optional<NodeLocation> location, String value)
{
    super(location);
    requireNonNull(value, "value is null");
    String hexString = WHITESPACE_PATTERN.matcher(value).replaceAll("").toUpperCase();
    if (NOT_HEX_DIGIT_PATTERN.matcher(hexString).matches()) {
        throw new ParsingException("Binary literal can only contain hexadecimal digits", location.get());
    }
    if (hexString.length() % 2 != 0) {
        throw new ParsingException("Binary literal must contain an even number of digits", location.get());
    }
    this.value = Slices.wrappedBuffer(BaseEncoding.base16().decode(hexString));
}
项目:presto    文件:LongLiteral.java   
private LongLiteral(Optional<NodeLocation> location, String value)
{
    super(location);
    requireNonNull(value, "value is null");
    try {
        this.value = Long.parseLong(value);
    }
    catch (NumberFormatException e) {
        throw new ParsingException("Invalid numeric literal: " + value);
    }
}
项目:presto    文件:GenericLiteral.java   
private GenericLiteral(Optional<NodeLocation> location, String type, String value)
{
    super(location);
    requireNonNull(type, "type is null");
    requireNonNull(value, "value is null");
    if (type.equalsIgnoreCase("X")) {
        // we explicitly disallow "X" as type name, so if the user arrived here,
        // it must be because that he intended to give a binaryLiteral instead, but
        // added whitespace between the X and quote
        throw new ParsingException("Spaces are not allowed between 'X' and the starting quote of a binary literal", location.get());
    }
    this.type = type;
    this.value = value;
}
项目:presto    文件:TreeAssertions.java   
private static Statement parseFormatted(SqlParser sqlParser, String sql, Node tree)
{
    try {
        return sqlParser.createStatement(sql);
    }
    catch (ParsingException e) {
        throw new AssertionError(format(
                "failed to parse formatted SQL: %s\nerror: %s\ntree: %s",
                sql, e.getMessage(), tree));
    }
}
项目:presto    文件:SqlQueryManager.java   
@Override
public QueryInfo createQuery(Session session, String query)
{
    requireNonNull(query, "query is null");
    checkArgument(!query.isEmpty(), "query must not be empty string");

    QueryId queryId = session.getQueryId();

    QueryExecution queryExecution;
    try {
        Statement statement = sqlParser.createStatement(query);
        QueryExecutionFactory<?> queryExecutionFactory = executionFactories.get(statement.getClass());
        if (queryExecutionFactory == null) {
            throw new PrestoException(NOT_SUPPORTED, "Unsupported statement type: " + statement.getClass().getSimpleName());
        }
        queryExecution = queryExecutionFactory.createQueryExecution(queryId, query, session, statement);
    }
    catch (ParsingException | PrestoException e) {
        // This is intentionally not a method, since after the state change listener is registered
        // it's not safe to do any of this, and we had bugs before where people reused this code in a method
        URI self = locationFactory.createQueryLocation(queryId);
        QueryExecution execution = new FailedQueryExecution(queryId, query, session, self, transactionManager, queryExecutor, e);

        queries.put(queryId, execution);
        queryMonitor.createdEvent(execution.getQueryInfo());
        queryMonitor.completionEvent(execution.getQueryInfo());
        stats.queryFinished(execution.getQueryInfo());
        expirationQueue.add(execution);

        return execution.getQueryInfo();
    }

    queryMonitor.createdEvent(queryExecution.getQueryInfo());

    queryExecution.addStateChangeListener(newValue -> {
        if (newValue.isDone()) {
            QueryInfo info = queryExecution.getQueryInfo();

            stats.queryFinished(info);
            queryMonitor.completionEvent(info);
            expirationQueue.add(queryExecution);
        }
    });

    queries.put(queryId, queryExecution);

    // start the query in the background
    if (!queueManager.submit(queryExecution, queryExecutor, stats)) {
        queryExecution.fail(new PrestoException(QUERY_QUEUE_FULL, "Too many queued queries!"));
    }

    return queryExecution.getQueryInfo();
}