예제 #1
0
def _format_query_body(query: Query) -> Mapping[str, Any]:
    expression_formatter = TracingExpressionFormatter()
    formatted = {
        "SELECT": [[e.name, e.expression.accept(expression_formatter)]
                   for e in query.get_selected_columns_from_ast()],
        "GROUPBY":
        [e.accept(expression_formatter) for e in query.get_groupby_from_ast()],
        "ORDERBY": [[e.expression.accept(expression_formatter), e.direction]
                    for e in query.get_orderby_from_ast()],
    }
    array_join = query.get_arrayjoin_from_ast()
    if array_join:
        formatted["ARRAYJOIN"] = array_join.accept(expression_formatter)
    condition = query.get_condition_from_ast()
    if condition:
        formatted["WHERE"] = condition.accept(expression_formatter)
    having = query.get_having_from_ast()
    if having:
        formatted["HAVING"] = having.accept(expression_formatter)
    limitby = query.get_limitby()
    if limitby:
        formatted["LIMITBY"] = {
            "LIMIT": limitby.limit,
            "BY": limitby.expression.accept(expression_formatter),
        }
    limit = query.get_limit()
    if limit:
        formatted["LIMIT"] = limit
    offset = query.get_offset()
    if offset:
        formatted["OFFSET"] = offset
    return formatted
예제 #2
0
def _format_limit(
        query: AbstractQuery,
        formatter: ClickhouseExpressionFormatterBase) -> Optional[StringNode]:
    ast_limit = query.get_limit()
    return (StringNode(f"LIMIT {ast_limit} OFFSET {query.get_offset()}")
            if ast_limit is not None else None)
예제 #3
0
def _format_limit(query: AbstractQuery,
                  formatter: ExpressionVisitor[str]) -> Optional[StringNode]:
    ast_limit = query.get_limit()
    return (StringNode(f"LIMIT {ast_limit} OFFSET {query.get_offset()}")
            if ast_limit is not None else None)