• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

georgia-tech-db / eva / #758

04 Sep 2023 08:37PM UTC coverage: 0.0% (-78.3%) from 78.333%
#758

push

circle-ci

hershd23
Increased underline length in at line 75 in text_summarization.rst
	modified:   docs/source/benchmarks/text_summarization.rst

0 of 11303 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/evadb/catalog/sql_config.py
1
# coding=utf-8
2
# Copyright 2018-2023 EvaDB
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
from threading import Lock
×
16
from weakref import WeakValueDictionary
×
17

18
from sqlalchemy import create_engine, event
×
19
from sqlalchemy.orm import scoped_session, sessionmaker
×
20
from sqlalchemy.pool import NullPool
×
21

22
from evadb.utils.generic_utils import is_postgres_uri, parse_config_yml
×
23

24
IDENTIFIER_COLUMN = "_row_id"
×
25

26
CATALOG_TABLES = [
×
27
    "column_catalog",
28
    "table_catalog",
29
    "database_catalog",
30
    "depend_column_and_udf_cache",
31
    "udf_cache",
32
    "udf_catalog",
33
    "depend_udf_and_udf_cache",
34
    "index_catalog",
35
    "udfio_catalog",
36
    "udf_cost_catalog",
37
    "udf_metadata_catalog",
38
]
39

40

41
class SingletonMeta(type):
×
42
    """
43
    This is a thread-safe implementation of Singleton.
44
    """
45

46
    _instances = WeakValueDictionary()
×
47
    _lock: Lock = Lock()
×
48

49
    def __call__(cls, uri):
×
50
        key = (cls, uri)
×
51
        with cls._lock:
×
52
            if key not in cls._instances:
×
53
                instance = super().__call__(uri)
×
54
                cls._instances[key] = instance
×
55
        return cls._instances[key]
×
56

57

58
class SQLConfig(metaclass=SingletonMeta):
×
59
    def __init__(self, uri):
×
60
        """Initializes the engine and session for database operations
61

62
        Retrieves the database uri for connection from ConfigurationManager.
63
        """
64

65
        self.worker_uri = str(uri)
×
66
        # set echo=True to log SQL
67

68
        connect_args = {}
×
69
        config_obj = parse_config_yml()
×
70
        if is_postgres_uri(config_obj["core"]["catalog_database_uri"]):
×
71
            # Set the arguments for postgres backend.
72
            connect_args = {"connect_timeout": 1000}
×
73
            # https://www.oddbird.net/2014/06/14/sqlalchemy-postgres-autocommit/
74
            self.engine = create_engine(
×
75
                self.worker_uri,
76
                poolclass=NullPool,
77
                isolation_level="AUTOCOMMIT",
78
                connect_args=connect_args,
79
            )
80
        else:
81
            # Default to SQLite.
82
            connect_args = {"timeout": 1000}
×
83
            self.engine = create_engine(
×
84
                self.worker_uri,
85
                connect_args=connect_args,
86
            )
87

88
        if self.engine.url.get_backend_name() == "sqlite":
×
89
            # enforce foreign key constraint and wal logging for sqlite
90
            # https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#foreign-key-support
91

92
            def _enable_sqlite_pragma(dbapi_con, con_record):
×
93
                dbapi_con.execute("pragma foreign_keys=ON")
×
94
                dbapi_con.execute("pragma synchronous=NORMAL")
×
95

96
                # disabling WAL for now, we need to fix the catalog operations.
97
                # Currently, there are too many connections being made, which is not an
98
                # optimal design. Ideally, we should implement a connection pool for
99
                # better management.
100
                # dbapi_con.execute("pragma journal_mode=WAL")
101
                # dbapi_con.close()
102

103
            event.listen(self.engine, "connect", _enable_sqlite_pragma)
×
104
        # statements
105
        self.session = scoped_session(sessionmaker(bind=self.engine))
×
106
        self.session.close()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc