Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

Add timediff as another time operationr function #92

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ibis_bigquery/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ def _formatter(translator, expr):
ops.Time: unary("TIME"),
ops.TimestampAdd: _timestamp_op("TIMESTAMP_ADD", {"h", "m", "s", "ms", "us"}),
ops.TimestampSub: _timestamp_op("TIMESTAMP_SUB", {"h", "m", "s", "ms", "us"}),
ops.TimestampDiff: _timestamp_op('TIME_DIFF', {'h', 'm', 's', 'ms', 'us'}),
ops.DateAdd: _timestamp_op("DATE_ADD", {"D", "W", "M", "Q", "Y"}),
ops.DateSub: _timestamp_op("DATE_SUB", {"D", "W", "M", "Q", "Y"}),
ops.TimestampNow: fixed_arity("CURRENT_TIMESTAMP", 0),
Expand Down
15 changes: 15 additions & 0 deletions tests/system/test_compiler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ibis
import ibis.expr.datatypes as dt
import ibis.expr.api as api
import packaging.version
import pytest

Expand Down Expand Up @@ -36,6 +37,20 @@ def test_union(alltypes, distinct, expected_keyword, project_id):
assert result == expected


@pytest.mark.parametrize(
('distinct', 'expected_keyword'), [(True, 'DISTINCT'), (False, 'ALL')]
'operand', [lambda t: api.time('18:00'), lambda t: t.k]
)
@pytest.mark.parametrize('unit', ['h', 'm', 's', 'ms', 'us', 'ns'])
def test_timestamp_timediff(operand, unit):
# import pytest;
# pytest.set_trace()
table = ibis.table([('c', 'timestamp')], name='t')
expr = operand(table).timediff(unit)
# assert isinstance(expr, ir.TimeValue)
# assert isinstance(expr.op(), ops.TimestampDiff)


def test_ieee_divide(alltypes, project_id):
expr = alltypes.double_col / 0
result = expr.compile()
Expand Down