Beispiel #1
0
    def test_where_parenthesis(self, test_arrow_table,
                               test_table_column_names):
        sql = ("select * from tbl "
               "where (lat > 2.0 and 15 <= total) or tip = 12")
        query_ast = create_query_ast(sql, test_arrow_table)

        self._test_select_exprs(query_ast, len(test_table_column_names))
        self._test_expression(query_ast.where_condition, SQLOperator.OR, 2)

        left_arg = query_ast.where_condition.arguments[0]
        self._test_expression(left_arg, SQLOperator.AND, 2)

        nested_left = left_arg.arguments[0]
        self._test_expression(nested_left, SQLOperator.GREATER_THAN, 2)
        _test_column(nested_left.arguments[0], 'lat')
        _test_literal(nested_left.arguments[1], 2.0)

        nested_right = left_arg.arguments[1]
        self._test_expression(nested_right, SQLOperator.LESS_THAN_OR_EQUAL, 2)
        _test_literal(nested_right.arguments[0], 15)
        _test_column(nested_right.arguments[1], 'total')

        right_arg = query_ast.where_condition.arguments[1]
        self._test_expression(right_arg, SQLOperator.EQUALS, 2)
        _test_column(right_arg.arguments[0], 'tip')
        _test_literal(right_arg.arguments[1], 12)
Beispiel #2
0
    def test_literal_alias(self, test_arrow_table):
        query = "select 2 as alias from tbl"
        query_ast = create_query_ast(query, test_arrow_table)

        self._test_select_exprs(query_ast, 1)
        _test_literal(query_ast.select_expressions[0], 2, 'alias')

        assert query_ast.where_condition is None
Beispiel #3
0
    def test_where_like_operators(self, test_arrow_table, query, sql_operator,
                                  args):
        query_ast = create_query_ast(query, test_arrow_table)

        assert query_ast is not None

        expr = query_ast.where_condition
        self._test_expression(expr, sql_operator, 2)
        _test_column(expr.arguments[0], 'tip')
        assert expr.arguments[1].value == args
Beispiel #4
0
    def test_unary_sql_operators(self, test_arrow_table, query, sql_operator):
        query_ast = create_query_ast(query, test_arrow_table)

        self._test_select_exprs(query_ast, 1)

        expr = query_ast.select_expressions[0]
        self._test_expression(expr, sql_operator, 1)
        _test_column(expr.arguments[0], 'tip')

        assert query_ast.where_condition is None
Beispiel #5
0
    def test_select_distinct(self, test_arrow_table):
        query = "select distinct tax, total, tip from t"
        query_ast = create_query_ast(query, test_arrow_table)

        self._test_select_exprs(query_ast, 3)

        _test_column(query_ast.select_expressions[0], 'tax')
        _test_column(query_ast.select_expressions[1], 'total')
        _test_column(query_ast.select_expressions[2], 'tip')

        assert query_ast.distinct is not None
        assert isinstance(query_ast.distinct, bool)
        assert query_ast.distinct

        assert query_ast.where_condition is None
Beispiel #6
0
    def test_where(self, test_arrow_table, test_table_column_names):
        query = "select * from tbl where vendor_id > 1 and lat < 4.5"
        query_ast = create_query_ast(query, test_arrow_table)

        self._test_select_exprs(query_ast, len(test_table_column_names))
        self._test_expression(query_ast.where_condition, SQLOperator.AND, 2)

        left_expr = query_ast.where_condition.arguments[0]
        self._test_expression(left_expr, SQLOperator.GREATER_THAN, 2)
        _test_column(left_expr.arguments[0], 'vendor_id')
        _test_literal(left_expr.arguments[1], 1)

        right_expr = query_ast.where_condition.arguments[1]
        self._test_expression(right_expr, SQLOperator.LESS_THAN, 2)
        _test_column(right_expr.arguments[0], 'lat')
        _test_literal(right_expr.arguments[1], 4.5)
Beispiel #7
0
    def test_expression_alias(self, test_arrow_table):
        query = "select to_int(np.sqrt(total)) as sqrt from t"
        query_ast = create_query_ast(query, test_arrow_table)

        self._test_select_exprs(query_ast, 1)

        self._test_expression(query_ast.select_expressions[0],
                              SQLOperator.FUNCTION,
                              1,
                              function_name='to_int',
                              alias='sqrt')
        nested_expr = query_ast.select_expressions[0].arguments[0]
        self._test_expression(nested_expr,
                              SQLOperator.FUNCTION,
                              1,
                              function_name='np.sqrt')
        _test_column(nested_expr.arguments[0], 'total')

        assert query_ast.where_condition is None
Beispiel #8
0
    def test_select_all_and_expressions(self, test_arrow_table,
                                        test_table_column_names):
        query = "select *, np.log(tip) * 17, total - tax from t"
        query_ast = create_query_ast(query, test_arrow_table)

        self._test_select_exprs(query_ast, len(test_table_column_names) + 2)

        expr = query_ast.select_expressions[-2]
        self._test_expression(expr, SQLOperator.MULTIPLICATION, 2)
        args = expr.arguments
        self._test_expression(args[0],
                              SQLOperator.FUNCTION,
                              1,
                              function_name='np.log')
        _test_column(args[0].arguments[0], 'tip')
        _test_literal(args[1], 17)

        expr = query_ast.select_expressions[-1]
        self._test_expression(expr, SQLOperator.SUBTRACTION, 2)
        args = expr.arguments
        _test_column(args[0], 'total')
        _test_column(args[1], 'tax')

        assert query_ast.where_condition is None