Skip to content

Commit 9a2f6ae

Browse files
committed
fix: Fixed a bug where 'sender.new_buffer()' would return None.
1 parent 6cec56e commit 9a2f6ae

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/questdb/ingress.pyx

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ cdef class Buffer:
306306
* To see the contents, call ``str(buffer)``.
307307
"""
308308
cdef line_sender_buffer* _impl
309+
cdef size_t _init_capacity
310+
cdef size_t _max_name_len
309311
cdef object _row_complete_sender
310312

311313
def __cinit__(self, init_capacity: int=65536, max_name_len: int=127):
@@ -319,12 +321,33 @@ cdef class Buffer:
319321
cdef inline _cinit_impl(self, size_t init_capacity, size_t max_name_len):
320322
self._impl = line_sender_buffer_with_max_name_len(max_name_len)
321323
line_sender_buffer_reserve(self._impl, init_capacity)
324+
self._init_capacity = init_capacity
325+
self._max_name_len = max_name_len
322326
self._row_complete_sender = None
323327

324328
def __dealloc__(self):
325329
self._row_complete_sender = None
326330
line_sender_buffer_free(self._impl)
327331

332+
@property
333+
def init_capacity(self) -> int:
334+
"""
335+
The initial capacity of the buffer when first created.
336+
337+
This may grow over time, see ``capacity()``.
338+
"""
339+
return self._init_capacity
340+
341+
@property
342+
def max_name_len(self) -> int:
343+
"""Maximum length of a table or column name."""
344+
return self._max_name_len
345+
346+
@property
347+
def max_name_len(self) -> int:
348+
"""Maximum length of a table or column name."""
349+
return self._max_name_len
350+
328351
def reserve(self, additional: int):
329352
"""
330353
Ensure the buffer has at least `additional` bytes of future capacity.
@@ -770,8 +793,8 @@ cdef class Sender:
770793
cdef Buffer _buffer
771794
cdef bint _auto_flush_enabled
772795
cdef ssize_t _auto_flush_watermark
773-
cdef object _init_capacity
774-
cdef object _max_name_len
796+
cdef size_t _init_capacity
797+
cdef size_t _max_name_len
775798

776799
def __cinit__(
777800
self,
@@ -896,10 +919,20 @@ cdef class Sender:
896919
The buffer is set up with the configured `init_capacity` and
897920
`max_name_len`.
898921
"""
899-
self._buffer = Buffer(
922+
return Buffer(
900923
init_capacity=self._init_capacity,
901924
max_name_len=self._max_name_len)
902925

926+
@property
927+
def init_capacity(self) -> int:
928+
"""The initial capacity of the sender's internal buffer."""
929+
return self._init_capacity
930+
931+
@property
932+
def max_name_len(self) -> int:
933+
"""Maximum length of a table or column name."""
934+
return self._max_name_len
935+
903936
def connect(self):
904937
cdef line_sender_error* err = NULL
905938
if self._opts == NULL:

test/test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,18 @@ def test_dont_flush_on_exception(self):
254254
msgs = server.recv()
255255
self.assertEqual(msgs, [])
256256

257+
def test_new_buffer(self):
258+
sender = qi.Sender(
259+
host='localhost',
260+
port=9009,
261+
init_capacity=1024,
262+
max_name_len=10)
263+
buffer = sender.new_buffer()
264+
self.assertEqual(buffer.init_capacity, 1024)
265+
self.assertEqual(buffer.max_name_len, 10)
266+
self.assertEqual(buffer.init_capacity, sender.init_capacity)
267+
self.assertEqual(buffer.max_name_len, sender.max_name_len)
268+
257269

258270
if __name__ == '__main__':
259271
unittest.main()

0 commit comments

Comments
 (0)