Exemplo n.º 1
0
    def test_decimal_builtins_2(self):
        d = L('5.245')
        dc = d.cast('decimal(12,5)')
        cases = [(dc % 5, Decimal('0.245')), (dc.fillna(0), Decimal('5.245')),
                 (dc.exp(), 189.6158), (dc.log(), 1.65728),
                 (dc.log2(), 2.39094), (dc.log10(), 0.71975),
                 (dc.sqrt(), 2.29019), (dc.zeroifnull(), Decimal('5.245')),
                 (-dc, Decimal('-5.245'))]

        for expr, expected in cases:
            result = self.con.execute(expr)
            if isinstance(expected, Decimal):
                tol = Decimal('0.0001')
            else:
                tol = 0.0001
            approx_equal(result, expected, tol)
Exemplo n.º 2
0
 def test_decimal_builtins(self):
     d = L(5.245)
     general_cases = [
         (L(-5).abs(), 5),
         (d.cast('int32'), 5),
         (d.ceil(), 6),
         (d.isnull(), False),
         (d.floor(), 5),
         (d.notnull(), True),
         (d.round(), 5),
         (d.round(2), Decimal('5.25')),
         (d.sign(), 1),
     ]
     self.assert_cases_equality(general_cases)
Exemplo n.º 3
0
    def test_decimal(self):
        col = self.con.table('tpch_customer').c_acctbal
        literal = ibis.literal(1).cast('decimal(12,2)')
        name = '__tmp_udf_' + util.guid()
        func = self._udf_creation_to_op(name, 'Identity', ['decimal(12,2)'],
                                        'decimal(12,2)')

        expr = func(literal)
        assert issubclass(type(expr), ir.ScalarExpr)
        result = self.con.execute(expr)
        assert result == Decimal(1)

        expr = func(col)
        assert issubclass(type(expr), ir.ArrayExpr)
        self.con.execute(expr)
Exemplo n.º 4
0
def test_decimal(udfcon, test_data_db, udf_ll):
    col = udfcon.table('tpch_customer').c_acctbal
    literal = ibis.literal(1).cast('decimal(12,2)')
    name = '__tmp_udf_' + util.guid()

    func = udf_creation_to_op(
        udf_ll, udfcon, test_data_db, name, 'Identity',
        ['decimal(12,2)'], 'decimal(12,2)')

    expr = func(literal)
    assert issubclass(type(expr), ir.ScalarExpr)
    result = udfcon.execute(expr)
    assert result == Decimal(1)

    expr = func(col)
    assert issubclass(type(expr), ir.ColumnExpr)
    udfcon.execute(expr)
Exemplo n.º 5
0
def test_timestamp_builtins(con, expr, expected):
    result = con.execute(expr)
    assert result == expected, to_sql(expr)


@pytest.mark.parametrize(
    ('expr', 'expected'),
    [
        (L(-5).abs(), 5),
        (L(5.245).cast('int32'), 5),
        (L(5.245).ceil(), 6),
        (L(5.245).isnull(), False),
        (L(5.245).floor(), 5),
        (L(5.245).notnull(), True),
        (L(5.245).round(), 5),
        (L(5.245).round(2), Decimal('5.25')),
        (L(5.245).sign(), 1),
    ]
)
def test_decimal_builtins(con, expr, expected):
    result = con.execute(expr)
    assert result == expected, to_sql(expr)


def test_decimal_builtins_2(con):
    d = L('5.245')
    dc = d.cast('decimal(12, 5)')
    cases = [
        (dc % 5, 0.245),

        (dc.fillna(0), 5.245),