singlestoredb 1.13.0__tar.gz → 1.13.1__tar.gz
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.
Potentially problematic release.
This version of singlestoredb might be problematic. Click here for more details.
- {singlestoredb-1.13.0/singlestoredb.egg-info → singlestoredb-1.13.1}/PKG-INFO +1 -1
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/setup.cfg +1 -1
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/__init__.py +1 -1
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/ai/__init__.py +1 -0
- singlestoredb-1.13.1/singlestoredb/ai/chat.py +26 -0
- singlestoredb-1.13.1/singlestoredb/ai/embeddings.py +27 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/functions/__init__.py +4 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/functions/ext/asgi.py +188 -94
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/functions/utils.py +171 -92
- singlestoredb-1.13.1/singlestoredb/management/inference_api.py +101 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/management/organization.py +17 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test_management.py +5 -5
- {singlestoredb-1.13.0 → singlestoredb-1.13.1/singlestoredb.egg-info}/PKG-INFO +1 -1
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb.egg-info/SOURCES.txt +2 -0
- singlestoredb-1.13.0/singlestoredb/ai/embeddings.py +0 -24
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/LICENSE +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/README.md +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/accel.c +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/setup.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/alchemy/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/apps/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/apps/_cloud_functions.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/apps/_config.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/apps/_connection_info.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/apps/_dashboards.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/apps/_process.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/apps/_python_udfs.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/apps/_stdout_supress.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/apps/_uvicorn_util.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/auth.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/config.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/connection.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/converters.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/exceptions.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/functions/decorator.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/functions/dtypes.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/functions/ext/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/functions/ext/arrow.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/functions/ext/json.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/functions/ext/mmap.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/functions/ext/rowdat_1.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/functions/ext/utils.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/functions/signature.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/functions/typing.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/fusion/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/fusion/graphql.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/fusion/handler.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/fusion/handlers/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/fusion/handlers/export.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/fusion/handlers/files.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/fusion/handlers/job.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/fusion/handlers/models.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/fusion/handlers/stage.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/fusion/handlers/utils.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/fusion/handlers/workspace.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/fusion/registry.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/fusion/result.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/http/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/http/connection.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/magics/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/magics/run_personal.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/magics/run_shared.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/management/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/management/billing_usage.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/management/cluster.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/management/export.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/management/files.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/management/job.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/management/manager.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/management/region.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/management/utils.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/management/workspace.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/_auth.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/charset.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/connection.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/constants/CLIENT.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/constants/COMMAND.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/constants/CR.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/constants/ER.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/constants/EXTENDED_TYPE.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/constants/FIELD_TYPE.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/constants/FLAG.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/constants/SERVER_STATUS.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/constants/VECTOR_TYPE.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/constants/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/converters.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/cursors.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/err.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/optionfile.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/protocol.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/base.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/conftest.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/test_DictCursor.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/test_SSCursor.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/test_basic.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/test_connection.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/test_converters.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/test_cursor.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/test_err.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/test_issues.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/test_load_local.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/test_nextset.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/test_optionfile.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/thirdparty/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/thirdparty/test_MySQLdb/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/thirdparty/test_MySQLdb/capabilities.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/thirdparty/test_MySQLdb/dbapi20.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_capabilities.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_dbapi20.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_nonstandard.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/mysql/times.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/notebook/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/notebook/_objects.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/notebook/_portal.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/py.typed +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/pytest.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/server/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/server/docker.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/server/free_tier.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/empty.sql +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/ext_funcs/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/local_infile.csv +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test.ipynb +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test.sql +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test2.ipynb +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test2.sql +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test_basics.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test_config.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test_connection.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test_dbapi.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test_exceptions.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test_ext_func.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test_ext_func_data.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test_fusion.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test_http.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test_plugin.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test_results.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test_types.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test_udf.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test_udf_returns.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/test_xdict.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/tests/utils.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/types.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/utils/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/utils/config.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/utils/convert_rows.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/utils/debug.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/utils/dtypes.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/utils/events.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/utils/mogrify.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/utils/results.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb/utils/xdict.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb.egg-info/dependency_links.txt +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb.egg-info/entry_points.txt +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb.egg-info/requires.txt +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/singlestoredb.egg-info/top_level.txt +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/sqlx/__init__.py +0 -0
- {singlestoredb-1.13.0 → singlestoredb-1.13.1}/sqlx/magic.py +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from singlestoredb.fusion.handlers.utils import get_workspace_manager
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
from langchain_openai import ChatOpenAI
|
|
8
|
+
except ImportError:
|
|
9
|
+
raise ImportError(
|
|
10
|
+
'Could not import langchain_openai python package. '
|
|
11
|
+
'Please install it with `pip install langchain_openai`.',
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class SingleStoreChatOpenAI(ChatOpenAI):
|
|
16
|
+
def __init__(self, model_name: str, **kwargs: Any):
|
|
17
|
+
inference_api_manger = (
|
|
18
|
+
get_workspace_manager().organizations.current.inference_apis
|
|
19
|
+
)
|
|
20
|
+
info = inference_api_manger.get(model_name=model_name)
|
|
21
|
+
super().__init__(
|
|
22
|
+
base_url=info.connection_url,
|
|
23
|
+
api_key=os.environ.get('SINGLESTOREDB_USER_TOKEN'),
|
|
24
|
+
model=model_name,
|
|
25
|
+
**kwargs,
|
|
26
|
+
)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from singlestoredb.fusion.handlers.utils import get_workspace_manager
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
from langchain_openai import OpenAIEmbeddings
|
|
8
|
+
except ImportError:
|
|
9
|
+
raise ImportError(
|
|
10
|
+
'Could not import langchain_openai python package. '
|
|
11
|
+
'Please install it with `pip install langchain_openai`.',
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class SingleStoreEmbeddings(OpenAIEmbeddings):
|
|
16
|
+
|
|
17
|
+
def __init__(self, model_name: str, **kwargs: Any):
|
|
18
|
+
inference_api_manger = (
|
|
19
|
+
get_workspace_manager().organizations.current.inference_apis
|
|
20
|
+
)
|
|
21
|
+
info = inference_api_manger.get(model_name=model_name)
|
|
22
|
+
super().__init__(
|
|
23
|
+
base_url=info.connection_url,
|
|
24
|
+
api_key=os.environ.get('SINGLESTOREDB_USER_TOKEN'),
|
|
25
|
+
model=model_name,
|
|
26
|
+
**kwargs,
|
|
27
|
+
)
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
from .decorator import udf # noqa: F401
|
|
2
2
|
from .typing import Masked # noqa: F401
|
|
3
3
|
from .typing import Table # noqa: F401
|
|
4
|
+
from .utils import pack_vector # noqa: F401
|
|
5
|
+
from .utils import pack_vectors # noqa: F401
|
|
6
|
+
from .utils import unpack_vector # noqa: F401
|
|
7
|
+
from .utils import unpack_vectors # noqa: F401
|
|
4
8
|
from .utils import VectorTypes
|
|
5
9
|
|
|
6
10
|
|
|
@@ -246,6 +246,192 @@ def get_masked_params(func: Callable[..., Any]) -> List[bool]:
|
|
|
246
246
|
return [typing.get_origin(x.annotation) is Masked for x in params.values()]
|
|
247
247
|
|
|
248
248
|
|
|
249
|
+
def build_tuple(x: Any) -> Any:
|
|
250
|
+
"""Convert object to tuple."""
|
|
251
|
+
return tuple(x) if isinstance(x, Masked) else (x, None)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def build_udf_endpoint(
|
|
255
|
+
func: Callable[..., Any],
|
|
256
|
+
returns_data_format: str,
|
|
257
|
+
) -> Callable[..., Any]:
|
|
258
|
+
"""
|
|
259
|
+
Build a UDF endpoint for scalar / list types (row-based).
|
|
260
|
+
|
|
261
|
+
Parameters
|
|
262
|
+
----------
|
|
263
|
+
func : Callable
|
|
264
|
+
The function to call as the endpoint
|
|
265
|
+
returns_data_format : str
|
|
266
|
+
The format of the return values
|
|
267
|
+
|
|
268
|
+
Returns
|
|
269
|
+
-------
|
|
270
|
+
Callable
|
|
271
|
+
The function endpoint
|
|
272
|
+
|
|
273
|
+
"""
|
|
274
|
+
if returns_data_format in ['scalar', 'list']:
|
|
275
|
+
|
|
276
|
+
async def do_func(
|
|
277
|
+
row_ids: Sequence[int],
|
|
278
|
+
rows: Sequence[Sequence[Any]],
|
|
279
|
+
) -> Tuple[Sequence[int], List[Tuple[Any, ...]]]:
|
|
280
|
+
'''Call function on given rows of data.'''
|
|
281
|
+
return row_ids, [as_tuple(x) for x in zip(func_map(func, rows))]
|
|
282
|
+
|
|
283
|
+
return do_func
|
|
284
|
+
|
|
285
|
+
return build_vector_udf_endpoint(func, returns_data_format)
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def build_vector_udf_endpoint(
|
|
289
|
+
func: Callable[..., Any],
|
|
290
|
+
returns_data_format: str,
|
|
291
|
+
) -> Callable[..., Any]:
|
|
292
|
+
"""
|
|
293
|
+
Build a UDF endpoint for vector formats (column-based).
|
|
294
|
+
|
|
295
|
+
Parameters
|
|
296
|
+
----------
|
|
297
|
+
func : Callable
|
|
298
|
+
The function to call as the endpoint
|
|
299
|
+
returns_data_format : str
|
|
300
|
+
The format of the return values
|
|
301
|
+
|
|
302
|
+
Returns
|
|
303
|
+
-------
|
|
304
|
+
Callable
|
|
305
|
+
The function endpoint
|
|
306
|
+
|
|
307
|
+
"""
|
|
308
|
+
masks = get_masked_params(func)
|
|
309
|
+
array_cls = get_array_class(returns_data_format)
|
|
310
|
+
|
|
311
|
+
async def do_func(
|
|
312
|
+
row_ids: Sequence[int],
|
|
313
|
+
cols: Sequence[Tuple[Sequence[Any], Optional[Sequence[bool]]]],
|
|
314
|
+
) -> Tuple[
|
|
315
|
+
Sequence[int],
|
|
316
|
+
List[Tuple[Sequence[Any], Optional[Sequence[bool]]]],
|
|
317
|
+
]:
|
|
318
|
+
'''Call function on given columns of data.'''
|
|
319
|
+
row_ids = array_cls(row_ids)
|
|
320
|
+
|
|
321
|
+
# Call the function with `cols` as the function parameters
|
|
322
|
+
if cols and cols[0]:
|
|
323
|
+
out = func(*[x if m else x[0] for x, m in zip(cols, masks)])
|
|
324
|
+
else:
|
|
325
|
+
out = func()
|
|
326
|
+
|
|
327
|
+
# Single masked value
|
|
328
|
+
if isinstance(out, Masked):
|
|
329
|
+
return row_ids, [tuple(out)]
|
|
330
|
+
|
|
331
|
+
# Multiple return values
|
|
332
|
+
if isinstance(out, tuple):
|
|
333
|
+
return row_ids, [build_tuple(x) for x in out]
|
|
334
|
+
|
|
335
|
+
# Single return value
|
|
336
|
+
return row_ids, [(out, None)]
|
|
337
|
+
|
|
338
|
+
return do_func
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def build_tvf_endpoint(
|
|
342
|
+
func: Callable[..., Any],
|
|
343
|
+
returns_data_format: str,
|
|
344
|
+
) -> Callable[..., Any]:
|
|
345
|
+
"""
|
|
346
|
+
Build a TVF endpoint for scalar / list types (row-based).
|
|
347
|
+
|
|
348
|
+
Parameters
|
|
349
|
+
----------
|
|
350
|
+
func : Callable
|
|
351
|
+
The function to call as the endpoint
|
|
352
|
+
returns_data_format : str
|
|
353
|
+
The format of the return values
|
|
354
|
+
|
|
355
|
+
Returns
|
|
356
|
+
-------
|
|
357
|
+
Callable
|
|
358
|
+
The function endpoint
|
|
359
|
+
|
|
360
|
+
"""
|
|
361
|
+
if returns_data_format in ['scalar', 'list']:
|
|
362
|
+
|
|
363
|
+
async def do_func(
|
|
364
|
+
row_ids: Sequence[int],
|
|
365
|
+
rows: Sequence[Sequence[Any]],
|
|
366
|
+
) -> Tuple[Sequence[int], List[Tuple[Any, ...]]]:
|
|
367
|
+
'''Call function on given rows of data.'''
|
|
368
|
+
out_ids: List[int] = []
|
|
369
|
+
out = []
|
|
370
|
+
# Call function on each row of data
|
|
371
|
+
for i, res in zip(row_ids, func_map(func, rows)):
|
|
372
|
+
out.extend(as_list_of_tuples(res))
|
|
373
|
+
out_ids.extend([row_ids[i]] * (len(out)-len(out_ids)))
|
|
374
|
+
return out_ids, out
|
|
375
|
+
|
|
376
|
+
return do_func
|
|
377
|
+
|
|
378
|
+
return build_vector_tvf_endpoint(func, returns_data_format)
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def build_vector_tvf_endpoint(
|
|
382
|
+
func: Callable[..., Any],
|
|
383
|
+
returns_data_format: str,
|
|
384
|
+
) -> Callable[..., Any]:
|
|
385
|
+
"""
|
|
386
|
+
Build a TVF endpoint for vector formats (column-based).
|
|
387
|
+
|
|
388
|
+
Parameters
|
|
389
|
+
----------
|
|
390
|
+
func : Callable
|
|
391
|
+
The function to call as the endpoint
|
|
392
|
+
returns_data_format : str
|
|
393
|
+
The format of the return values
|
|
394
|
+
|
|
395
|
+
Returns
|
|
396
|
+
-------
|
|
397
|
+
Callable
|
|
398
|
+
The function endpoint
|
|
399
|
+
|
|
400
|
+
"""
|
|
401
|
+
masks = get_masked_params(func)
|
|
402
|
+
array_cls = get_array_class(returns_data_format)
|
|
403
|
+
|
|
404
|
+
async def do_func(
|
|
405
|
+
row_ids: Sequence[int],
|
|
406
|
+
cols: Sequence[Tuple[Sequence[Any], Optional[Sequence[bool]]]],
|
|
407
|
+
) -> Tuple[
|
|
408
|
+
Sequence[int],
|
|
409
|
+
List[Tuple[Sequence[Any], Optional[Sequence[bool]]]],
|
|
410
|
+
]:
|
|
411
|
+
'''Call function on given columns of data.'''
|
|
412
|
+
# NOTE: There is no way to determine which row ID belongs to
|
|
413
|
+
# each result row, so we just have to use the same
|
|
414
|
+
# row ID for all rows in the result.
|
|
415
|
+
|
|
416
|
+
# Call function on each column of data
|
|
417
|
+
if cols and cols[0]:
|
|
418
|
+
res = get_dataframe_columns(
|
|
419
|
+
func(*[x if m else x[0] for x, m in zip(cols, masks)]),
|
|
420
|
+
)
|
|
421
|
+
else:
|
|
422
|
+
res = get_dataframe_columns(func())
|
|
423
|
+
|
|
424
|
+
# Generate row IDs
|
|
425
|
+
if isinstance(res[0], Masked):
|
|
426
|
+
row_ids = array_cls([row_ids[0]] * len(res[0][0]))
|
|
427
|
+
else:
|
|
428
|
+
row_ids = array_cls([row_ids[0]] * len(res[0]))
|
|
429
|
+
|
|
430
|
+
return row_ids, [build_tuple(x) for x in res]
|
|
431
|
+
|
|
432
|
+
return do_func
|
|
433
|
+
|
|
434
|
+
|
|
249
435
|
def make_func(
|
|
250
436
|
name: str,
|
|
251
437
|
func: Callable[..., Any],
|
|
@@ -273,102 +459,10 @@ def make_func(
|
|
|
273
459
|
args_data_format = sig.get('args_data_format', 'scalar')
|
|
274
460
|
returns_data_format = sig.get('returns_data_format', 'scalar')
|
|
275
461
|
|
|
276
|
-
masks = get_masked_params(func)
|
|
277
|
-
|
|
278
462
|
if function_type == 'tvf':
|
|
279
|
-
|
|
280
|
-
if returns_data_format in ['scalar', 'list']:
|
|
281
|
-
async def do_func(
|
|
282
|
-
row_ids: Sequence[int],
|
|
283
|
-
rows: Sequence[Sequence[Any]],
|
|
284
|
-
) -> Tuple[Sequence[int], List[Tuple[Any, ...]]]:
|
|
285
|
-
'''Call function on given rows of data.'''
|
|
286
|
-
out_ids: List[int] = []
|
|
287
|
-
out = []
|
|
288
|
-
# Call function on each row of data
|
|
289
|
-
for i, res in zip(row_ids, func_map(func, rows)):
|
|
290
|
-
out.extend(as_list_of_tuples(res))
|
|
291
|
-
out_ids.extend([row_ids[i]] * (len(out)-len(out_ids)))
|
|
292
|
-
return out_ids, out
|
|
293
|
-
|
|
294
|
-
# Vector formats (column-based)
|
|
295
|
-
else:
|
|
296
|
-
array_cls = get_array_class(returns_data_format)
|
|
297
|
-
|
|
298
|
-
async def do_func( # type: ignore
|
|
299
|
-
row_ids: Sequence[int],
|
|
300
|
-
cols: Sequence[Tuple[Sequence[Any], Optional[Sequence[bool]]]],
|
|
301
|
-
) -> Tuple[
|
|
302
|
-
Sequence[int],
|
|
303
|
-
List[Tuple[Sequence[Any], Optional[Sequence[bool]]]],
|
|
304
|
-
]:
|
|
305
|
-
'''Call function on given cols of data.'''
|
|
306
|
-
# NOTE: There is no way to determine which row ID belongs to
|
|
307
|
-
# each result row, so we just have to use the same
|
|
308
|
-
# row ID for all rows in the result.
|
|
309
|
-
|
|
310
|
-
def build_tuple(x: Any) -> Any:
|
|
311
|
-
return tuple(x) if isinstance(x, Masked) else (x, None)
|
|
312
|
-
|
|
313
|
-
# Call function on each column of data
|
|
314
|
-
if cols and cols[0]:
|
|
315
|
-
res = get_dataframe_columns(
|
|
316
|
-
func(*[x if m else x[0] for x, m in zip(cols, masks)]),
|
|
317
|
-
)
|
|
318
|
-
else:
|
|
319
|
-
res = get_dataframe_columns(func())
|
|
320
|
-
|
|
321
|
-
# Generate row IDs
|
|
322
|
-
if isinstance(res[0], Masked):
|
|
323
|
-
row_ids = array_cls([row_ids[0]] * len(res[0][0]))
|
|
324
|
-
else:
|
|
325
|
-
row_ids = array_cls([row_ids[0]] * len(res[0]))
|
|
326
|
-
|
|
327
|
-
return row_ids, [build_tuple(x) for x in res]
|
|
328
|
-
|
|
463
|
+
do_func = build_tvf_endpoint(func, returns_data_format)
|
|
329
464
|
else:
|
|
330
|
-
|
|
331
|
-
if returns_data_format in ['scalar', 'list']:
|
|
332
|
-
async def do_func(
|
|
333
|
-
row_ids: Sequence[int],
|
|
334
|
-
rows: Sequence[Sequence[Any]],
|
|
335
|
-
) -> Tuple[Sequence[int], List[Tuple[Any, ...]]]:
|
|
336
|
-
'''Call function on given rows of data.'''
|
|
337
|
-
return row_ids, [as_tuple(x) for x in zip(func_map(func, rows))]
|
|
338
|
-
|
|
339
|
-
# Vector formats (column-based)
|
|
340
|
-
else:
|
|
341
|
-
array_cls = get_array_class(returns_data_format)
|
|
342
|
-
|
|
343
|
-
async def do_func( # type: ignore
|
|
344
|
-
row_ids: Sequence[int],
|
|
345
|
-
cols: Sequence[Tuple[Sequence[Any], Optional[Sequence[bool]]]],
|
|
346
|
-
) -> Tuple[
|
|
347
|
-
Sequence[int],
|
|
348
|
-
List[Tuple[Sequence[Any], Optional[Sequence[bool]]]],
|
|
349
|
-
]:
|
|
350
|
-
'''Call function on given cols of data.'''
|
|
351
|
-
row_ids = array_cls(row_ids)
|
|
352
|
-
|
|
353
|
-
def build_tuple(x: Any) -> Any:
|
|
354
|
-
return tuple(x) if isinstance(x, Masked) else (x, None)
|
|
355
|
-
|
|
356
|
-
# Call the function with `cols` as the function parameters
|
|
357
|
-
if cols and cols[0]:
|
|
358
|
-
out = func(*[x if m else x[0] for x, m in zip(cols, masks)])
|
|
359
|
-
else:
|
|
360
|
-
out = func()
|
|
361
|
-
|
|
362
|
-
# Single masked value
|
|
363
|
-
if isinstance(out, Masked):
|
|
364
|
-
return row_ids, [tuple(out)]
|
|
365
|
-
|
|
366
|
-
# Multiple return values
|
|
367
|
-
if isinstance(out, tuple):
|
|
368
|
-
return row_ids, [build_tuple(x) for x in out]
|
|
369
|
-
|
|
370
|
-
# Single return value
|
|
371
|
-
return row_ids, [(out, None)]
|
|
465
|
+
do_func = build_udf_endpoint(func, returns_data_format)
|
|
372
466
|
|
|
373
467
|
do_func.__name__ = name
|
|
374
468
|
do_func.__doc__ = func.__doc__
|