Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 1b99100

Browse files
author
Sergey Vasilyev
committed
Remove unused code: time travelling
1 parent b3084cc commit 1b99100

File tree

5 files changed

+3
-123
lines changed

5 files changed

+3
-123
lines changed

data_diff/abcs/mixins.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -141,29 +141,6 @@ def list_tables(self, table_schema: str, like: Compilable = None) -> Compilable:
141141
"""
142142

143143

144-
@attrs.define(frozen=False)
145-
class AbstractMixin_TimeTravel(AbstractMixin):
146-
@abstractmethod
147-
def time_travel(
148-
self,
149-
table: Compilable,
150-
before: bool = False,
151-
timestamp: Compilable = None,
152-
offset: Compilable = None,
153-
statement: Compilable = None,
154-
) -> Compilable:
155-
"""Selects historical data from a table
156-
157-
Parameters:
158-
table - The name of the table whose history we're querying
159-
timestamp - A constant timestamp
160-
offset - the time 'offset' seconds before now
161-
statement - identifier for statement, e.g. query ID
162-
163-
Must specify exactly one of `timestamp`, `offset` or `statement`.
164-
"""
165-
166-
167144
@attrs.define(frozen=False)
168145
class AbstractMixin_OptimizerHints(AbstractMixin):
169146
@abstractmethod

data_diff/databases/base.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
TableAlias,
4949
TableOp,
5050
TablePath,
51-
TimeTravel,
5251
TruncateTable,
5352
UnaryOp,
5453
WhenThen,
@@ -74,7 +73,7 @@
7473
Boolean,
7574
JSON,
7675
)
77-
from data_diff.abcs.mixins import AbstractMixin_TimeTravel, Compilable
76+
from data_diff.abcs.mixins import Compilable
7877
from data_diff.abcs.mixins import (
7978
AbstractMixin_Schema,
8079
AbstractMixin_NormalizeValue,
@@ -327,8 +326,6 @@ def render_compilable(self, c: Compiler, elem: Compilable) -> str:
327326
return self.render_explain(c, elem)
328327
elif isinstance(elem, CurrentTimestamp):
329328
return self.render_currenttimestamp(c, elem)
330-
elif isinstance(elem, TimeTravel):
331-
return self.render_timetravel(c, elem)
332329
elif isinstance(elem, CreateTable):
333330
return self.render_createtable(c, elem)
334331
elif isinstance(elem, DropTable):
@@ -605,16 +602,6 @@ def render_explain(self, c: Compiler, elem: Explain) -> str:
605602
def render_currenttimestamp(self, c: Compiler, elem: CurrentTimestamp) -> str:
606603
return self.current_timestamp()
607604

608-
def render_timetravel(self, c: Compiler, elem: TimeTravel) -> str:
609-
assert isinstance(c, AbstractMixin_TimeTravel)
610-
return self.compile(
611-
c,
612-
# TODO: why is it c.? why not self? time-trvelling is the dialect's thing, isnt't it?
613-
c.time_travel(
614-
elem.table, before=elem.before, timestamp=elem.timestamp, offset=elem.offset, statement=elem.statement
615-
),
616-
)
617-
618605
def render_createtable(self, c: Compiler, elem: CreateTable) -> str:
619606
ne = "IF NOT EXISTS " if elem.if_not_exists else ""
620607
if elem.source_table:

data_diff/databases/bigquery.py

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
AbstractMixin_MD5,
2525
AbstractMixin_NormalizeValue,
2626
AbstractMixin_Schema,
27-
AbstractMixin_TimeTravel,
2827
)
2928
from data_diff.abcs.compiler import Compilable
3029
from data_diff.queries.api import this, table, SKIP, code
@@ -63,9 +62,7 @@ def import_bigquery_service_account_impersonation():
6362

6463

6564
@attrs.define(frozen=False)
66-
class Dialect(
67-
BaseDialect, AbstractMixin_Schema, AbstractMixin_MD5, AbstractMixin_NormalizeValue, AbstractMixin_TimeTravel
68-
):
65+
class Dialect(BaseDialect, AbstractMixin_Schema, AbstractMixin_MD5, AbstractMixin_NormalizeValue):
6966
name = "BigQuery"
7067
ROUNDS_ON_PREC_LOSS = False # Technically BigQuery doesn't allow implicit rounding or truncation
7168
TYPE_CLASSES = {
@@ -197,31 +194,6 @@ def list_tables(self, table_schema: str, like: Compilable = None) -> Compilable:
197194
.select(this.table_name)
198195
)
199196

200-
def time_travel(
201-
self,
202-
table: Compilable,
203-
before: bool = False,
204-
timestamp: Compilable = None,
205-
offset: Compilable = None,
206-
statement: Compilable = None,
207-
) -> Compilable:
208-
if before:
209-
raise NotImplementedError("before=True not supported for BigQuery time-travel")
210-
211-
if statement is not None:
212-
raise NotImplementedError("BigQuery time-travel doesn't support querying by statement id")
213-
214-
if timestamp is not None:
215-
assert offset is None
216-
return code("{table} FOR SYSTEM_TIME AS OF {timestamp}", table=table, timestamp=timestamp)
217-
218-
assert offset is not None
219-
return code(
220-
"{table} FOR SYSTEM_TIME AS OF TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL {offset} HOUR);",
221-
table=table,
222-
offset=offset,
223-
)
224-
225197

226198
@attrs.define(frozen=False, init=False, kw_only=True)
227199
class BigQuery(Database):

data_diff/databases/snowflake.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
AbstractMixin_MD5,
2020
AbstractMixin_NormalizeValue,
2121
AbstractMixin_Schema,
22-
AbstractMixin_TimeTravel,
2322
)
2423
from data_diff.abcs.compiler import Compilable
2524
from data_diff.queries.api import table, this, SKIP, code
@@ -43,9 +42,7 @@ def import_snowflake():
4342
return snowflake, serialization, default_backend
4443

4544

46-
class Dialect(
47-
BaseDialect, AbstractMixin_Schema, AbstractMixin_MD5, AbstractMixin_NormalizeValue, AbstractMixin_TimeTravel
48-
):
45+
class Dialect(BaseDialect, AbstractMixin_Schema, AbstractMixin_MD5, AbstractMixin_NormalizeValue):
4946
name = "Snowflake"
5047
ROUNDS_ON_PREC_LOSS = False
5148
TYPE_CLASSES = {
@@ -117,30 +114,6 @@ def list_tables(self, table_schema: str, like: Compilable = None) -> Compilable:
117114
.select(table_name=this.TABLE_NAME)
118115
)
119116

120-
def time_travel(
121-
self,
122-
table: Compilable,
123-
before: bool = False,
124-
timestamp: Compilable = None,
125-
offset: Compilable = None,
126-
statement: Compilable = None,
127-
) -> Compilable:
128-
at_or_before = "AT" if before else "BEFORE"
129-
if timestamp is not None:
130-
assert offset is None and statement is None
131-
key = "timestamp"
132-
value = timestamp
133-
elif offset is not None:
134-
assert statement is None
135-
key = "offset"
136-
value = offset
137-
else:
138-
assert statement is not None
139-
key = "statement"
140-
value = statement
141-
142-
return code(f"{{table}} {at_or_before}({key} => {{value}})", table=table, value=value)
143-
144117

145118
@attrs.define(frozen=False, init=False, kw_only=True)
146119
class Snowflake(Database):

data_diff/queries/ast_classes.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -457,26 +457,6 @@ def insert_expr(self, expr: Expr):
457457
expr = expr.select()
458458
return InsertToTable(self, expr)
459459

460-
def time_travel(
461-
self, *, before: bool = False, timestamp: datetime = None, offset: int = None, statement: str = None
462-
) -> Compilable:
463-
"""Selects historical data from the table
464-
465-
Parameters:
466-
before: If false, inclusive of the specified point in time.
467-
If True, only return the time before it. (at/before)
468-
timestamp: A constant timestamp
469-
offset: the time 'offset' seconds before now
470-
statement: identifier for statement, e.g. query ID
471-
472-
Must specify exactly one of `timestamp`, `offset` or `statement`.
473-
"""
474-
if sum(int(i is not None) for i in (timestamp, offset, statement)) != 1:
475-
raise ValueError("Must specify exactly one of `timestamp`, `offset` or `statement`.")
476-
477-
if timestamp is not None:
478-
assert offset is None and statement is None
479-
480460

481461
@attrs.define(frozen=True, eq=False)
482462
class TableAlias(ExprNode, ITable):
@@ -752,15 +732,6 @@ def type(self) -> Optional[type]:
752732
return datetime
753733

754734

755-
@attrs.define(frozen=True, eq=False)
756-
class TimeTravel(ITable): # TODO: Unused?
757-
table: TablePath
758-
before: bool = False
759-
timestamp: Optional[datetime] = None
760-
offset: Optional[int] = None
761-
statement: Optional[str] = None
762-
763-
764735
# DDL
765736

766737

0 commit comments

Comments
 (0)