def test_where(self): table = self.lineitem q = table.l_quantity expr = api.where(table.l_discount > 0, q * table.l_discount, api.null) assert isinstance(expr, ir.DecimalArray) expr = api.where(table.l_discount > 0, (q * table.l_discount).sum(), api.null) assert isinstance(expr, ir.DecimalArray) expr = api.where(table.l_discount.sum() > 0, (q * table.l_discount).sum(), api.null) assert isinstance(expr, ir.DecimalScalar)
def test_where(lineitem): table = lineitem q = table.l_quantity expr = api.where(table.l_discount > 0, q * table.l_discount, api.null()) assert isinstance(expr, ir.DecimalColumn) expr = api.where(table.l_discount > 0, (q * table.l_discount).sum(), api.null()) assert isinstance(expr, ir.DecimalColumn) expr = api.where(table.l_discount.sum() > 0, (q * table.l_discount).sum(), api.null()) assert isinstance(expr, ir.DecimalScalar)
def test_where(lineitem): table = lineitem q = table.l_quantity expr = api.where(table.l_discount > 0, q * table.l_discount, api.null()) assert isinstance(expr, ir.DecimalColumn) expr = api.where( table.l_discount > 0, (q * table.l_discount).sum(), api.null() ) assert isinstance(expr, ir.DecimalColumn) expr = api.where( table.l_discount.sum() > 0, (q * table.l_discount).sum(), api.null() ) assert isinstance(expr, ir.DecimalScalar)
def test_decimal_timestamp_builtins(self): table = self.con.table('tpch_lineitem') dc = table.l_quantity ts = table.l_receiptdate.cast('timestamp') exprs = [ dc % 10, dc + 5, dc + dc, dc / 2, dc * 2, dc ** 2, dc.cast('double'), api.where(table.l_discount > 0, dc * table.l_discount, api.NA), dc.fillna(0), ts < (ibis.now() + ibis.month(3)), ts < (ibis.timestamp('2005-01-01') + ibis.month(3)), # hashing dc.hash(), ts.hash(), # truncate ts.truncate('y'), ts.truncate('q'), ts.truncate('month'), ts.truncate('d'), ts.truncate('w'), ts.truncate('h'), ts.truncate('minute'), ] timestamp_fields = ['year', 'month', 'day', 'hour', 'minute', 'second', 'millisecond', 'microsecond', 'week'] for field in timestamp_fields: if hasattr(ts, field): exprs.append(getattr(ts, field)()) offset = getattr(ibis, field)(2) exprs.append(ts + offset) exprs.append(ts - offset) proj_exprs = [expr.name('e%d' % i) for i, expr in enumerate(exprs)] projection = table[proj_exprs].limit(10) projection.execute()
def test_decimal_timestamp_builtins(self): table = self.con.table("tpch_lineitem") dc = table.l_quantity ts = table.l_receiptdate.cast("timestamp") exprs = [ dc % 10, dc + 5, dc + dc, dc / 2, dc * 2, dc ** 2, dc.cast("double"), api.where(table.l_discount > 0, dc * table.l_discount, api.NA), dc.fillna(0), ts < (ibis.now() + ibis.month(3)), ts < (ibis.timestamp("2005-01-01") + ibis.month(3)), # hashing dc.hash(), ts.hash(), # truncate ts.truncate("y"), ts.truncate("q"), ts.truncate("month"), ts.truncate("d"), ts.truncate("w"), ts.truncate("h"), ts.truncate("minute"), ] timestamp_fields = ["year", "month", "day", "hour", "minute", "second", "millisecond", "microsecond", "week"] for field in timestamp_fields: if hasattr(ts, field): exprs.append(getattr(ts, field)()) offset = getattr(ibis, field)(2) exprs.append(ts + offset) exprs.append(ts - offset) proj_exprs = [expr.name("e%d" % i) for i, expr in enumerate(exprs)] projection = table[proj_exprs].limit(10) projection.execute()