utils.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:clickhouse-cli 作者: hatarist 项目源码 文件源码
def parse_partial_identifier(word):
    """
    Attempt to parse a (partially typed) word as an identifier.

    word may include a schema qualification, like `schema_name.partial_name`
    or `schema_name.` There may also be unclosed quotation marks, like
    `"schema` or `schema."partial_name`.

    :param word: string representing a (partially complete) identifier
    :return: sqlparse.sql.Identifier, or None
    """

    p = sqlparse.parse(word)[0]
    n_tok = len(p.tokens)
    if n_tok == 1 and isinstance(p.tokens[0], Identifier):
        return p.tokens[0]
    elif p.token_next_by(m=(Error, '"'))[1]:
        # An unmatched double quote, e.g. '"foo', 'foo."', or 'foo."bar'
        # Close the double quote, then reparse
        return parse_partial_identifier(word + '"')
    else:
        return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号