clickhouse-driver 0.2.1__cp39-cp39-win_amd64.whl → 0.2.8__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.
Files changed (85) hide show
  1. clickhouse_driver/__init__.py +9 -9
  2. clickhouse_driver/block.py +227 -195
  3. clickhouse_driver/blockstreamprofileinfo.py +22 -22
  4. clickhouse_driver/bufferedreader.cp39-win_amd64.pyd +0 -0
  5. clickhouse_driver/bufferedwriter.cp39-win_amd64.pyd +0 -0
  6. clickhouse_driver/client.py +896 -666
  7. clickhouse_driver/clientinfo.py +119 -80
  8. clickhouse_driver/columns/arraycolumn.py +161 -150
  9. clickhouse_driver/columns/base.py +221 -147
  10. clickhouse_driver/columns/boolcolumn.py +7 -0
  11. clickhouse_driver/columns/datecolumn.py +108 -49
  12. clickhouse_driver/columns/datetimecolumn.py +202 -207
  13. clickhouse_driver/columns/decimalcolumn.py +116 -118
  14. clickhouse_driver/columns/enumcolumn.py +119 -119
  15. clickhouse_driver/columns/exceptions.py +12 -12
  16. clickhouse_driver/columns/floatcolumn.py +34 -34
  17. clickhouse_driver/columns/intcolumn.py +157 -157
  18. clickhouse_driver/columns/intervalcolumn.py +33 -33
  19. clickhouse_driver/columns/ipcolumn.py +118 -118
  20. clickhouse_driver/columns/jsoncolumn.py +37 -0
  21. clickhouse_driver/columns/largeint.cp39-win_amd64.pyd +0 -0
  22. clickhouse_driver/columns/lowcardinalitycolumn.py +142 -123
  23. clickhouse_driver/columns/mapcolumn.py +73 -58
  24. clickhouse_driver/columns/nestedcolumn.py +10 -0
  25. clickhouse_driver/columns/nothingcolumn.py +13 -13
  26. clickhouse_driver/columns/nullablecolumn.py +7 -7
  27. clickhouse_driver/columns/nullcolumn.py +15 -15
  28. clickhouse_driver/columns/numpy/base.py +47 -14
  29. clickhouse_driver/columns/numpy/boolcolumn.py +8 -0
  30. clickhouse_driver/columns/numpy/datecolumn.py +19 -12
  31. clickhouse_driver/columns/numpy/datetimecolumn.py +143 -145
  32. clickhouse_driver/columns/numpy/floatcolumn.py +24 -13
  33. clickhouse_driver/columns/numpy/intcolumn.py +43 -43
  34. clickhouse_driver/columns/numpy/lowcardinalitycolumn.py +96 -83
  35. clickhouse_driver/columns/numpy/service.py +58 -80
  36. clickhouse_driver/columns/numpy/stringcolumn.py +78 -76
  37. clickhouse_driver/columns/numpy/tuplecolumn.py +37 -0
  38. clickhouse_driver/columns/service.py +185 -131
  39. clickhouse_driver/columns/simpleaggregatefunctioncolumn.py +7 -7
  40. clickhouse_driver/columns/stringcolumn.py +73 -73
  41. clickhouse_driver/columns/tuplecolumn.py +63 -65
  42. clickhouse_driver/columns/util.py +60 -0
  43. clickhouse_driver/columns/uuidcolumn.py +64 -64
  44. clickhouse_driver/compression/__init__.py +28 -28
  45. clickhouse_driver/compression/base.py +87 -52
  46. clickhouse_driver/compression/lz4.py +21 -55
  47. clickhouse_driver/compression/lz4hc.py +9 -9
  48. clickhouse_driver/compression/zstd.py +20 -51
  49. clickhouse_driver/connection.py +784 -632
  50. clickhouse_driver/context.py +36 -36
  51. clickhouse_driver/dbapi/__init__.py +62 -62
  52. clickhouse_driver/dbapi/connection.py +99 -96
  53. clickhouse_driver/dbapi/cursor.py +370 -368
  54. clickhouse_driver/dbapi/errors.py +40 -40
  55. clickhouse_driver/dbapi/extras.py +73 -0
  56. clickhouse_driver/defines.py +55 -42
  57. clickhouse_driver/errors.py +453 -446
  58. clickhouse_driver/log.py +48 -44
  59. clickhouse_driver/numpy/block.py +8 -8
  60. clickhouse_driver/numpy/helpers.py +25 -25
  61. clickhouse_driver/numpy/result.py +123 -123
  62. clickhouse_driver/opentelemetry.py +43 -0
  63. clickhouse_driver/progress.py +38 -32
  64. clickhouse_driver/protocol.py +114 -105
  65. clickhouse_driver/queryprocessingstage.py +8 -8
  66. clickhouse_driver/reader.py +69 -69
  67. clickhouse_driver/readhelpers.py +26 -26
  68. clickhouse_driver/result.py +144 -144
  69. clickhouse_driver/settings/available.py +405 -405
  70. clickhouse_driver/settings/types.py +50 -50
  71. clickhouse_driver/settings/writer.py +34 -29
  72. clickhouse_driver/streams/compressed.py +88 -88
  73. clickhouse_driver/streams/native.py +102 -90
  74. clickhouse_driver/util/compat.py +39 -0
  75. clickhouse_driver/util/escape.py +94 -55
  76. clickhouse_driver/util/helpers.py +57 -57
  77. clickhouse_driver/varint.cp39-win_amd64.pyd +0 -0
  78. clickhouse_driver/writer.py +67 -67
  79. {clickhouse_driver-0.2.1.dist-info → clickhouse_driver-0.2.8.dist-info}/LICENSE +21 -21
  80. clickhouse_driver-0.2.8.dist-info/METADATA +201 -0
  81. clickhouse_driver-0.2.8.dist-info/RECORD +89 -0
  82. {clickhouse_driver-0.2.1.dist-info → clickhouse_driver-0.2.8.dist-info}/WHEEL +1 -1
  83. clickhouse_driver-0.2.1.dist-info/METADATA +0 -24
  84. clickhouse_driver-0.2.1.dist-info/RECORD +0 -80
  85. {clickhouse_driver-0.2.1.dist-info → clickhouse_driver-0.2.8.dist-info}/top_level.txt +0 -0
