Skip to content

Commit ecd2435

Browse files
committed
Add medium int range checks; add organization field to WorkspaceManager
1 parent 73a7596 commit ecd2435

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

docs/src/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ create new ones.
171171
:toctree: generated/
172172

173173
WorkspaceManager
174+
WorkspaceManager.organization
174175
WorkspaceManager.workspace_groups
175176
WorkspaceManager.regions
176177
WorkspaceManager.create_workspace_group

singlestoredb/functions/ext/rowdat_1.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
ft.FLOAT: 4,
8383
ft.DOUBLE: 8,
8484
}
85+
medium_int_types = set([ft.INT24, -ft.INT24])
8586
int_types = set([
8687
ft.TINY, -ft.TINY, ft.SHORT, -ft.SHORT, ft.INT24, -ft.INT24,
8788
ft.LONG, -ft.LONG, ft.LONGLONG, -ft.LONGLONG,
@@ -369,6 +370,16 @@ def _dump(
369370
out.write(struct.pack(numeric_formats[rtype], default))
370371
else:
371372
if rtype in int_types:
373+
if rtype == ft.INT24:
374+
if int(value) > 8388607 or int(value) < -8388608:
375+
raise ValueError(
376+
'value is outside range of MEDIUMINT',
377+
)
378+
elif rtype == -ft.INT24:
379+
if int(value) > 16777215 or int(value) < 0:
380+
raise ValueError(
381+
'value is outside range of UNSIGNED MEDIUMINT',
382+
)
372383
out.write(struct.pack(numeric_formats[rtype], int(value)))
373384
else:
374385
out.write(struct.pack(numeric_formats[rtype], float(value)))
@@ -437,6 +448,16 @@ def _dump_vectors(
437448
out.write(struct.pack(numeric_formats[rtype], default))
438449
else:
439450
if rtype in int_types:
451+
if rtype == ft.INT24:
452+
if int(value) > 8388607 or int(value) < -8388608:
453+
raise ValueError(
454+
'value is outside range of MEDIUMINT',
455+
)
456+
elif rtype == -ft.INT24:
457+
if int(value) > 16777215 or int(value) < 0:
458+
raise ValueError(
459+
'value is outside range of UNSIGNED MEDIUMINT',
460+
)
440461
out.write(struct.pack(numeric_formats[rtype], int(value)))
441462
else:
442463
out.write(struct.pack(numeric_formats[rtype], float(value)))
@@ -697,18 +718,16 @@ def _dump_arrow_accel(
697718

698719

699720
if not has_accel:
700-
_load_accel = _load
701-
_dump_accel = _dump
702-
load = _load
703-
dump = _dump
704-
load_pandas = _load_pandas
705-
dump_pandas = _dump_pandas
706-
load_numpy = _load_numpy
707-
dump_numpy = _dump_numpy
708-
load_arrow = _load_arrow
709-
dump_arrow = _dump_arrow
710-
load_polars = _load_polars
711-
dump_polars = _dump_polars
721+
load = _load_accel = _load
722+
dump = _dump_accel = _dump
723+
load_pandas = _load_pandas_accel = _load_pandas # noqa: F811
724+
dump_pandas = _dump_pandas_accel = _dump_pandas # noqa: F811
725+
load_numpy = _load_numpy_accel = _load_numpy # noqa: F811
726+
dump_numpy = _dump_numpy_accel = _dump_numpy # noqa: F811
727+
load_arrow = _load_arrow_accel = _load_arrow # noqa: F811
728+
dump_arrow = _dump_arrow_accel = _dump_arrow # noqa: F811
729+
load_polars = _load_polars_accel = _load_polars # noqa: F811
730+
dump_polars = _dump_polars_accel = _dump_polars # noqa: F811
712731

713732
else:
714733
_load_accel = _singlestoredb_accel.load_rowdat_1

singlestoredb/management/workspace.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,14 @@ def from_dict(
12221222
out._manager = manager
12231223
return out
12241224

1225+
@property
1226+
def organization(self) -> Organization:
1227+
if self._manager is None:
1228+
raise ManagementError(
1229+
msg='No workspace manager is associated with this object.',
1230+
)
1231+
return self._manager.organization
1232+
12251233
@property
12261234
def stage(self) -> Stage:
12271235
"""Stage manager."""
@@ -1479,6 +1487,11 @@ def organizations(self) -> Organizations:
14791487
"""Return the organizations."""
14801488
return Organizations(self)
14811489

1490+
@property
1491+
def organization(self) -> Organization:
1492+
""" Return the current organization."""
1493+
return self.organizations.current
1494+
14821495
@property
14831496
def billing(self) -> Billing:
14841497
"""Return the current billing information."""

singlestoredb/tests/test_ext_func_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
],
241241
[
242242
100, 100, 32700, 32800, 2147483600, 2147483800, 100.0,
243-
100.0, 100, 100, 2147483600, 2147483800, 'bye', b'bye',
243+
100.0, 100, 100, 8388600, 16777200, 'bye', b'bye',
244244
],
245245
[
246246
120, 130, 254, 254, 254, 254, 3.14159, 3.14159,

0 commit comments

Comments
 (0)