singlestoredb 1.16.1__py3-none-any.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 (183) hide show
  1. singlestoredb/__init__.py +75 -0
  2. singlestoredb/ai/__init__.py +2 -0
  3. singlestoredb/ai/chat.py +139 -0
  4. singlestoredb/ai/embeddings.py +128 -0
  5. singlestoredb/alchemy/__init__.py +90 -0
  6. singlestoredb/apps/__init__.py +3 -0
  7. singlestoredb/apps/_cloud_functions.py +90 -0
  8. singlestoredb/apps/_config.py +72 -0
  9. singlestoredb/apps/_connection_info.py +18 -0
  10. singlestoredb/apps/_dashboards.py +47 -0
  11. singlestoredb/apps/_process.py +32 -0
  12. singlestoredb/apps/_python_udfs.py +100 -0
  13. singlestoredb/apps/_stdout_supress.py +30 -0
  14. singlestoredb/apps/_uvicorn_util.py +36 -0
  15. singlestoredb/auth.py +245 -0
  16. singlestoredb/config.py +484 -0
  17. singlestoredb/connection.py +1487 -0
  18. singlestoredb/converters.py +950 -0
  19. singlestoredb/docstring/__init__.py +33 -0
  20. singlestoredb/docstring/attrdoc.py +126 -0
  21. singlestoredb/docstring/common.py +230 -0
  22. singlestoredb/docstring/epydoc.py +267 -0
  23. singlestoredb/docstring/google.py +412 -0
  24. singlestoredb/docstring/numpydoc.py +562 -0
  25. singlestoredb/docstring/parser.py +100 -0
  26. singlestoredb/docstring/py.typed +1 -0
  27. singlestoredb/docstring/rest.py +256 -0
  28. singlestoredb/docstring/tests/__init__.py +1 -0
  29. singlestoredb/docstring/tests/_pydoctor.py +21 -0
  30. singlestoredb/docstring/tests/test_epydoc.py +729 -0
  31. singlestoredb/docstring/tests/test_google.py +1007 -0
  32. singlestoredb/docstring/tests/test_numpydoc.py +1100 -0
  33. singlestoredb/docstring/tests/test_parse_from_object.py +109 -0
  34. singlestoredb/docstring/tests/test_parser.py +248 -0
  35. singlestoredb/docstring/tests/test_rest.py +547 -0
  36. singlestoredb/docstring/tests/test_util.py +70 -0
  37. singlestoredb/docstring/util.py +141 -0
  38. singlestoredb/exceptions.py +120 -0
  39. singlestoredb/functions/__init__.py +16 -0
  40. singlestoredb/functions/decorator.py +201 -0
  41. singlestoredb/functions/dtypes.py +1793 -0
  42. singlestoredb/functions/ext/__init__.py +1 -0
  43. singlestoredb/functions/ext/arrow.py +375 -0
  44. singlestoredb/functions/ext/asgi.py +2133 -0
  45. singlestoredb/functions/ext/json.py +420 -0
  46. singlestoredb/functions/ext/mmap.py +413 -0
  47. singlestoredb/functions/ext/rowdat_1.py +724 -0
  48. singlestoredb/functions/ext/timer.py +89 -0
  49. singlestoredb/functions/ext/utils.py +218 -0
  50. singlestoredb/functions/signature.py +1578 -0
  51. singlestoredb/functions/typing/__init__.py +41 -0
  52. singlestoredb/functions/typing/numpy.py +20 -0
  53. singlestoredb/functions/typing/pandas.py +2 -0
  54. singlestoredb/functions/typing/polars.py +2 -0
  55. singlestoredb/functions/typing/pyarrow.py +2 -0
  56. singlestoredb/functions/utils.py +421 -0
  57. singlestoredb/fusion/__init__.py +11 -0
  58. singlestoredb/fusion/graphql.py +213 -0
  59. singlestoredb/fusion/handler.py +916 -0
  60. singlestoredb/fusion/handlers/__init__.py +0 -0
  61. singlestoredb/fusion/handlers/export.py +525 -0
  62. singlestoredb/fusion/handlers/files.py +690 -0
  63. singlestoredb/fusion/handlers/job.py +660 -0
  64. singlestoredb/fusion/handlers/models.py +250 -0
  65. singlestoredb/fusion/handlers/stage.py +502 -0
  66. singlestoredb/fusion/handlers/utils.py +324 -0
  67. singlestoredb/fusion/handlers/workspace.py +956 -0
  68. singlestoredb/fusion/registry.py +249 -0
  69. singlestoredb/fusion/result.py +399 -0
  70. singlestoredb/http/__init__.py +27 -0
  71. singlestoredb/http/connection.py +1267 -0
  72. singlestoredb/magics/__init__.py +34 -0
  73. singlestoredb/magics/run_personal.py +137 -0
  74. singlestoredb/magics/run_shared.py +134 -0
  75. singlestoredb/management/__init__.py +9 -0
  76. singlestoredb/management/billing_usage.py +148 -0
  77. singlestoredb/management/cluster.py +462 -0
  78. singlestoredb/management/export.py +295 -0
  79. singlestoredb/management/files.py +1102 -0
  80. singlestoredb/management/inference_api.py +105 -0
  81. singlestoredb/management/job.py +887 -0
  82. singlestoredb/management/manager.py +373 -0
  83. singlestoredb/management/organization.py +226 -0
  84. singlestoredb/management/region.py +169 -0
  85. singlestoredb/management/utils.py +423 -0
  86. singlestoredb/management/workspace.py +1927 -0
  87. singlestoredb/mysql/__init__.py +177 -0
  88. singlestoredb/mysql/_auth.py +298 -0
  89. singlestoredb/mysql/charset.py +214 -0
  90. singlestoredb/mysql/connection.py +2032 -0
  91. singlestoredb/mysql/constants/CLIENT.py +38 -0
  92. singlestoredb/mysql/constants/COMMAND.py +32 -0
  93. singlestoredb/mysql/constants/CR.py +78 -0
  94. singlestoredb/mysql/constants/ER.py +474 -0
  95. singlestoredb/mysql/constants/EXTENDED_TYPE.py +3 -0
  96. singlestoredb/mysql/constants/FIELD_TYPE.py +48 -0
  97. singlestoredb/mysql/constants/FLAG.py +15 -0
  98. singlestoredb/mysql/constants/SERVER_STATUS.py +10 -0
  99. singlestoredb/mysql/constants/VECTOR_TYPE.py +6 -0
  100. singlestoredb/mysql/constants/__init__.py +0 -0
  101. singlestoredb/mysql/converters.py +271 -0
  102. singlestoredb/mysql/cursors.py +896 -0
  103. singlestoredb/mysql/err.py +92 -0
  104. singlestoredb/mysql/optionfile.py +20 -0
  105. singlestoredb/mysql/protocol.py +450 -0
  106. singlestoredb/mysql/tests/__init__.py +19 -0
  107. singlestoredb/mysql/tests/base.py +126 -0
  108. singlestoredb/mysql/tests/conftest.py +37 -0
  109. singlestoredb/mysql/tests/test_DictCursor.py +132 -0
  110. singlestoredb/mysql/tests/test_SSCursor.py +141 -0
  111. singlestoredb/mysql/tests/test_basic.py +452 -0
  112. singlestoredb/mysql/tests/test_connection.py +851 -0
  113. singlestoredb/mysql/tests/test_converters.py +58 -0
  114. singlestoredb/mysql/tests/test_cursor.py +141 -0
  115. singlestoredb/mysql/tests/test_err.py +16 -0
  116. singlestoredb/mysql/tests/test_issues.py +514 -0
  117. singlestoredb/mysql/tests/test_load_local.py +75 -0
  118. singlestoredb/mysql/tests/test_nextset.py +88 -0
  119. singlestoredb/mysql/tests/test_optionfile.py +27 -0
  120. singlestoredb/mysql/tests/thirdparty/__init__.py +6 -0
  121. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/__init__.py +9 -0
  122. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/capabilities.py +323 -0
  123. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/dbapi20.py +865 -0
  124. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_capabilities.py +110 -0
  125. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_dbapi20.py +224 -0
  126. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_nonstandard.py +101 -0
  127. singlestoredb/mysql/times.py +23 -0
  128. singlestoredb/notebook/__init__.py +16 -0
  129. singlestoredb/notebook/_objects.py +213 -0
  130. singlestoredb/notebook/_portal.py +352 -0
  131. singlestoredb/py.typed +0 -0
  132. singlestoredb/pytest.py +352 -0
  133. singlestoredb/server/__init__.py +0 -0
  134. singlestoredb/server/docker.py +452 -0
  135. singlestoredb/server/free_tier.py +267 -0
  136. singlestoredb/tests/__init__.py +0 -0
  137. singlestoredb/tests/alltypes.sql +307 -0
  138. singlestoredb/tests/alltypes_no_nulls.sql +208 -0
  139. singlestoredb/tests/empty.sql +0 -0
  140. singlestoredb/tests/ext_funcs/__init__.py +702 -0
  141. singlestoredb/tests/local_infile.csv +3 -0
  142. singlestoredb/tests/test.ipynb +18 -0
  143. singlestoredb/tests/test.sql +680 -0
  144. singlestoredb/tests/test2.ipynb +18 -0
  145. singlestoredb/tests/test2.sql +1 -0
  146. singlestoredb/tests/test_basics.py +1332 -0
  147. singlestoredb/tests/test_config.py +318 -0
  148. singlestoredb/tests/test_connection.py +3103 -0
  149. singlestoredb/tests/test_dbapi.py +27 -0
  150. singlestoredb/tests/test_exceptions.py +45 -0
  151. singlestoredb/tests/test_ext_func.py +1472 -0
  152. singlestoredb/tests/test_ext_func_data.py +1101 -0
  153. singlestoredb/tests/test_fusion.py +1527 -0
  154. singlestoredb/tests/test_http.py +288 -0
  155. singlestoredb/tests/test_management.py +1599 -0
  156. singlestoredb/tests/test_plugin.py +33 -0
  157. singlestoredb/tests/test_results.py +171 -0
  158. singlestoredb/tests/test_types.py +132 -0
  159. singlestoredb/tests/test_udf.py +737 -0
  160. singlestoredb/tests/test_udf_returns.py +459 -0
  161. singlestoredb/tests/test_vectorstore.py +51 -0
  162. singlestoredb/tests/test_xdict.py +333 -0
  163. singlestoredb/tests/utils.py +141 -0
  164. singlestoredb/types.py +373 -0
  165. singlestoredb/utils/__init__.py +0 -0
  166. singlestoredb/utils/config.py +950 -0
  167. singlestoredb/utils/convert_rows.py +69 -0
  168. singlestoredb/utils/debug.py +13 -0
  169. singlestoredb/utils/dtypes.py +205 -0
  170. singlestoredb/utils/events.py +65 -0
  171. singlestoredb/utils/mogrify.py +151 -0
  172. singlestoredb/utils/results.py +585 -0
  173. singlestoredb/utils/xdict.py +425 -0
  174. singlestoredb/vectorstore.py +192 -0
  175. singlestoredb/warnings.py +5 -0
  176. singlestoredb-1.16.1.dist-info/METADATA +165 -0
  177. singlestoredb-1.16.1.dist-info/RECORD +183 -0
  178. singlestoredb-1.16.1.dist-info/WHEEL +5 -0
  179. singlestoredb-1.16.1.dist-info/entry_points.txt +2 -0
  180. singlestoredb-1.16.1.dist-info/licenses/LICENSE +201 -0
  181. singlestoredb-1.16.1.dist-info/top_level.txt +3 -0
  182. sqlx/__init__.py +4 -0
  183. sqlx/magic.py +113 -0
