clickhouse-driver 0.2.1__cp39-cp39-win_amd64.whl → 0.2.10__cp39-cp39-win_amd64.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.
- clickhouse_driver/__init__.py +9 -9
- clickhouse_driver/block.py +227 -195
- clickhouse_driver/blockstreamprofileinfo.py +22 -22
- clickhouse_driver/bufferedreader.cp39-win_amd64.pyd +0 -0
- clickhouse_driver/bufferedwriter.cp39-win_amd64.pyd +0 -0
- clickhouse_driver/client.py +812 -666
- clickhouse_driver/clientinfo.py +119 -80
- clickhouse_driver/columns/arraycolumn.py +161 -150
- clickhouse_driver/columns/base.py +221 -147
- clickhouse_driver/columns/boolcolumn.py +7 -0
- clickhouse_driver/columns/datecolumn.py +108 -49
- clickhouse_driver/columns/datetimecolumn.py +203 -207
- clickhouse_driver/columns/decimalcolumn.py +116 -118
- clickhouse_driver/columns/enumcolumn.py +129 -119
- clickhouse_driver/columns/exceptions.py +12 -12
- clickhouse_driver/columns/floatcolumn.py +34 -34
- clickhouse_driver/columns/intcolumn.py +157 -157
- clickhouse_driver/columns/intervalcolumn.py +33 -33
- clickhouse_driver/columns/ipcolumn.py +118 -118
- clickhouse_driver/columns/jsoncolumn.py +37 -0
- clickhouse_driver/columns/largeint.cp39-win_amd64.pyd +0 -0
- clickhouse_driver/columns/lowcardinalitycolumn.py +142 -123
- clickhouse_driver/columns/mapcolumn.py +73 -58
- clickhouse_driver/columns/nestedcolumn.py +10 -0
- clickhouse_driver/columns/nothingcolumn.py +13 -13
- clickhouse_driver/columns/nullablecolumn.py +7 -7
- clickhouse_driver/columns/nullcolumn.py +15 -15
- clickhouse_driver/columns/numpy/base.py +47 -14
- clickhouse_driver/columns/numpy/boolcolumn.py +8 -0
- clickhouse_driver/columns/numpy/datecolumn.py +19 -12
- clickhouse_driver/columns/numpy/datetimecolumn.py +146 -145
- clickhouse_driver/columns/numpy/floatcolumn.py +24 -13
- clickhouse_driver/columns/numpy/intcolumn.py +43 -43
- clickhouse_driver/columns/numpy/lowcardinalitycolumn.py +96 -83
- clickhouse_driver/columns/numpy/service.py +58 -80
- clickhouse_driver/columns/numpy/stringcolumn.py +78 -76
- clickhouse_driver/columns/numpy/tuplecolumn.py +37 -0
- clickhouse_driver/columns/service.py +185 -131
- clickhouse_driver/columns/simpleaggregatefunctioncolumn.py +7 -7
- clickhouse_driver/columns/stringcolumn.py +73 -73
- clickhouse_driver/columns/tuplecolumn.py +63 -65
- clickhouse_driver/columns/util.py +61 -0
- clickhouse_driver/columns/uuidcolumn.py +64 -64
- clickhouse_driver/compression/__init__.py +32 -28
- clickhouse_driver/compression/base.py +87 -52
- clickhouse_driver/compression/lz4.py +21 -55
- clickhouse_driver/compression/lz4hc.py +9 -9
- clickhouse_driver/compression/zstd.py +20 -51
- clickhouse_driver/connection.py +825 -632
- clickhouse_driver/context.py +36 -36
- clickhouse_driver/dbapi/__init__.py +62 -62
- clickhouse_driver/dbapi/connection.py +99 -96
- clickhouse_driver/dbapi/cursor.py +370 -368
- clickhouse_driver/dbapi/errors.py +40 -40
- clickhouse_driver/dbapi/extras.py +73 -0
- clickhouse_driver/defines.py +58 -42
- clickhouse_driver/errors.py +453 -446
- clickhouse_driver/log.py +48 -44
- clickhouse_driver/numpy/block.py +8 -8
- clickhouse_driver/numpy/helpers.py +28 -25
- clickhouse_driver/numpy/result.py +123 -123
- clickhouse_driver/opentelemetry.py +43 -0
- clickhouse_driver/progress.py +44 -32
- clickhouse_driver/protocol.py +130 -105
- clickhouse_driver/queryprocessingstage.py +8 -8
- clickhouse_driver/reader.py +69 -69
- clickhouse_driver/readhelpers.py +26 -26
- clickhouse_driver/result.py +144 -144
- clickhouse_driver/settings/available.py +405 -405
- clickhouse_driver/settings/types.py +50 -50
- clickhouse_driver/settings/writer.py +34 -29
- clickhouse_driver/streams/compressed.py +88 -88
- clickhouse_driver/streams/native.py +108 -90
- clickhouse_driver/util/compat.py +39 -0
- clickhouse_driver/util/escape.py +94 -55
- clickhouse_driver/util/helpers.py +173 -57
- clickhouse_driver/varint.cp39-win_amd64.pyd +0 -0
- clickhouse_driver/writer.py +67 -67
- clickhouse_driver-0.2.10.dist-info/METADATA +215 -0
- clickhouse_driver-0.2.10.dist-info/RECORD +89 -0
- {clickhouse_driver-0.2.1.dist-info → clickhouse_driver-0.2.10.dist-info}/WHEEL +1 -1
- {clickhouse_driver-0.2.1.dist-info → clickhouse_driver-0.2.10.dist-info/licenses}/LICENSE +21 -21
- clickhouse_driver-0.2.1.dist-info/METADATA +0 -24
- clickhouse_driver-0.2.1.dist-info/RECORD +0 -80
- {clickhouse_driver-0.2.1.dist-info → clickhouse_driver-0.2.10.dist-info}/top_level.txt +0 -0
|
@@ -1,119 +1,129 @@
|
|
|
1
|
-
from enum import Enum
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
from
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
1
|
+
from enum import Enum
|
|
2
|
+
from collections import OrderedDict
|
|
3
|
+
|
|
4
|
+
from .. import errors
|
|
5
|
+
from .intcolumn import IntColumn
|
|
6
|
+
|
|
7
|
+
invalid_names_for_python_enum = frozenset(['mro', ''])
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class EnumColumn(IntColumn):
|
|
11
|
+
py_types = (Enum, int, str)
|
|
12
|
+
|
|
13
|
+
def __init__(self, name_by_value, value_by_name, **kwargs):
|
|
14
|
+
self.name_by_value = name_by_value
|
|
15
|
+
self.value_by_name = value_by_name
|
|
16
|
+
super(EnumColumn, self).__init__(**kwargs)
|
|
17
|
+
|
|
18
|
+
def before_write_items(self, items, nulls_map=None):
|
|
19
|
+
null_value = self.null_value
|
|
20
|
+
name_by_value = self.name_by_value
|
|
21
|
+
value_by_name = self.value_by_name
|
|
22
|
+
|
|
23
|
+
for i, item in enumerate(items):
|
|
24
|
+
if nulls_map and nulls_map[i]:
|
|
25
|
+
items[i] = null_value
|
|
26
|
+
continue
|
|
27
|
+
|
|
28
|
+
source_value = item.name if isinstance(item, Enum) else item
|
|
29
|
+
|
|
30
|
+
# Check real enum value
|
|
31
|
+
try:
|
|
32
|
+
if isinstance(source_value, str):
|
|
33
|
+
items[i] = value_by_name[source_value]
|
|
34
|
+
else:
|
|
35
|
+
items[i] = value_by_name[name_by_value[source_value]]
|
|
36
|
+
except (ValueError, KeyError):
|
|
37
|
+
choices = ', '.join(
|
|
38
|
+
"'{}' = {}".format(name.replace("'", r"\'"), value)
|
|
39
|
+
for name, value in value_by_name.items()
|
|
40
|
+
)
|
|
41
|
+
enum_str = '{}({})'.format(self.ch_type, choices)
|
|
42
|
+
|
|
43
|
+
raise errors.LogicalError(
|
|
44
|
+
"Unknown element '{}' for type {}"
|
|
45
|
+
.format(source_value, enum_str)
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
def after_read_items(self, items, nulls_map=None):
|
|
49
|
+
name_by_value = self.name_by_value
|
|
50
|
+
|
|
51
|
+
if nulls_map is None:
|
|
52
|
+
return tuple(name_by_value[item] for item in items)
|
|
53
|
+
else:
|
|
54
|
+
return tuple(
|
|
55
|
+
(None if is_null else name_by_value[items[i]])
|
|
56
|
+
for i, is_null in enumerate(nulls_map)
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class Enum8Column(EnumColumn):
|
|
61
|
+
ch_type = 'Enum8'
|
|
62
|
+
format = 'b'
|
|
63
|
+
int_size = 1
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class Enum16Column(EnumColumn):
|
|
67
|
+
ch_type = 'Enum16'
|
|
68
|
+
format = 'h'
|
|
69
|
+
int_size = 2
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def create_enum_column(spec, column_options):
|
|
73
|
+
if spec.startswith('Enum8'):
|
|
74
|
+
params = spec[6:-1]
|
|
75
|
+
cls = Enum8Column
|
|
76
|
+
else:
|
|
77
|
+
params = spec[7:-1]
|
|
78
|
+
cls = Enum16Column
|
|
79
|
+
|
|
80
|
+
name_by_value, value_by_name = _parse_options(params)
|
|
81
|
+
|
|
82
|
+
return cls(name_by_value, value_by_name, **column_options)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _parse_options(option_string):
|
|
86
|
+
name_by_value, value_by_name = {}, OrderedDict()
|
|
87
|
+
after_name = False
|
|
88
|
+
escaped = False
|
|
89
|
+
quote_character = None
|
|
90
|
+
name = ''
|
|
91
|
+
value = ''
|
|
92
|
+
|
|
93
|
+
for ch in option_string:
|
|
94
|
+
if escaped:
|
|
95
|
+
name += ch
|
|
96
|
+
escaped = False # accepting escaped character
|
|
97
|
+
|
|
98
|
+
elif after_name:
|
|
99
|
+
if ch in (' ', '='):
|
|
100
|
+
pass
|
|
101
|
+
elif ch == ',':
|
|
102
|
+
value = int(value)
|
|
103
|
+
name_by_value[value] = name
|
|
104
|
+
value_by_name[name] = value
|
|
105
|
+
after_name = False
|
|
106
|
+
name = ''
|
|
107
|
+
value = '' # reset before collecting new option
|
|
108
|
+
else:
|
|
109
|
+
value += ch
|
|
110
|
+
|
|
111
|
+
elif quote_character:
|
|
112
|
+
if ch == '\\':
|
|
113
|
+
escaped = True
|
|
114
|
+
elif ch == quote_character:
|
|
115
|
+
quote_character = None
|
|
116
|
+
after_name = True # start collecting option value
|
|
117
|
+
else:
|
|
118
|
+
name += ch
|
|
119
|
+
|
|
120
|
+
else:
|
|
121
|
+
if ch == "'":
|
|
122
|
+
quote_character = ch
|
|
123
|
+
|
|
124
|
+
if after_name:
|
|
125
|
+
value = int(value)
|
|
126
|
+
name_by_value[value] = name
|
|
127
|
+
value_by_name[name] = value
|
|
128
|
+
|
|
129
|
+
return name_by_value, value_by_name
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class ColumnException(Exception):
|
|
4
|
-
pass
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class ColumnTypeMismatchException(ColumnException):
|
|
8
|
-
pass
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class StructPackException(ColumnException):
|
|
12
|
-
pass
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
class ColumnException(Exception):
|
|
4
|
+
pass
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ColumnTypeMismatchException(ColumnException):
|
|
8
|
+
pass
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class StructPackException(ColumnException):
|
|
12
|
+
pass
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
from ctypes import c_float
|
|
2
|
-
|
|
3
|
-
from .base import FormatColumn
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class FloatColumn(FormatColumn):
|
|
7
|
-
py_types = (float, int)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class Float32Column(FloatColumn):
|
|
11
|
-
ch_type = 'Float32'
|
|
12
|
-
format = 'f'
|
|
13
|
-
|
|
14
|
-
def __init__(self, types_check=False, **kwargs):
|
|
15
|
-
super(Float32Column, self).__init__(types_check=types_check, **kwargs)
|
|
16
|
-
|
|
17
|
-
if types_check:
|
|
18
|
-
# Chop only bytes that fit current type.
|
|
19
|
-
# Cast to -nan or nan if overflows.
|
|
20
|
-
def before_write_items(items, nulls_map=None):
|
|
21
|
-
null_value = self.null_value
|
|
22
|
-
|
|
23
|
-
for i, item in enumerate(items):
|
|
24
|
-
if nulls_map and nulls_map[i]:
|
|
25
|
-
items[i] = null_value
|
|
26
|
-
else:
|
|
27
|
-
items[i] = c_float(item).value
|
|
28
|
-
|
|
29
|
-
self.before_write_items = before_write_items
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class Float64Column(FloatColumn):
|
|
33
|
-
ch_type = 'Float64'
|
|
34
|
-
format = 'd'
|
|
1
|
+
from ctypes import c_float
|
|
2
|
+
|
|
3
|
+
from .base import FormatColumn
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class FloatColumn(FormatColumn):
|
|
7
|
+
py_types = (float, int)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Float32Column(FloatColumn):
|
|
11
|
+
ch_type = 'Float32'
|
|
12
|
+
format = 'f'
|
|
13
|
+
|
|
14
|
+
def __init__(self, types_check=False, **kwargs):
|
|
15
|
+
super(Float32Column, self).__init__(types_check=types_check, **kwargs)
|
|
16
|
+
|
|
17
|
+
if types_check:
|
|
18
|
+
# Chop only bytes that fit current type.
|
|
19
|
+
# Cast to -nan or nan if overflows.
|
|
20
|
+
def before_write_items(items, nulls_map=None):
|
|
21
|
+
null_value = self.null_value
|
|
22
|
+
|
|
23
|
+
for i, item in enumerate(items):
|
|
24
|
+
if nulls_map and nulls_map[i]:
|
|
25
|
+
items[i] = null_value
|
|
26
|
+
else:
|
|
27
|
+
items[i] = c_float(item).value
|
|
28
|
+
|
|
29
|
+
self.before_write_items = before_write_items
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Float64Column(FloatColumn):
|
|
33
|
+
ch_type = 'Float64'
|
|
34
|
+
format = 'd'
|
|
@@ -1,157 +1,157 @@
|
|
|
1
|
-
|
|
2
|
-
from .exceptions import ColumnTypeMismatchException
|
|
3
|
-
from .base import FormatColumn
|
|
4
|
-
from .largeint import (
|
|
5
|
-
int128_from_quads, int128_to_quads, uint128_from_quads, uint128_to_quads,
|
|
6
|
-
int256_from_quads, int256_to_quads, uint256_from_quads, uint256_to_quads
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class IntColumn(FormatColumn):
|
|
11
|
-
py_types = (int, )
|
|
12
|
-
int_size = None
|
|
13
|
-
|
|
14
|
-
def __init__(self, types_check=False, **kwargs):
|
|
15
|
-
super(IntColumn, self).__init__(types_check=types_check, **kwargs)
|
|
16
|
-
|
|
17
|
-
if types_check:
|
|
18
|
-
self.mask = (1 << 8 * self.int_size) - 1
|
|
19
|
-
|
|
20
|
-
# Chop only bytes that fit current type.
|
|
21
|
-
# ctypes.c_intXX is slower.
|
|
22
|
-
def before_write_items(items, nulls_map=None):
|
|
23
|
-
# TODO: cythonize
|
|
24
|
-
null_value = self.null_value
|
|
25
|
-
|
|
26
|
-
for i, item in enumerate(items):
|
|
27
|
-
if nulls_map and nulls_map[i]:
|
|
28
|
-
items[i] = null_value
|
|
29
|
-
continue
|
|
30
|
-
|
|
31
|
-
if item >= 0:
|
|
32
|
-
sign = 1
|
|
33
|
-
else:
|
|
34
|
-
sign = -1
|
|
35
|
-
item = -item
|
|
36
|
-
|
|
37
|
-
items[i] = sign * (item & self.mask)
|
|
38
|
-
|
|
39
|
-
self.before_write_items = before_write_items
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
class UIntColumn(IntColumn):
|
|
43
|
-
def __init__(self, types_check=False, **kwargs):
|
|
44
|
-
super(UIntColumn, self).__init__(types_check=types_check, **kwargs)
|
|
45
|
-
|
|
46
|
-
if types_check:
|
|
47
|
-
def check_item(value):
|
|
48
|
-
if value < 0:
|
|
49
|
-
raise ColumnTypeMismatchException(value)
|
|
50
|
-
|
|
51
|
-
self.check_item = check_item
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
class Int8Column(IntColumn):
|
|
55
|
-
ch_type = 'Int8'
|
|
56
|
-
format = 'b'
|
|
57
|
-
int_size = 1
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
class Int16Column(IntColumn):
|
|
61
|
-
ch_type = 'Int16'
|
|
62
|
-
format = 'h'
|
|
63
|
-
int_size = 2
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
class Int32Column(IntColumn):
|
|
67
|
-
ch_type = 'Int32'
|
|
68
|
-
format = 'i'
|
|
69
|
-
int_size = 4
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
class Int64Column(IntColumn):
|
|
73
|
-
ch_type = 'Int64'
|
|
74
|
-
format = 'q'
|
|
75
|
-
int_size = 8
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
class UInt8Column(UIntColumn):
|
|
79
|
-
ch_type = 'UInt8'
|
|
80
|
-
format = 'B'
|
|
81
|
-
int_size = 1
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
class UInt16Column(UIntColumn):
|
|
85
|
-
ch_type = 'UInt16'
|
|
86
|
-
format = 'H'
|
|
87
|
-
int_size = 2
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
class UInt32Column(UIntColumn):
|
|
91
|
-
ch_type = 'UInt32'
|
|
92
|
-
format = 'I'
|
|
93
|
-
int_size = 4
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
class UInt64Column(UIntColumn):
|
|
97
|
-
ch_type = 'UInt64'
|
|
98
|
-
format = 'Q'
|
|
99
|
-
int_size = 8
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
class LargeIntColumn(IntColumn):
|
|
103
|
-
format = 'Q' # We manually deal with sign in read/write.
|
|
104
|
-
factor = None
|
|
105
|
-
|
|
106
|
-
to_quads = None
|
|
107
|
-
from_quads = None
|
|
108
|
-
|
|
109
|
-
def write_items(self, items, buf):
|
|
110
|
-
n_items = len(items)
|
|
111
|
-
|
|
112
|
-
s = self.make_struct(self.factor * n_items)
|
|
113
|
-
uint_64_pairs = self.to_quads(items, n_items)
|
|
114
|
-
|
|
115
|
-
buf.write(s.pack(*uint_64_pairs))
|
|
116
|
-
|
|
117
|
-
def read_items(self, n_items, buf):
|
|
118
|
-
s = self.make_struct(self.factor * n_items)
|
|
119
|
-
items = s.unpack(buf.read(s.size))
|
|
120
|
-
|
|
121
|
-
return self.from_quads(items, n_items)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
class Int128Column(LargeIntColumn):
|
|
125
|
-
ch_type = 'Int128'
|
|
126
|
-
int_size = 16
|
|
127
|
-
factor = 2
|
|
128
|
-
|
|
129
|
-
to_quads = int128_to_quads
|
|
130
|
-
from_quads = int128_from_quads
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
class UInt128Column(LargeIntColumn):
|
|
134
|
-
ch_type = 'UInt128'
|
|
135
|
-
int_size = 16
|
|
136
|
-
factor = 2
|
|
137
|
-
|
|
138
|
-
to_quads = uint128_to_quads
|
|
139
|
-
from_quads = uint128_from_quads
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
class Int256Column(LargeIntColumn):
|
|
143
|
-
ch_type = 'Int256'
|
|
144
|
-
int_size = 32
|
|
145
|
-
factor = 4
|
|
146
|
-
|
|
147
|
-
to_quads = int256_to_quads
|
|
148
|
-
from_quads = int256_from_quads
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
class UInt256Column(LargeIntColumn):
|
|
152
|
-
ch_type = 'UInt256'
|
|
153
|
-
int_size = 32
|
|
154
|
-
factor = 4
|
|
155
|
-
|
|
156
|
-
to_quads = uint256_to_quads
|
|
157
|
-
from_quads = uint256_from_quads
|
|
1
|
+
|
|
2
|
+
from .exceptions import ColumnTypeMismatchException
|
|
3
|
+
from .base import FormatColumn
|
|
4
|
+
from .largeint import (
|
|
5
|
+
int128_from_quads, int128_to_quads, uint128_from_quads, uint128_to_quads,
|
|
6
|
+
int256_from_quads, int256_to_quads, uint256_from_quads, uint256_to_quads
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class IntColumn(FormatColumn):
|
|
11
|
+
py_types = (int, )
|
|
12
|
+
int_size = None
|
|
13
|
+
|
|
14
|
+
def __init__(self, types_check=False, **kwargs):
|
|
15
|
+
super(IntColumn, self).__init__(types_check=types_check, **kwargs)
|
|
16
|
+
|
|
17
|
+
if types_check:
|
|
18
|
+
self.mask = (1 << 8 * self.int_size) - 1
|
|
19
|
+
|
|
20
|
+
# Chop only bytes that fit current type.
|
|
21
|
+
# ctypes.c_intXX is slower.
|
|
22
|
+
def before_write_items(items, nulls_map=None):
|
|
23
|
+
# TODO: cythonize
|
|
24
|
+
null_value = self.null_value
|
|
25
|
+
|
|
26
|
+
for i, item in enumerate(items):
|
|
27
|
+
if nulls_map and nulls_map[i]:
|
|
28
|
+
items[i] = null_value
|
|
29
|
+
continue
|
|
30
|
+
|
|
31
|
+
if item >= 0:
|
|
32
|
+
sign = 1
|
|
33
|
+
else:
|
|
34
|
+
sign = -1
|
|
35
|
+
item = -item
|
|
36
|
+
|
|
37
|
+
items[i] = sign * (item & self.mask)
|
|
38
|
+
|
|
39
|
+
self.before_write_items = before_write_items
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class UIntColumn(IntColumn):
|
|
43
|
+
def __init__(self, types_check=False, **kwargs):
|
|
44
|
+
super(UIntColumn, self).__init__(types_check=types_check, **kwargs)
|
|
45
|
+
|
|
46
|
+
if types_check:
|
|
47
|
+
def check_item(value):
|
|
48
|
+
if value < 0:
|
|
49
|
+
raise ColumnTypeMismatchException(value)
|
|
50
|
+
|
|
51
|
+
self.check_item = check_item
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class Int8Column(IntColumn):
|
|
55
|
+
ch_type = 'Int8'
|
|
56
|
+
format = 'b'
|
|
57
|
+
int_size = 1
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class Int16Column(IntColumn):
|
|
61
|
+
ch_type = 'Int16'
|
|
62
|
+
format = 'h'
|
|
63
|
+
int_size = 2
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class Int32Column(IntColumn):
|
|
67
|
+
ch_type = 'Int32'
|
|
68
|
+
format = 'i'
|
|
69
|
+
int_size = 4
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class Int64Column(IntColumn):
|
|
73
|
+
ch_type = 'Int64'
|
|
74
|
+
format = 'q'
|
|
75
|
+
int_size = 8
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class UInt8Column(UIntColumn):
|
|
79
|
+
ch_type = 'UInt8'
|
|
80
|
+
format = 'B'
|
|
81
|
+
int_size = 1
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class UInt16Column(UIntColumn):
|
|
85
|
+
ch_type = 'UInt16'
|
|
86
|
+
format = 'H'
|
|
87
|
+
int_size = 2
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class UInt32Column(UIntColumn):
|
|
91
|
+
ch_type = 'UInt32'
|
|
92
|
+
format = 'I'
|
|
93
|
+
int_size = 4
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class UInt64Column(UIntColumn):
|
|
97
|
+
ch_type = 'UInt64'
|
|
98
|
+
format = 'Q'
|
|
99
|
+
int_size = 8
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class LargeIntColumn(IntColumn):
|
|
103
|
+
format = 'Q' # We manually deal with sign in read/write.
|
|
104
|
+
factor = None
|
|
105
|
+
|
|
106
|
+
to_quads = None
|
|
107
|
+
from_quads = None
|
|
108
|
+
|
|
109
|
+
def write_items(self, items, buf):
|
|
110
|
+
n_items = len(items)
|
|
111
|
+
|
|
112
|
+
s = self.make_struct(self.factor * n_items)
|
|
113
|
+
uint_64_pairs = self.to_quads(items, n_items)
|
|
114
|
+
|
|
115
|
+
buf.write(s.pack(*uint_64_pairs))
|
|
116
|
+
|
|
117
|
+
def read_items(self, n_items, buf):
|
|
118
|
+
s = self.make_struct(self.factor * n_items)
|
|
119
|
+
items = s.unpack(buf.read(s.size))
|
|
120
|
+
|
|
121
|
+
return self.from_quads(items, n_items)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class Int128Column(LargeIntColumn):
|
|
125
|
+
ch_type = 'Int128'
|
|
126
|
+
int_size = 16
|
|
127
|
+
factor = 2
|
|
128
|
+
|
|
129
|
+
to_quads = int128_to_quads
|
|
130
|
+
from_quads = int128_from_quads
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
class UInt128Column(LargeIntColumn):
|
|
134
|
+
ch_type = 'UInt128'
|
|
135
|
+
int_size = 16
|
|
136
|
+
factor = 2
|
|
137
|
+
|
|
138
|
+
to_quads = uint128_to_quads
|
|
139
|
+
from_quads = uint128_from_quads
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class Int256Column(LargeIntColumn):
|
|
143
|
+
ch_type = 'Int256'
|
|
144
|
+
int_size = 32
|
|
145
|
+
factor = 4
|
|
146
|
+
|
|
147
|
+
to_quads = int256_to_quads
|
|
148
|
+
from_quads = int256_from_quads
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class UInt256Column(LargeIntColumn):
|
|
152
|
+
ch_type = 'UInt256'
|
|
153
|
+
int_size = 32
|
|
154
|
+
factor = 4
|
|
155
|
+
|
|
156
|
+
to_quads = uint256_to_quads
|
|
157
|
+
from_quads = uint256_from_quads
|