acryl-datahub 0.15.0rc21__py3-none-any.whl → 0.15.0rc23__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of acryl-datahub might be problematic. Click here for more details.

@@ -1,6 +1,7 @@
1
1
  import collections
2
2
  import gzip
3
3
  import logging
4
+ import os
4
5
  import pathlib
5
6
  import pickle
6
7
  import shutil
@@ -33,6 +34,14 @@ from datahub.ingestion.api.closeable import Closeable
33
34
 
34
35
  logger: logging.Logger = logging.getLogger(__name__)
35
36
 
37
+ OVERRIDE_SQLITE_VERSION_REQUIREMENT_STR = (
38
+ os.environ.get("OVERRIDE_SQLITE_VERSION_REQ") or ""
39
+ )
40
+ OVERRIDE_SQLITE_VERSION_REQUIREMENT = (
41
+ OVERRIDE_SQLITE_VERSION_REQUIREMENT_STR
42
+ and OVERRIDE_SQLITE_VERSION_REQUIREMENT_STR.lower() != "false"
43
+ )
44
+
36
45
  _DEFAULT_FILE_NAME = "sqlite.db"
37
46
  _DEFAULT_TABLE_NAME = "data"
38
47
 
@@ -212,6 +221,7 @@ class FileBackedDict(MutableMapping[str, _VT], Closeable, Generic[_VT]):
212
221
  _active_object_cache: OrderedDict[str, Tuple[_VT, bool]] = field(
213
222
  init=False, repr=False
214
223
  )
224
+ _use_sqlite_on_conflict: bool = field(repr=False, default=True)
215
225
 
216
226
  def __post_init__(self) -> None:
217
227
  assert (
@@ -232,7 +242,10 @@ class FileBackedDict(MutableMapping[str, _VT], Closeable, Generic[_VT]):
232
242
  # We use the ON CONFLICT clause to implement UPSERTs with sqlite.
233
243
  # This was added in 3.24.0 from 2018-06-04.
234
244
  # See https://www.sqlite.org/lang_conflict.html
235
- raise RuntimeError("SQLite version 3.24.0 or later is required")
245
+ if OVERRIDE_SQLITE_VERSION_REQUIREMENT:
246
+ self.use_sqlite_on_conflict = False
247
+ else:
248
+ raise RuntimeError("SQLite version 3.24.0 or later is required")
236
249
 
237
250
  # We keep a small cache in memory to avoid having to serialize/deserialize
238
251
  # data from the database too often. We use an OrderedDict to build
@@ -295,7 +308,7 @@ class FileBackedDict(MutableMapping[str, _VT], Closeable, Generic[_VT]):
295
308
  values.append(column_serializer(value))
296
309
  items_to_write.append(tuple(values))
297
310
 
298
- if items_to_write:
311
+ if items_to_write and self._use_sqlite_on_conflict:
299
312
  # Tricky: By using a INSERT INTO ... ON CONFLICT (key) structure, we can
300
313
  # ensure that the rowid remains the same if a value is updated but is
301
314
  # autoincremented when rows are inserted.
@@ -312,6 +325,26 @@ class FileBackedDict(MutableMapping[str, _VT], Closeable, Generic[_VT]):
312
325
  """,
313
326
  items_to_write,
314
327
  )
328
+ else:
329
+ for item in items_to_write:
330
+ try:
331
+ self._conn.execute(
332
+ f"""INSERT INTO {self.tablename} (
333
+ key,
334
+ value
335
+ {''.join(f', {column_name}' for column_name in self.extra_columns.keys())}
336
+ )
337
+ VALUES ({', '.join(['?'] *(2 + len(self.extra_columns)))})""",
338
+ item,
339
+ )
340
+ except sqlite3.IntegrityError:
341
+ self._conn.execute(
342
+ f"""UPDATE {self.tablename} SET
343
+ value = ?
344
+ {''.join(f', {column_name} = ?' for column_name in self.extra_columns.keys())}
345
+ WHERE key = ?""",
346
+ (*item[1:], item[0]),
347
+ )
315
348
 
316
349
  def flush(self) -> None:
317
350
  self._prune_cache(len(self._active_object_cache))