@@ -0,0 +1,702 @@
1
+ #!/usr/bin/env python3
2
+ # mypy: disable-error-code="type-arg"
3
+ import asyncio
4
+ import time
5
+ import typing
6
+ from typing import List
7
+ from typing import NamedTuple
8
+ from typing import Optional
9
+ from typing import Tuple
10
+
11
+ import numpy as np
12
+
13
+ import singlestoredb.functions.dtypes as dt
14
+ from singlestoredb.functions import Masked
15
+ from singlestoredb.functions import Table
16
+ from singlestoredb.functions import udf
17
+ from singlestoredb.functions.dtypes import BIGINT
18
+ from singlestoredb.functions.dtypes import BLOB
19
+ from singlestoredb.functions.dtypes import DOUBLE
20
+ from singlestoredb.functions.dtypes import FLOAT
21
+ from singlestoredb.functions.dtypes import MEDIUMINT
22
+ from singlestoredb.functions.dtypes import SMALLINT
23
+ from singlestoredb.functions.dtypes import TEXT
24
+ from singlestoredb.functions.dtypes import TINYINT
25
+ from singlestoredb.functions.typing import numpy as npt
26
+ from singlestoredb.functions.typing import pandas as pdt
27
+ from singlestoredb.functions.typing import polars as plt
28
+ from singlestoredb.functions.typing import pyarrow as pat
29
+
30
+
31
+ @udf
32
+ def doc_test(x: int, y: float) -> int:
33
+ """
34
+ A simple function to test the decorator and documentation.
35
+
36
+ Parameters
37
+ ----------
38
+ x : int
39
+ An integer to be multiplied by 2.
40
+ y : float
41
+ A float that is not used in the computation.
42
+
43
+ Examples
44
+ --------
45
+ Basic usage of the function:
46
+ >>> doc_test(
47
+ ... 3, 4.5,
48
+ ... )
49
+ 6
50
+
51
+ Another example with different values:
52
+ >>> doc_test(5, 2.0)
53
+ 10
54
+
55
+ SQL Example
56
+ sql> SELECT doc_test(3, 4.5);
57
+ 6
58
+
59
+ Final text
60
+
61
+ Returns
62
+ -------
63
+ int
64
+ The input integer multiplied by 2.
65
+
66
+ """
67
+ return x * 2
68
+
69
+
70
+ @udf
71
+ def int_mult(x: int, y: int) -> int:
72
+ return x * y
73
+
74
+
75
+ @udf
76
+ def double_mult(x: float, y: float) -> float:
77
+ return x * y
78
+
79
+
80
+ @udf(timeout=2)
81
+ def timeout_double_mult(x: float, y: float) -> float:
82
+ time.sleep(5)
83
+ return x * y
84
+
85
+
86
+ @udf
87
+ async def async_double_mult(x: float, y: float) -> float:
88
+ return x * y
89
+
90
+
91
+ @udf(timeout=2)
92
+ async def async_timeout_double_mult(x: float, y: float) -> float:
93
+ await asyncio.sleep(5)
94
+ return x * y
95
+
96
+
97
+ @udf(
98
+ args=[DOUBLE(nullable=False), DOUBLE(nullable=False)],
99
+ returns=DOUBLE(nullable=False),
100
+ )
101
+ def pandas_double_mult(x: pdt.Series, y: pdt.Series) -> pdt.Series:
102
+ return x * y
103
+
104
+
105
+ @udf
106
+ def numpy_double_mult(
107
+ x: npt.Float64Array,
108
+ y: npt.Float64Array,
109
+ ) -> npt.Float64Array:
110
+ return x * y
111
+
112
+
113
+ @udf
114
+ async def async_numpy_double_mult(
115
+ x: npt.Float64Array,
116
+ y: npt.Float64Array,
117
+ ) -> npt.Float64Array:
118
+ return x * y
119
+
120
+
121
+ @udf(
122
+ args=[DOUBLE(nullable=False), DOUBLE(nullable=False)],
123
+ returns=DOUBLE(nullable=False),
124
+ )
125
+ def arrow_double_mult(x: pat.Array, y: pat.Array) -> pat.Array:
126
+ import pyarrow.compute as pc
127
+ return pc.multiply(x, y)
128
+
129
+
130
+ @udf(
131
+ args=[DOUBLE(nullable=False), DOUBLE(nullable=False)],
132
+ returns=DOUBLE(nullable=False),
133
+ )
134
+ def polars_double_mult(x: plt.Series, y: plt.Series) -> plt.Series:
135
+ return x * y
136
+
137
+
138
+ @udf
139
+ def nullable_double_mult(x: Optional[float], y: Optional[float]) -> Optional[float]:
140
+ if x is None or y is None:
141
+ return None
142
+ return x * y
143
+
144
+
145
+ @udf(args=[FLOAT(nullable=False), FLOAT(nullable=False)], returns=FLOAT(nullable=False))
146
+ def float_mult(x: float, y: float) -> float:
147
+ return x * y
148
+
149
+
150
+ @udf(args=[FLOAT(nullable=True), FLOAT(nullable=True)], returns=FLOAT(nullable=True))
151
+ def nullable_float_mult(x: Optional[float], y: Optional[float]) -> Optional[float]:
152
+ if x is None or y is None:
153
+ return None
154
+ return x * y
155
+
156
+
157
+ #
158
+ # TINYINT
159
+ #
160
+
161
+ tinyint_udf = udf(
162
+ args=[TINYINT(nullable=False), TINYINT(nullable=False)],
163
+ returns=TINYINT(nullable=False),
164
+ )
165
+
166
+
167
+ @tinyint_udf
168
+ def tinyint_mult(x: Optional[int], y: Optional[int]) -> Optional[int]:
169
+ if x is None or y is None:
170
+ return None
171
+ return x * y
172
+
173
+
174
+ @tinyint_udf
175
+ def pandas_tinyint_mult(x: pdt.Series, y: pdt.Series) -> pdt.Series:
176
+ return x * y
177
+
178
+
179
+ @tinyint_udf
180
+ def polars_tinyint_mult(x: plt.Series, y: plt.Series) -> plt.Series:
181
+ return x * y
182
+
183
+
184
+ @tinyint_udf
185
+ def numpy_tinyint_mult(x: np.ndarray, y: np.ndarray) -> np.ndarray:
186
+ return x * y
187
+
188
+
189
+ @tinyint_udf
190
+ def arrow_tinyint_mult(x: pat.Array, y: pat.Array) -> pat.Array:
191
+ import pyarrow.compute as pc
192
+ return pc.multiply(x, y)
193
+
194
+ #
195
+ # SMALLINT
196
+ #
197
+
198
+
199
+ smallint_udf = udf(
200
+ args=[SMALLINT(nullable=False), SMALLINT(nullable=False)],
201
+ returns=SMALLINT(nullable=False),
202
+ )
203
+
204
+
205
+ @smallint_udf
206
+ def smallint_mult(x: Optional[int], y: Optional[int]) -> Optional[int]:
207
+ if x is None or y is None:
208
+ return None
209
+ return x * y
210
+
211
+
212
+ @smallint_udf
213
+ def pandas_smallint_mult(x: pdt.Series, y: pdt.Series) -> pdt.Series:
214
+ return x * y
215
+
216
+
217
+ @smallint_udf
218
+ def polars_smallint_mult(x: plt.Series, y: plt.Series) -> plt.Series:
219
+ return x * y
220
+
221
+
222
+ @smallint_udf
223
+ def numpy_smallint_mult(x: np.ndarray, y: np.ndarray) -> np.ndarray:
224
+ return x * y
225
+
226
+
227
+ @smallint_udf
228
+ def arrow_smallint_mult(x: pat.Array, y: pat.Array) -> pat.Array:
229
+ import pyarrow.compute as pc
230
+ return pc.multiply(x, y)
231
+
232
+
233
+ #
234
+ # MEDIUMINT
235
+ #
236
+
237
+
238
+ mediumint_udf = udf(
239
+ args=[MEDIUMINT(nullable=False), MEDIUMINT(nullable=False)],
240
+ returns=MEDIUMINT(nullable=False),
241
+ )
242
+
243
+
244
+ @mediumint_udf
245
+ def mediumint_mult(x: Optional[int], y: Optional[int]) -> Optional[int]:
246
+ if x is None or y is None:
247
+ return None
248
+ return x * y
249
+
250
+
251
+ @mediumint_udf
252
+ def pandas_mediumint_mult(x: pdt.Series, y: pdt.Series) -> pdt.Series:
253
+ return x * y
254
+
255
+
256
+ @mediumint_udf
257
+ def polars_mediumint_mult(x: plt.Series, y: plt.Series) -> plt.Series:
258
+ return x * y
259
+
260
+
261
+ @mediumint_udf
262
+ def numpy_mediumint_mult(x: np.ndarray, y: np.ndarray) -> np.ndarray:
263
+ return x * y
264
+
265
+
266
+ @mediumint_udf
267
+ def arrow_mediumint_mult(x: pat.Array, y: pat.Array) -> pat.Array:
268
+ import pyarrow.compute as pc
269
+ return pc.multiply(x, y)
270
+
271
+
272
+ #
273
+ # BIGINT
274
+ #
275
+
276
+
277
+ bigint_udf = udf(
278
+ args=[BIGINT(nullable=False), BIGINT(nullable=False)],
279
+ returns=BIGINT(nullable=False),
280
+ )
281
+
282
+
283
+ @bigint_udf
284
+ def bigint_mult(x: Optional[int], y: Optional[int]) -> Optional[int]:
285
+ if x is None or y is None:
286
+ return None
287
+ return x * y
288
+
289
+
290
+ @bigint_udf
291
+ def pandas_bigint_mult(x: pdt.Series, y: pdt.Series) -> pdt.Series:
292
+ return x * y
293
+
294
+
295
+ @bigint_udf
296
+ def polars_bigint_mult(x: plt.Series, y: plt.Series) -> plt.Series:
297
+ return x * y
298
+
299
+
300
+ @bigint_udf
301
+ def numpy_bigint_mult(x: np.ndarray, y: np.ndarray) -> np.ndarray:
302
+ return x * y
303
+
304
+
305
+ @bigint_udf
306
+ def arrow_bigint_mult(x: pat.Array, y: pat.Array) -> pat.Array:
307
+ import pyarrow.compute as pc
308
+ return pc.multiply(x, y)
309
+
310
+
311
+ #
312
+ # NULLABLE TINYINT
313
+ #
314
+
315
+
316
+ nullable_tinyint_udf = udf(
317
+ args=[TINYINT(nullable=True), TINYINT(nullable=True)],
318
+ returns=TINYINT(nullable=True),
319
+ )
320
+
321
+
322
+ @nullable_tinyint_udf
323
+ def nullable_tinyint_mult(x: Optional[int], y: Optional[int]) -> Optional[int]:
324
+ if x is None or y is None:
325
+ return None
326
+ return x * y
327
+
328
+
329
+ @nullable_tinyint_udf
330
+ def pandas_nullable_tinyint_mult(x: pdt.Series, y: pdt.Series) -> pdt.Series:
331
+ return x * y
332
+
333
+
334
+ @nullable_tinyint_udf
335
+ def polars_nullable_tinyint_mult(x: plt.Series, y: plt.Series) -> plt.Series:
336
+ return x * y
337
+
338
+
339
+ @nullable_tinyint_udf
340
+ def numpy_nullable_tinyint_mult(x: np.ndarray, y: np.ndarray) -> np.ndarray:
341
+ return x * y
342
+
343
+
344
+ @nullable_tinyint_udf
345
+ def arrow_nullable_tinyint_mult(x: pat.Array, y: pat.Array) -> pat.Array:
346
+ import pyarrow.compute as pc
347
+ return pc.multiply(x, y)
348
+
349
+ #
350
+ # NULLABLE SMALLINT
351
+ #
352
+
353
+
354
+ nullable_smallint_udf = udf(
355
+ args=[SMALLINT(nullable=True), SMALLINT(nullable=True)],
356
+ returns=SMALLINT(nullable=True),
357
+ )
358
+
359
+
360
+ @nullable_smallint_udf
361
+ def nullable_smallint_mult(x: Optional[int], y: Optional[int]) -> Optional[int]:
362
+ if x is None or y is None:
363
+ return None
364
+ return x * y
365
+
366
+
367
+ @nullable_smallint_udf
368
+ def pandas_nullable_smallint_mult(x: pdt.Series, y: pdt.Series) -> pdt.Series:
369
+ return x * y
370
+
371
+
372
+ @nullable_smallint_udf
373
+ def polars_nullable_smallint_mult(x: plt.Series, y: plt.Series) -> plt.Series:
374
+ return x * y
375
+
376
+
377
+ @nullable_smallint_udf
378
+ def numpy_nullable_smallint_mult(x: np.ndarray, y: np.ndarray) -> np.ndarray:
379
+ return x * y
380
+
381
+
382
+ @nullable_smallint_udf
383
+ def arrow_nullable_smallint_mult(x: pat.Array, y: pat.Array) -> pat.Array:
384
+ import pyarrow.compute as pc
385
+ return pc.multiply(x, y)
386
+
387
+
388
+ #
389
+ # NULLABLE MEDIUMINT
390
+ #
391
+
392
+
393
+ nullable_mediumint_udf = udf(
394
+ args=[MEDIUMINT(nullable=True), MEDIUMINT(nullable=True)],
395
+ returns=MEDIUMINT(nullable=True),
396
+ )
397
+
398
+
399
+ @nullable_mediumint_udf
400
+ def nullable_mediumint_mult(x: Optional[int], y: Optional[int]) -> Optional[int]:
401
+ if x is None or y is None:
402
+ return None
403
+ return x * y
404
+
405
+
406
+ @nullable_mediumint_udf
407
+ def pandas_nullable_mediumint_mult(x: pdt.Series, y: pdt.Series) -> pdt.Series:
408
+ return x * y
409
+
410
+
411
+ @nullable_mediumint_udf
412
+ def polars_nullable_mediumint_mult(x: plt.Series, y: plt.Series) -> plt.Series:
413
+ return x * y
414
+
415
+
416
+ @nullable_mediumint_udf
417
+ def numpy_nullable_mediumint_mult(x: np.ndarray, y: np.ndarray) -> np.ndarray:
418
+ return x * y
419
+
420
+
421
+ @nullable_mediumint_udf
422
+ def arrow_nullable_mediumint_mult(x: pat.Array, y: pat.Array) -> pat.Array:
423
+ import pyarrow.compute as pc
424
+ return pc.multiply(x, y)
425
+
426
+
427
+ #
428
+ # NULLABLE BIGINT
429
+ #
430
+
431
+
432
+ nullable_bigint_udf = udf(
433
+ args=[BIGINT(nullable=True), BIGINT(nullable=True)],
434
+ returns=BIGINT(nullable=True),
435
+ )
436
+
437
+
438
+ @nullable_bigint_udf
439
+ def nullable_bigint_mult(x: Optional[int], y: Optional[int]) -> Optional[int]:
440
+ if x is None or y is None:
441
+ return None
442
+ return x * y
443
+
444
+
445
+ @nullable_bigint_udf
446
+ def pandas_nullable_bigint_mult(x: pdt.Series, y: pdt.Series) -> pdt.Series:
447
+ return x * y
448
+
449
+
450
+ @nullable_bigint_udf
451
+ def polars_nullable_bigint_mult(x: plt.Series, y: plt.Series) -> plt.Series:
452
+ return x * y
453
+
454
+
455
+ @nullable_bigint_udf
456
+ def numpy_nullable_bigint_mult(x: np.ndarray, y: np.ndarray) -> np.ndarray:
457
+ return x * y
458
+
459
+
460
+ @nullable_bigint_udf
461
+ def arrow_nullable_bigint_mult(x: pat.Array, y: pat.Array) -> pat.Array:
462
+ import pyarrow.compute as pc
463
+ return pc.multiply(x, y)
464
+
465
+
466
+ @udf
467
+ def nullable_int_mult(x: Optional[int], y: Optional[int]) -> Optional[int]:
468
+ if x is None or y is None:
469
+ return None
470
+ return x * y
471
+
472
+
473
+ @udf
474
+ def string_mult(x: str, times: int) -> str:
475
+ return x * times
476
+
477
+
478
+ @udf(args=[TEXT(nullable=False), BIGINT(nullable=False)], returns=TEXT(nullable=False))
479
+ def pandas_string_mult(x: pdt.Series, times: pdt.Series) -> pdt.Series:
480
+ return x * times
481
+
482
+
483
+ @udf
484
+ def numpy_string_mult(
485
+ x: npt.NDArray[np.str_], times: npt.NDArray[np.int_],
486
+ ) -> npt.NDArray[np.str_]:
487
+ return x * times
488
+
489
+
490
+ # @udf.polars
491
+ # def polars_string_mult(x: str, times: int) -> str:
492
+ # print(type(x), x, type(times), times)
493
+ # return x * times
494
+
495
+
496
+ # @udf.arrow
497
+ # def arrow_string_mult(x: str, times: int) -> str:
498
+ # print(type(x), x, type(times), times)
499
+ # import pyarrow.compute as pc
500
+ # return pc.multiply(x, times)
501
+ # return x * times
502
+
503
+
504
+ @udf
505
+ def nullable_string_mult(x: Optional[str], times: Optional[int]) -> Optional[str]:
506
+ if x is None or times is None:
507
+ return None
508
+ return x * times
509
+
510
+
511
+ @udf(
512
+ args=[TINYINT(nullable=True), TINYINT(nullable=True)],
513
+ returns=TINYINT(nullable=True),
514
+ )
515
+ def pandas_nullable_tinyint_mult_with_masks(
516
+ x: Masked[pdt.Series], y: Masked[pdt.Series],
517
+ ) -> Masked[pdt.Series]:
518
+ x_data, x_nulls = x
519
+ y_data, y_nulls = y
520
+ return Masked(x_data * y_data, x_nulls | y_nulls)
521
+
522
+
523
+ @udf
524
+ def numpy_nullable_tinyint_mult_with_masks(
525
+ x: Masked[npt.NDArray[np.int8]], y: Masked[npt.NDArray[np.int8]],
526
+ ) -> Masked[npt.NDArray[np.int8]]:
527
+ x_data, x_nulls = x
528
+ y_data, y_nulls = y
529
+ return Masked(x_data * y_data, x_nulls | y_nulls)
530
+
531
+
532
+ @udf(
533
+ args=[TINYINT(nullable=True), TINYINT(nullable=True)],
534
+ returns=TINYINT(nullable=True),
535
+ )
536
+ def polars_nullable_tinyint_mult_with_masks(
537
+ x: Masked[plt.Series], y: Masked[plt.Series],
538
+ ) -> Masked[plt.Series]:
539
+ x_data, x_nulls = x
540
+ y_data, y_nulls = y
541
+ return Masked(x_data * y_data, x_nulls | y_nulls)
542
+
543
+
544
+ @udf(
545
+ args=[TINYINT(nullable=True), TINYINT(nullable=True)],
546
+ returns=TINYINT(nullable=True),
547
+ )
548
+ def arrow_nullable_tinyint_mult_with_masks(
549
+ x: Masked[pat.Array], y: Masked[pat.Array],
550
+ ) -> Masked[pat.Array]:
551
+ import pyarrow.compute as pc
552
+ x_data, x_nulls = x
553
+ y_data, y_nulls = y
554
+ return Masked(pc.multiply(x_data, y_data), pc.or_(x_nulls, y_nulls))
555
+
556
+
557
+ @udf(returns=[TEXT(nullable=False, name='res')])
558
+ def numpy_fixed_strings() -> Table[npt.StrArray]:
559
+ out = np.array(
560
+ [
561
+ 'hello',
562
+ 'hi there 😜',
563
+ '😜 bye',
564
+ ], dtype=np.str_,
565
+ )
566
+ assert str(out.dtype) == '<U10'
567
+ return Table(out)
568
+
569
+
570
+ @udf(returns=[TEXT(nullable=False, name='res'), TINYINT(nullable=False, name='res2')])
571
+ def numpy_fixed_strings_2() -> Table[npt.StrArray, npt.Int8Array]:
572
+ out = np.array(
573
+ [
574
+ 'hello',
575
+ 'hi there 😜',
576
+ '😜 bye',
577
+ ], dtype=np.str_,
578
+ )
579
+ assert str(out.dtype) == '<U10'
580
+ return Table(out, out)
581
+
582
+
583
+ @udf(returns=[BLOB(nullable=False, name='res')])
584
+ def numpy_fixed_binary() -> Table[npt.BytesArray]:
585
+ out = np.array(
586
+ [
587
+ 'hello'.encode('utf8'),
588
+ 'hi there 😜'.encode('utf8'),
589
+ '😜 bye'.encode('utf8'),
590
+ ], dtype=np.bytes_,
591
+ )
592
+ assert str(out.dtype) == '|S13'
593
+ return Table(out)
594
+
595
+
596
+ @udf
597
+ def no_args_no_return_value() -> None:
598
+ pass
599
+
600
+
601
+ @udf
602
+ def table_function(n: int) -> Table[List[int]]:
603
+ return Table([10] * n)
604
+
605
+
606
+ @udf
607
+ async def async_table_function(n: int) -> Table[List[int]]:
608
+ return Table([10] * n)
609
+
610
+
611
+ @udf(
612
+ returns=[
613
+ dt.INT(name='c_int', nullable=False),
614
+ dt.DOUBLE(name='c_float', nullable=False),
615
+ dt.TEXT(name='c_str', nullable=False),
616
+ ],
617
+ )
618
+ def table_function_tuple(n: int) -> Table[List[Tuple[int, float, str]]]:
619
+ return Table([(10, 10.0, 'ten')] * n)
620
+
621
+
622
+ class MyTable(NamedTuple):
623
+ c_int: int
624
+ c_float: float
625
+ c_str: str
626
+
627
+
628
+ @udf
629
+ def table_function_struct(n: int) -> Table[List[MyTable]]:
630
+ return Table([MyTable(10, 10.0, 'ten')] * n)
631
+
632
+
633
+ @udf
634
+ def vec_function(
635
+ x: npt.Float64Array, y: npt.Float64Array,
636
+ ) -> npt.Float64Array:
637
+ return x * y
638
+
639
+
640
+ class VecInputs(typing.NamedTuple):
641
+ x: np.int8
642
+ y: np.int8
643
+
644
+
645
+ class VecOutputs(typing.NamedTuple):
646
+ res: np.int16
647
+
648
+
649
+ @udf(args=VecInputs, returns=VecOutputs)
650
+ def vec_function_ints(
651
+ x: npt.IntArray, y: npt.IntArray,
652
+ ) -> npt.IntArray:
653
+ return x * y
654
+
655
+
656
+ class DFOutputs(typing.NamedTuple):
657
+ res: np.int16
658
+ res2: np.float64
659
+
660
+
661
+ @udf(args=VecInputs, returns=DFOutputs)
662
+ def vec_function_df(
663
+ x: npt.IntArray, y: npt.IntArray,
664
+ ) -> Table[pdt.DataFrame]:
665
+ return pdt.DataFrame(dict(res=[1, 2, 3], res2=[1.1, 2.2, 3.3]))
666
+
667
+
668
+ @udf(args=VecInputs, returns=DFOutputs)
669
+ async def async_vec_function_df(
670
+ x: npt.IntArray, y: npt.IntArray,
671
+ ) -> Table[pdt.DataFrame]:
672
+ return pdt.DataFrame(dict(res=[1, 2, 3], res2=[1.1, 2.2, 3.3]))
673
+
674
+
675
+ class MaskOutputs(typing.NamedTuple):
676
+ res: Optional[np.int16]
677
+
678
+
679
+ @udf(args=VecInputs, returns=MaskOutputs)
680
+ def vec_function_ints_masked(
681
+ x: Masked[npt.IntArray], y: Masked[npt.IntArray],
682
+ ) -> Table[Masked[npt.IntArray]]:
683
+ x_data, x_nulls = x
684
+ y_data, y_nulls = y
685
+ return Table(Masked(x_data * y_data, x_nulls | y_nulls))
686
+
687
+
688
+ class MaskOutputs2(typing.NamedTuple):
689
+ res: Optional[np.int16]
690
+ res2: Optional[np.int16]
691
+
692
+
693
+ @udf(args=VecInputs, returns=MaskOutputs2)
694
+ def vec_function_ints_masked2(
695
+ x: Masked[npt.IntArray], y: Masked[npt.IntArray],
696
+ ) -> Table[Masked[npt.IntArray], Masked[npt.IntArray]]:
697
+ x_data, x_nulls = x
698
+ y_data, y_nulls = y
699
+ return Table(
700
+ Masked(x_data * y_data, x_nulls | y_nulls),
701
+ Masked(x_data * y_data, x_nulls | y_nulls),
702
+ )
@@ -0,0 +1,3 @@
1
+ John,Doe,34
2
+ Sandy,Smith,24
3
+ Patty,Jones,57
@@ -0,0 +1,18 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "Test Notebook"
8
+ ]
9
+ }
10
+ ],
11
+ "metadata": {
12
+ "language_info": {
13
+ "name": "python"
14
+ }
15
+ },
16
+ "nbformat": 4,
17
+ "nbformat_minor": 2
18
+ }