clickhouse_driver/log.py CHANGED
@@ -1,44 +1,48 @@
1
- import logging
2
-
3
- logger = logging.getLogger(__name__)
4
-
5
-
6
- log_priorities = (
7
- 'Unknown',
8
- 'Fatal',
9
- 'Critical',
10
- 'Error',
11
- 'Warning',
12
- 'Notice',
13
- 'Information',
14
- 'Debug',
15
- 'Trace'
16
- )
17
-
18
-
19
- def log_block(block):
20
- if block is None:
21
- return
22
-
23
- column_names = [x[0] for x in block.columns_with_types]
24
-
25
- for row in block.get_rows():
26
- row = dict(zip(column_names, row))
27
-
28
- if 1 <= row['priority'] <= 8:
29
- priority = log_priorities[row['priority']]
30
- else:
31
- priority = row[0]
32
-
33
- # thread_number in servers prior 20.x
34
- thread_id = row.get('thread_id') or row['thread_number']
35
-
36
- logger.info(
37
- '[ %s ] [ %s ] {%s} <%s> %s: %s',
38
- row['host_name'],
39
- thread_id,
40
- row['query_id'],
41
- priority,
42
- row['source'],
43
- row['text']
44
- )
1
+ import logging
2
+
3
+ logger = logging.getLogger(__name__)
4
+
5
+ # Keep in sync with ClickHouse priorities
6
+ # https://github.com/ClickHouse/ClickHouse/blob/master/src/Interpreters/InternalTextLogsQueue.cpp
7
+ log_priorities = (
8
+ 'Unknown',
9
+ 'Fatal',
10
+ 'Critical',
11
+ 'Error',
12
+ 'Warning',
13
+ 'Notice',
14
+ 'Information',
15
+ 'Debug',
16
+ 'Trace',
17
+ 'Test',
18
+ )
19
+
20
+ num_priorities = len(log_priorities)
21
+
22
+
23
+ def log_block(block):
24
+ if block is None:
25
+ return
26
+
27
+ column_names = [x[0] for x in block.columns_with_types]
28
+
29
+ for row in block.get_rows():
30
+ row = dict(zip(column_names, row))
31
+
32
+ if 1 <= row['priority'] <= num_priorities:
33
+ priority = log_priorities[row['priority']]
34
+ else:
35
+ priority = row[0]
36
+
37
+ # thread_number in servers prior 20.x
38
+ thread_id = row.get('thread_id') or row['thread_number']
39
+
40
+ logger.info(
41
+ '[ %s ] [ %s ] {%s} <%s> %s: %s',
42
+ row['host_name'],
43
+ thread_id,
44
+ row['query_id'],
45
+ priority,
46
+ row['source'],
47
+ row['text']
48
+ )
@@ -1,8 +1,8 @@
1
- import numpy as np
2
-
3
- from ..block import ColumnOrientedBlock
4
-
5
-
6
- class NumpyColumnOrientedBlock(ColumnOrientedBlock):
7
- def transposed(self):
8
- return np.transpose(self.data)
1
+ import numpy as np
2
+
3
+ from ..block import ColumnOrientedBlock
4
+
5
+
6
+ class NumpyColumnOrientedBlock(ColumnOrientedBlock):
7
+ def transposed(self):
8
+ return np.transpose(self.data)
@@ -1,25 +1,25 @@
1
- import numpy as np
2
- import pandas as pd
3
-
4
-
5
- def column_chunks(columns, n):
6
- for column in columns:
7
- if not isinstance(column, (np.ndarray, pd.DatetimeIndex)):
8
- raise TypeError(
9
- 'Unsupported column type: {}. '
10
- 'ndarray/DatetimeIndex is expected.'
11
- .format(type(column))
12
- )
13
-
14
- # create chunk generator for every column
15
- chunked = [
16
- iter(np.array_split(c, range(0, len(c), n)) if len(c) > n else [c])
17
- for c in columns
18
- ]
19
-
20
- while True:
21
- # get next chunk for every column
22
- item = [next(column, []) for column in chunked]
23
- if not any(len(x) for x in item):
24
- break
25
- yield item
1
+ import numpy as np
2
+ import pandas as pd
3
+
4
+
5
+ def column_chunks(columns, n):
6
+ for column in columns:
7
+ if not isinstance(column, (np.ndarray, pd.DatetimeIndex)):
8
+ raise TypeError(
9
+ 'Unsupported column type: {}. '
10
+ 'ndarray/DatetimeIndex is expected.'
11
+ .format(type(column))
12
+ )
13
+
14
+ # create chunk generator for every column
15
+ chunked = [
16
+ iter(np.array_split(c, len(c) // n) if len(c) > n else [c])
17
+ for c in columns
18
+ ]
19
+
20
+ while True:
21
+ # get next chunk for every column
22
+ item = [next(column, []) for column in chunked]
23
+ if not any(len(x) for x in item):
24
+ break
25
+ yield item
@@ -1,123 +1,123 @@
1
- from itertools import chain
2
-
3
- import numpy as np
4
- import pandas as pd
5
- from pandas.api.types import union_categoricals
6
-
7
- from ..progress import Progress
8
- from ..result import QueryResult
9
-
10
-
11
- class NumpyQueryResult(QueryResult):
12
- """
13
- Stores query result from multiple blocks as numpy arrays.
14
- """
15
-
16
- def store(self, packet):
17
- block = getattr(packet, 'block', None)
18
- if block is None:
19
- return
20
-
21
- # Header block contains no rows. Pick columns from it.
22
- if block.num_rows:
23
- if self.columnar:
24
- self.data.append(block.get_columns())
25
- else:
26
- self.data.extend(block.get_rows())
27
-
28
- elif not self.columns_with_types:
29
- self.columns_with_types = block.columns_with_types
30
-
31
- def get_result(self):
32
- """
33
- :return: stored query result.
34
- """
35
-
36
- for packet in self.packet_generator:
37
- self.store(packet)
38
-
39
- if self.columnar:
40
- data = []
41
- # Transpose to a list of columns, each column is list of chunks
42
- for column_chunks in zip(*self.data):
43
- # Concatenate chunks for each column
44
- if isinstance(column_chunks[0], np.ndarray):
45
- column = np.concatenate(column_chunks)
46
- elif isinstance(column_chunks[0], pd.Categorical):
47
- column = union_categoricals(column_chunks)
48
- else:
49
- column = tuple(chain.from_iterable(column_chunks))
50
- data.append(column)
51
- else:
52
- data = self.data
53
-
54
- if self.with_column_types:
55
- return data, self.columns_with_types
56
- else:
57
- return data
58
-
59
-
60
- class NumpyProgressQueryResult(NumpyQueryResult):
61
- """
62
- Stores query result and progress information from multiple blocks.
63
- Provides iteration over query progress.
64
- """
65
-
66
- def __init__(self, *args, **kwargs):
67
- self.progress_totals = Progress()
68
-
69
- super(NumpyProgressQueryResult, self).__init__(*args, **kwargs)
70
-
71
- def __iter__(self):
72
- return self
73
-
74
- def __next__(self):
75
- while True:
76
- packet = next(self.packet_generator)
77
- progress_packet = getattr(packet, 'progress', None)
78
- if progress_packet:
79
- self.progress_totals.increment(progress_packet)
80
- return (
81
- self.progress_totals.rows, self.progress_totals.total_rows
82
- )
83
- else:
84
- self.store(packet)
85
-
86
- def get_result(self):
87
- # Read all progress packets.
88
- for _ in self:
89
- pass
90
-
91
- return super(NumpyProgressQueryResult, self).get_result()
92
-
93
-
94
- class NumpyIterQueryResult(object):
95
- """
96
- Provides iteration over returned data by chunks (streaming by chunks).
97
- """
98
-
99
- def __init__(
100
- self, packet_generator,
101
- with_column_types=False):
102
- self.packet_generator = packet_generator
103
- self.with_column_types = with_column_types
104
-
105
- self.first_block = True
106
- super(NumpyIterQueryResult, self).__init__()
107
-
108
- def __iter__(self):
109
- return self
110
-
111
- def __next__(self):
112
- packet = next(self.packet_generator)
113
- block = getattr(packet, 'block', None)
114
- if block is None:
115
- return []
116
-
117
- if self.first_block and self.with_column_types:
118
- self.first_block = False
119
- rv = [block.columns_with_types]
120
- rv.extend(block.get_rows())
121
- return rv
122
- else:
123
- return block.get_rows()
1
+ from itertools import chain
2
+
3
+ import numpy as np
4
+ import pandas as pd
5
+ from pandas.api.types import union_categoricals
6
+
7
+ from ..progress import Progress
8
+ from ..result import QueryResult
9
+
10
+
11
+ class NumpyQueryResult(QueryResult):
12
+ """
13
+ Stores query result from multiple blocks as numpy arrays.
14
+ """
15
+
16
+ def store(self, packet):
17
+ block = getattr(packet, 'block', None)
18
+ if block is None:
19
+ return
20
+
21
+ # Header block contains no rows. Pick columns from it.
22
+ if block.num_rows:
23
+ if self.columnar:
24
+ self.data.append(block.get_columns())
25
+ else:
26
+ self.data.extend(block.get_rows())
27
+
28
+ elif not self.columns_with_types:
29
+ self.columns_with_types = block.columns_with_types
30
+
31
+ def get_result(self):
32
+ """
33
+ :return: stored query result.
34
+ """
35
+
36
+ for packet in self.packet_generator:
37
+ self.store(packet)
38
+
39
+ if self.columnar:
40
+ data = []
41
+ # Transpose to a list of columns, each column is list of chunks
42
+ for column_chunks in zip(*self.data):
43
+ # Concatenate chunks for each column
44
+ if isinstance(column_chunks[0], np.ndarray):
45
+ column = np.concatenate(column_chunks)
46
+ elif isinstance(column_chunks[0], pd.Categorical):
47
+ column = union_categoricals(column_chunks)
48
+ else:
49
+ column = tuple(chain.from_iterable(column_chunks))
50
+ data.append(column)
51
+ else:
52
+ data = self.data
53
+
54
+ if self.with_column_types:
55
+ return data, self.columns_with_types
56
+ else:
57
+ return data
58
+
59
+
60
+ class NumpyProgressQueryResult(NumpyQueryResult):
61
+ """
62
+ Stores query result and progress information from multiple blocks.
63
+ Provides iteration over query progress.
64
+ """
65
+
66
+ def __init__(self, *args, **kwargs):
67
+ self.progress_totals = Progress()
68
+
69
+ super(NumpyProgressQueryResult, self).__init__(*args, **kwargs)
70
+
71
+ def __iter__(self):
72
+ return self
73
+
74
+ def __next__(self):
75
+ while True:
76
+ packet = next(self.packet_generator)
77
+ progress_packet = getattr(packet, 'progress', None)
78
+ if progress_packet:
79
+ self.progress_totals.increment(progress_packet)
80
+ return (
81
+ self.progress_totals.rows, self.progress_totals.total_rows
82
+ )
83
+ else:
84
+ self.store(packet)
85
+
86
+ def get_result(self):
87
+ # Read all progress packets.
88
+ for _ in self:
89
+ pass
90
+
91
+ return super(NumpyProgressQueryResult, self).get_result()
92
+
93
+
94
+ class NumpyIterQueryResult(object):
95
+ """
96
+ Provides iteration over returned data by chunks (streaming by chunks).
97
+ """
98
+
99
+ def __init__(
100
+ self, packet_generator,
101
+ with_column_types=False):
102
+ self.packet_generator = packet_generator
103
+ self.with_column_types = with_column_types
104
+
105
+ self.first_block = True
106
+ super(NumpyIterQueryResult, self).__init__()
107
+
108
+ def __iter__(self):
109
+ return self
110
+
111
+ def __next__(self):
112
+ packet = next(self.packet_generator)
113
+ block = getattr(packet, 'block', None)
114
+ if block is None:
115
+ return []
116
+
117
+ if self.first_block and self.with_column_types:
118
+ self.first_block = False
119
+ rv = [block.columns_with_types]
120
+ rv.extend(block.get_rows())
121
+ return rv
122
+ else:
123
+ return block.get_rows()
@@ -0,0 +1,43 @@
1
+
2
+ class OpenTelemetryTraceContext(object):
3
+ traceparent_tpl = 'xx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx-xx'
4
+ translation = str.maketrans('1234567890abcdef', 'xxxxxxxxxxxxxxxx')
5
+
6
+ def __init__(self, traceparent, tracestate):
7
+ # xx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx-xx
8
+ # ^ ^ ^ ^
9
+ # version trace_id span_id flags
10
+
11
+ self.trace_id = None # UUID
12
+ self.span_id = None # UInt64
13
+ self.tracestate = tracestate # String
14
+ self.trace_flags = None # UInt8
15
+
16
+ if traceparent is not None:
17
+ self.parse_traceparent(traceparent)
18
+
19
+ super(OpenTelemetryTraceContext, self).__init__()
20
+
21
+ def parse_traceparent(self, traceparent):
22
+ traceparent = traceparent.lower()
23
+
24
+ if len(traceparent) != len(self.traceparent_tpl):
25
+ raise ValueError('unexpected length {}, expected {}'.format(
26
+ len(traceparent), len(self.traceparent_tpl)
27
+ ))
28
+
29
+ if traceparent.translate(self.translation) != self.traceparent_tpl:
30
+ raise ValueError(
31
+ 'Malformed traceparant header: {}'.format(traceparent)
32
+ )
33
+
34
+ parts = traceparent.split('-')
35
+ version = int(parts[0], 16)
36
+ if version != 0:
37
+ raise ValueError(
38
+ 'unexpected version {}, expected 00'.format(parts[0])
39
+ )
40
+
41
+ self.trace_id = (int(parts[1][16:], 16) << 64) + int(parts[1][:16], 16)
42
+ self.span_id = int(parts[2], 16)
43
+ self.trace_flags = int(parts[3], 16)
@@ -1,32 +1,38 @@
1
- from . import defines
2
- from .varint import read_varint
3
-
4
-
5
- class Progress(object):
6
- def __init__(self):
7
- self.rows = 0
8
- self.bytes = 0
9
- self.total_rows = 0
10
- self.written_rows = 0
11
- self.written_bytes = 0
12
-
13
- super(Progress, self).__init__()
14
-
15
- def read(self, server_revision, fin):
16
- self.rows = read_varint(fin)
17
- self.bytes = read_varint(fin)
18
-
19
- revision = server_revision
20
- if revision >= defines.DBMS_MIN_REVISION_WITH_TOTAL_ROWS_IN_PROGRESS:
21
- self.total_rows = read_varint(fin)
22
-
23
- if revision >= defines.DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO:
24
- self.written_rows = read_varint(fin)
25
- self.written_bytes = read_varint(fin)
26
-
27
- def increment(self, another_progress):
28
- self.rows += another_progress.rows
29
- self.bytes += another_progress.bytes
30
- self.total_rows += another_progress.total_rows
31
- self.written_rows += another_progress.written_rows
32
- self.written_bytes += another_progress.written_bytes
1
+ from . import defines
2
+ from .varint import read_varint
3
+
4
+
5
+ class Progress(object):
6
+ def __init__(self):
7
+ self.rows = 0
8
+ self.bytes = 0
9
+ self.total_rows = 0
10
+ self.written_rows = 0
11
+ self.written_bytes = 0
12
+ self.elapsed_ns = 0
13
+
14
+ super(Progress, self).__init__()
15
+
16
+ def read(self, server_info, fin):
17
+ self.rows = read_varint(fin)
18
+ self.bytes = read_varint(fin)
19
+
20
+ revision = server_info.used_revision
21
+ if revision >= defines.DBMS_MIN_REVISION_WITH_TOTAL_ROWS_IN_PROGRESS:
22
+ self.total_rows = read_varint(fin)
23
+
24
+ if revision >= defines.DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO:
25
+ self.written_rows = read_varint(fin)
26
+ self.written_bytes = read_varint(fin)
27
+
28
+ if revision >= defines. \
29
+ DBMS_MIN_PROTOCOL_VERSION_WITH_SERVER_QUERY_TIME_IN_PROGRESS:
30
+ self.elapsed_ns = read_varint(fin)
31
+
32
+ def increment(self, another_progress):
33
+ self.rows += another_progress.rows
34
+ self.bytes += another_progress.bytes
35
+ self.total_rows += another_progress.total_rows
36
+ self.written_rows += another_progress.written_rows
37
+ self.written_bytes += another_progress.written_bytes
38
+ self.elapsed_ns += another_progress.elapsed_ns