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

xzkostyan / clickhouse-sqlalchemy / 6685607456

29 Oct 2023 08:24PM UTC coverage: 85.756% (-0.2%) from 85.952%
6685607456

push

github

web-flow
Merge pull request #268 from Net-Mist/sa-2.0

SQLAlchemy 2.0

48 of 52 new or added lines in 12 files covered. (92.31%)

5 existing lines in 3 files now uncovered.

2342 of 2731 relevant lines covered (85.76%)

19.99 hits per line

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

82.5
/clickhouse_sqlalchemy/sql/schema.py
1
from sqlalchemy import Table as TableBase
16✔
2
from sqlalchemy.sql.base import (
24✔
3
    DialectKWArgs, Immutable
4
)
5
from sqlalchemy.sql.schema import SchemaItem
24✔
6
from sqlalchemy.sql.selectable import FromClause
24✔
7
from sqlalchemy.sql.selectable import Join
24✔
8

9
from clickhouse_sqlalchemy.sql.selectable import Select
24✔
10

11
from . import ddl
24✔
12

13

14
class Table(TableBase):
24✔
15
    def drop(self, bind=None, checkfirst=False, if_exists=False):
24✔
16
        if bind is None:
24✔
NEW
17
            bind = self.bind
×
18
        bind._run_ddl_visitor(ddl.SchemaDropper, self,
24✔
19
                              checkfirst=checkfirst, if_exists=if_exists)
20

21
    def join(self, right, onclause=None, isouter=False, full=False,
24✔
22
             type=None, strictness=None, distribution=None):
23
        flags = {
24✔
24
            'full': full,
25
            'type': type,
26
            'strictness': strictness,
27
            'distribution': distribution
28
        }
29
        return Join(self, right, onclause=onclause, isouter=isouter,
24✔
30
                    full=flags)
31

32
    def select(self, whereclause=None, **params):
24✔
33
        if whereclause:
24✔
NEW
34
            return Select(self, whereclause, **params)
×
35
        return Select(self, **params)
24✔
36

37
    @classmethod
24✔
38
    def _make_from_standard(cls, std_table, _extend_on=None):
24✔
39
        ch_table = cls(std_table.name, std_table.metadata)
24✔
40
        ch_table.schema = std_table.schema
24✔
41
        ch_table.fullname = std_table.fullname
24✔
42
        ch_table.implicit_returning = std_table.implicit_returning
24✔
43
        ch_table.comment = std_table.comment
24✔
44
        ch_table.info = std_table.info
24✔
45
        ch_table._prefixes = std_table._prefixes
24✔
46
        ch_table.dialect_options = std_table.dialect_options
24✔
47

48
        if _extend_on is None:
24✔
49
            ch_table._columns = std_table._columns
24✔
50
            ch_table.columns = std_table.columns
24✔
51

52
        return ch_table
24✔
53

54

55
class MaterializedView(DialectKWArgs, SchemaItem, Immutable, FromClause):
24✔
56
    __visit_name__ = 'materialized_view'
24✔
57

58
    def __init__(self, *args, **kwargs):
24✔
59
        pass
24✔
60

61
    @property
24✔
62
    def bind(self):
20✔
UNCOV
63
        return self.metadata.bind
×
64

65
    @property
24✔
66
    def metadata(self):
20✔
UNCOV
67
        return self.inner_table.metadata
×
68

69
    def __new__(cls, inner_model, selectable, if_not_exists=False,
24✔
70
                cluster=None, populate=False, use_to=None,
71
                mv_suffix='_mv', name=None):
72
        rv = object.__new__(cls)
24✔
73
        rv.__init__()
24✔
74

75
        rv.mv_selectable = selectable
24✔
76
        rv.inner_table = inner_model.__table__
24✔
77
        rv.if_not_exists = if_not_exists
24✔
78
        rv.cluster = cluster
24✔
79
        rv.populate = populate
24✔
80
        rv.to = use_to
24✔
81

82
        table = inner_model.__table__
24✔
83
        metadata = rv.inner_table.metadata
24✔
84

85
        if use_to:
24✔
86
            if name is None:
×
87
                name = table.name + mv_suffix
×
88
        else:
89
            name = table.name
24✔
90

91
        rv.name = name
24✔
92

93
        metadata.info.setdefault('mat_views', set()).add(name)
24✔
94
        if not hasattr(metadata, 'mat_views'):
24✔
95
            metadata.mat_views = {}
24✔
96
        metadata.mat_views[name] = rv
24✔
97

98
        table.info['mv_storage'] = True
24✔
99

100
        return rv
24✔
101

102
    def __repr__(self):
24✔
103
        args = [repr(self.name), repr(self.metadata)]
×
104

105
        if self.to:
×
106
            args += ['TO ' + repr(self.inner_table.name)]
×
107
        else:
108
            args += (
×
109
                [repr(x) for x in self.inner_table.columns]
110
                + [repr(self.inner_table.engine)]
111
                + ['%s=%s' % (k, repr(getattr(self, k))) for k in ['schema']]
112
            )
113

114
        args += ['AS ' + str(self.mv_selectable)]
×
115

116
        return 'MaterializedView(%s)' % ', '.join(args)
×
117

118
    def create(self, bind=None, checkfirst=False, if_not_exists=False):
24✔
119
        if bind is None:
24✔
NEW
120
            bind = self.bind
×
121
        bind._run_ddl_visitor(ddl.SchemaGenerator, self, checkfirst=checkfirst,
24✔
122
                              if_not_exists=if_not_exists)
123

124
    def drop(self, bind=None, checkfirst=False, if_exists=False):
24✔
125
        if bind is None:
24✔
NEW
126
            bind = self.bind
×
127
        bind._run_ddl_visitor(ddl.SchemaDropper, self, checkfirst=checkfirst,
24✔
128
                              if_exists=if_exists)
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

© 2026 Coveralls, Inc