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

xzkostyan / clickhouse-sqlalchemy / 11405726556

18 Oct 2024 02:28PM UTC coverage: 85.988% (-0.09%) from 86.082%
11405726556

push

github

xzkostyan
Version bumped to 0.2.7

1 of 1 new or added line in 1 file covered. (100.0%)

63 existing lines in 11 files now uncovered.

2332 of 2712 relevant lines covered (85.99%)

20.04 hits per line

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

89.74
/clickhouse_sqlalchemy/sql/schema.py
1
from sqlalchemy import Table as TableBase
16✔
2
from sqlalchemy.sql.base import (
24✔
3
    _bind_or_error, 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✔
17
            bind = _bind_or_error(self)
24✔
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 = tuple({
24✔
24
            'full': full,
25
            'type': type,
26
            'strictness': strictness,
27
            'distribution': distribution
28
        }.items())
29
        return Join(self, right, onclause=onclause, isouter=isouter,
24✔
30
                    full=flags)
31

32
    def select(self, whereclause=None, **params):
24✔
33
        return Select._create([self], whereclause, **params)
24✔
34

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

46
        if _extend_on is None:
24✔
47
            ch_table._columns = std_table._columns
24✔
48
            ch_table.columns = std_table.columns
24✔
49

50
        return ch_table
24✔
51

52

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

56
    def __init__(self, *args, **kwargs):
24✔
57
        pass
24✔
58

59
    @property
24✔
60
    def bind(self):
20✔
61
        return self.metadata.bind
24✔
62

63
    @property
24✔
64
    def metadata(self):
20✔
65
        return self.inner_table.metadata
24✔
66

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

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

80
        table = inner_model.__table__
24✔
81
        metadata = rv.inner_table.metadata
24✔
82

83
        if use_to:
24✔
UNCOV
84
            if name is None:
×
UNCOV
85
                name = table.name + mv_suffix
×
86
        else:
87
            name = table.name
24✔
88

89
        rv.name = name
24✔
90

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

96
        table.info['mv_storage'] = True
24✔
97

98
        return rv
24✔
99

100
    def __repr__(self):
24✔
UNCOV
101
        args = [repr(self.name), repr(self.metadata)]
×
102

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

UNCOV
112
        args += ['AS ' + str(self.mv_selectable)]
×
113

UNCOV
114
        return 'MaterializedView(%s)' % ', '.join(args)
×
115

116
    def create(self, bind=None, checkfirst=False, if_not_exists=False):
24✔
117
        if bind is None:
24✔
118
            bind = _bind_or_error(self)
24✔
119
        bind._run_ddl_visitor(ddl.SchemaGenerator, self, checkfirst=checkfirst,
24✔
120
                              if_not_exists=if_not_exists)
121

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

© 2025 Coveralls, Inc