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

Commit ca00b32

Browse files
authored
Merge pull request #101 from datafold/refactor_database
Refactor database.py -> databases/*.py, each db gets a file.
2 parents bcafe20 + 620ca74 commit ca00b32

23 files changed

+1013
-983
lines changed

data_diff/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Tuple, Iterator, Optional, Union
22

3-
from .database import connect_to_uri
3+
from .databases.connect import connect_to_uri
44
from .diff_tables import (
55
TableSegment,
66
TableDiffer,
@@ -9,7 +9,6 @@
99
DbKey,
1010
DbTime,
1111
DbPath,
12-
parse_table_name,
1312
)
1413

1514

@@ -18,10 +17,11 @@ def connect_to_table(
1817
):
1918
"""Connects to a URI and creates a TableSegment instance"""
2019

20+
db = connect_to_uri(db_uri, thread_count=thread_count)
21+
2122
if isinstance(table_name, str):
22-
table_name = parse_table_name(table_name)
23+
table_name = db.parse_table_name(table_name)
2324

24-
db = connect_to_uri(db_uri, thread_count=thread_count)
2525
return TableSegment(db, table_name, key_column, **kwargs)
2626

2727

data_diff/__main__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
TableDiffer,
1010
DEFAULT_BISECTION_THRESHOLD,
1111
DEFAULT_BISECTION_FACTOR,
12-
parse_table_name,
1312
)
14-
from .database import connect_to_uri, parse_table_name
13+
from .databases.connect import connect_to_uri
1514
from .parse_time import parse_time_before_now, UNITS_STR, ParseError
1615

1716
import rich
@@ -51,7 +50,7 @@
5150
@click.option("--max-age", default=None, help="Considers only rows younger than specified. See --min-age.")
5251
@click.option("-s", "--stats", is_flag=True, help="Print stats instead of a detailed diff")
5352
@click.option("-d", "--debug", is_flag=True, help="Print debug info")
54-
@click.option("--json", 'json_output', is_flag=True, help="Print JSONL output for machine readability")
53+
@click.option("--json", "json_output", is_flag=True, help="Print JSONL output for machine readability")
5554
@click.option("-v", "--verbose", is_flag=True, help="Print extra info")
5655
@click.option("-i", "--interactive", is_flag=True, help="Confirm queries, implies --debug")
5756
@click.option("--keep-column-case", is_flag=True, help="Don't use the schema to fix the case of given column names.")
@@ -104,7 +103,7 @@ def main(
104103
try:
105104
threads = int(threads)
106105
except ValueError:
107-
logger.error("Error: threads must be a number, 'auto', or 'serial'.")
106+
logging.error("Error: threads must be a number, 'auto', or 'serial'.")
108107
return
109108
if threads < 1:
110109
logging.error("Error: threads must be >= 1")
@@ -129,8 +128,8 @@ def main(
129128
logging.error("Error while parsing age expression: %s" % e)
130129
return
131130

132-
table1 = TableSegment(db1, parse_table_name(table1_name), key_column, update_column, columns, **options)
133-
table2 = TableSegment(db2, parse_table_name(table2_name), key_column, update_column, columns, **options)
131+
table1 = TableSegment(db1, db1.parse_table_name(table1_name), key_column, update_column, columns, **options)
132+
table2 = TableSegment(db2, db2.parse_table_name(table2_name), key_column, update_column, columns, **options)
134133

135134
differ = TableDiffer(
136135
bisection_factor=bisection_factor,

0 commit comments

Comments
 (0)