Skip to content

Commit 0573705

Browse files
author
boonhapus
committed
Merge branch 'dev'
2 parents 16a0fab + 011c470 commit 0573705

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

cs_tools/__project__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "1.5.11"
1+
__version__ = "1.5.12"
22
__docs__ = "https://thoughtspot.github.io/cs_tools/"
33
__repo__ = "https://github.com/thoughtspot/cs_tools"
44
__help__ = f"{__repo__}/discussions/"

cs_tools/sync/sqlite/syncer.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
import pathlib
77

8+
from sqlalchemy.dialects.sqlite import insert
89
import pydantic
910
import sqlalchemy as sa
1011

@@ -40,6 +41,21 @@ def __init__(self, **kwargs):
4041
def __repr__(self):
4142
return f"<SQLiteSyncer conn_string='{self.engine.url}'>"
4243

44+
def insert_on_conflict(self, data: TableRows, *, table: sa.Table) -> Union[sa.Insert, sa.Update]:
45+
"""UPSERT."""
46+
stmt = insert(table).values(data)
47+
48+
if table.columns == table.primary_key:
49+
set_ = {c.key: getattr(stmt.excluded, c.key) for c in table.columns}
50+
else:
51+
set_ = {c.key: getattr(stmt.excluded, c.key) for c in table.columns if c.key not in table.primary_key}
52+
53+
stmt = stmt.on_conflict_do_update(
54+
index_elements=table.primary_key,
55+
set_=set_,
56+
)
57+
return stmt
58+
4359
# @contextlib.contextmanager
4460
# def pragma_speedy_insert(self):
4561
# """ """
@@ -91,6 +107,12 @@ def dump(self, tablename: str, *, data: TableRows) -> None:
91107
)
92108

93109
if self.load_strategy == "UPSERT":
94-
sync_utils.generic_upsert(table, session=self.session, data=data)
110+
sync_utils.batched(
111+
self.insert_on_conflict,
112+
session=self.session,
113+
data=data,
114+
max_parameters=const.SQLITE_MAX_VARIABLES,
115+
table=table,
116+
)
95117

96118
self.session.commit()

cs_tools/sync/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def format_datetime_values(row: dict[str, Any], *, dt_format: str = DATETIME_FOR
5050
return out
5151

5252

53-
def batched(prepared_statement, *, session: sa.orm.Session, data: TableRows, max_parameters: int = 999) -> None:
53+
def batched(prepared_statement, *, session: sa.orm.Session, data: TableRows, max_parameters: int = 999, **kw) -> None:
5454
"""Split data across multiple transactions."""
5555
batchsize = min(5000, max_parameters // len(data[0]))
5656
rows = []
@@ -60,14 +60,14 @@ def batched(prepared_statement, *, session: sa.orm.Session, data: TableRows, max
6060

6161
# Commit every so often.
6262
if row_number % batchsize == 0:
63-
stmt = prepared_statement(rows)
63+
stmt = prepared_statement(rows, **kw)
6464
session.execute(stmt)
6565
session.commit()
6666
rows = []
6767

6868
# Final commit, grab the rest of the data rows.
6969
if rows:
70-
stmt = prepared_statement(rows)
70+
stmt = prepared_statement(rows, **kw)
7171
session.execute(stmt)
7272
session.commit()
7373

cs_tools/updater/_updater.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def pip(self, command: str, *args, with_system_python: bool = False, **kwargs) -
195195
# don't ping pypi for new versions of pip -- it doesn't matter and is noisy
196196
"--disable-pip-version-check",
197197
# trust installs from the official python package index and the thoughtspot github repos
198-
"--trusted-host", "files.pythonhost.org",
198+
"--trusted-host", "files.pythonhosted.org",
199199
"--trusted-host", "pypi.org",
200200
"--trusted-host", "pypi.python.org",
201201
"--trusted-host", "github.com",

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ dependencies = [
3939
"thoughtspot_tml",
4040
"awesomeversion",
4141
"httpx >= 0.27.0",
42-
"pydantic >= 2.6.4",
4342
"pydantic-settings",
4443
"email-validator",
4544
"pendulum >= 3.0.0",
@@ -48,6 +47,9 @@ dependencies = [
4847
"toml",
4948
"packaging",
5049

50+
# TODO: https://github.com/pydantic/pydantic/issues/10910
51+
"pydantic == 2.9.2",
52+
5153
# TODO: https://github.com/thoughtspot/thoughtspot_tml/issues/24
5254
"betterproto[compiler] == 2.0.0b6",
5355

0 commit comments

Comments
 (0)