omnata-plugin-runtime 0.5.7a152__tar.gz → 0.5.7a153__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {omnata_plugin_runtime-0.5.7a152 → omnata_plugin_runtime-0.5.7a153}/PKG-INFO +1 -1
- {omnata_plugin_runtime-0.5.7a152 → omnata_plugin_runtime-0.5.7a153}/pyproject.toml +1 -1
- {omnata_plugin_runtime-0.5.7a152 → omnata_plugin_runtime-0.5.7a153}/src/omnata_plugin_runtime/omnata_plugin.py +38 -90
- {omnata_plugin_runtime-0.5.7a152 → omnata_plugin_runtime-0.5.7a153}/LICENSE +0 -0
- {omnata_plugin_runtime-0.5.7a152 → omnata_plugin_runtime-0.5.7a153}/README.md +0 -0
- {omnata_plugin_runtime-0.5.7a152 → omnata_plugin_runtime-0.5.7a153}/src/omnata_plugin_runtime/__init__.py +0 -0
- {omnata_plugin_runtime-0.5.7a152 → omnata_plugin_runtime-0.5.7a153}/src/omnata_plugin_runtime/api.py +0 -0
- {omnata_plugin_runtime-0.5.7a152 → omnata_plugin_runtime-0.5.7a153}/src/omnata_plugin_runtime/configuration.py +0 -0
- {omnata_plugin_runtime-0.5.7a152 → omnata_plugin_runtime-0.5.7a153}/src/omnata_plugin_runtime/forms.py +0 -0
- {omnata_plugin_runtime-0.5.7a152 → omnata_plugin_runtime-0.5.7a153}/src/omnata_plugin_runtime/logging.py +0 -0
- {omnata_plugin_runtime-0.5.7a152 → omnata_plugin_runtime-0.5.7a153}/src/omnata_plugin_runtime/plugin_entrypoints.py +0 -0
- {omnata_plugin_runtime-0.5.7a152 → omnata_plugin_runtime-0.5.7a153}/src/omnata_plugin_runtime/rate_limiting.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
[tool.poetry]
|
2
2
|
name = "omnata-plugin-runtime"
|
3
|
-
version = "0.5.7-
|
3
|
+
version = "0.5.7-a153"
|
4
4
|
description = "Classes and common runtime components for building and running Omnata Plugins"
|
5
5
|
authors = ["James Weakley <james.weakley@omnata.com>"]
|
6
6
|
readme = "README.md"
|
@@ -39,7 +39,6 @@ import jinja2
|
|
39
39
|
import pandas
|
40
40
|
from pydantic_core import to_jsonable_python
|
41
41
|
from pydantic import Field, TypeAdapter, ValidationError, create_model, root_validator, BaseModel
|
42
|
-
from pydantic.dataclasses import dataclass
|
43
42
|
from dateutil.parser import parse
|
44
43
|
from jinja2 import Environment
|
45
44
|
from snowflake.connector.pandas_tools import write_pandas
|
@@ -2231,8 +2230,7 @@ def get_nested_value(nested_dict:Dict, keys:List[str]):
|
|
2231
2230
|
return reduce(lambda d, key: d.get(key) if isinstance(d, dict) else None, keys, nested_dict)
|
2232
2231
|
|
2233
2232
|
|
2234
|
-
|
2235
|
-
class SnowflakeFunctionParameter:
|
2233
|
+
class SnowflakeFunctionParameter(BaseModel):
|
2236
2234
|
"""
|
2237
2235
|
Represents a parameter for a Snowflake UDF or UDTF
|
2238
2236
|
"""
|
@@ -2246,8 +2244,7 @@ class SnowflakeFunctionParameter:
|
|
2246
2244
|
return f"{self.name} {self.data_type} default {self.default_value_clause}"
|
2247
2245
|
return f"{self.name} {self.data_type}"
|
2248
2246
|
|
2249
|
-
|
2250
|
-
class SnowflakeUDTFResultColumn:
|
2247
|
+
class SnowflakeUDTFResultColumn(BaseModel):
|
2251
2248
|
"""
|
2252
2249
|
Represents a result column for a Snowflake UDTF
|
2253
2250
|
"""
|
@@ -2256,49 +2253,21 @@ class SnowflakeUDTFResultColumn:
|
|
2256
2253
|
def __str__(self):
|
2257
2254
|
return f"{self.name} {self.data_type}"
|
2258
2255
|
|
2259
|
-
|
2260
|
-
class PythonUDTFDefinition:
|
2256
|
+
class UDTFDefinition(BaseModel):
|
2261
2257
|
"""
|
2262
2258
|
The information needed by the plugin uploader to put a Python UDTF definition into the setup script.
|
2263
2259
|
Do not use this class directly in plugins, instead use the omnata_udtf decorator.
|
2264
2260
|
"""
|
2265
|
-
name: str
|
2266
|
-
|
2267
|
-
|
2268
|
-
|
2269
|
-
|
2270
|
-
|
2271
|
-
|
2272
|
-
|
2273
|
-
|
2274
|
-
|
2275
|
-
table_result_columns = ', '.join([f"{col.name} {col.data_type}" for col in self.result_columns])
|
2276
|
-
packages_str = ', '.join([f"'{p}'" for p in self.packages])
|
2277
|
-
return f"""CREATE OR REPLACE FUNCTION UDFS.{self.name}({param_str})
|
2278
|
-
RETURNS TABLE({table_result_columns})
|
2279
|
-
LANGUAGE PYTHON
|
2280
|
-
RUNTIME_VERSION=3.10
|
2281
|
-
COMMENT = $${self.description}$$
|
2282
|
-
PACKAGES = ({packages_str})
|
2283
|
-
IMPORTS = ('/app.zip')
|
2284
|
-
HANDLER='{self.handler}';
|
2285
|
-
"""
|
2286
|
-
|
2287
|
-
@dataclass
|
2288
|
-
class JavaUDTFDefinition:
|
2289
|
-
"""
|
2290
|
-
The information needed by the plugin uploader to put a Java UDTF definition into the setup script.
|
2291
|
-
These are created directly in python, since we don't want the omnata cli to need to do any Java reflection.
|
2292
|
-
Any .jar files placed in the udf_direct_imports directory will be uploaded to the stage and can be
|
2293
|
-
added to the imports parameter as (e.g.) '/my_jar.jar'.
|
2294
|
-
"""
|
2295
|
-
name: str
|
2296
|
-
description: str
|
2297
|
-
params: List[SnowflakeFunctionParameter]
|
2298
|
-
result_columns: List[SnowflakeUDTFResultColumn]
|
2299
|
-
packages: List[str]
|
2300
|
-
imports: List[str]
|
2301
|
-
handler: str
|
2261
|
+
name: str = Field(..., title="The name of the UDTF")
|
2262
|
+
language: Literal['python','java'] = Field(..., title="The language of the UDF")
|
2263
|
+
runtime_version: str = Field(..., title="The runtime version of the UDF (language dependent)")
|
2264
|
+
description: str = Field(..., title="A description of the UDTF")
|
2265
|
+
params: List[SnowflakeFunctionParameter] = Field(..., title="The parameters of the UDTF")
|
2266
|
+
result_columns: List[SnowflakeUDTFResultColumn] = Field(..., title="The result columns of the UDTF")
|
2267
|
+
handler: str = Field(..., title="The handler class/function for the UDTF")
|
2268
|
+
expose_to_consumer: bool = Field(..., title="Whether the UDTF should be exposed to consumers")
|
2269
|
+
imports: Optional[List[str]] = Field(None, title="A list of imports required by the UDF")
|
2270
|
+
packages: Optional[List[str]] = Field(None, title="A list of packages required by the UDTF")
|
2302
2271
|
|
2303
2272
|
def __str__(self):
|
2304
2273
|
param_str = ', '.join([str(param) for param in self.params])
|
@@ -2307,54 +2276,29 @@ class JavaUDTFDefinition:
|
|
2307
2276
|
imports_str = ', '.join([f"'{i}'" for i in self.imports])
|
2308
2277
|
return f"""CREATE OR REPLACE FUNCTION UDFS.{self.name}({param_str})
|
2309
2278
|
RETURNS TABLE({table_result_columns})
|
2310
|
-
LANGUAGE
|
2311
|
-
RUNTIME_VERSION=
|
2279
|
+
LANGUAGE {self.language.upper()}
|
2280
|
+
RUNTIME_VERSION={self.runtime_version}
|
2312
2281
|
COMMENT = $${self.description}$$
|
2313
2282
|
PACKAGES = ({packages_str})
|
2314
2283
|
IMPORTS = ({imports_str})
|
2315
2284
|
HANDLER='{self.handler}';
|
2316
2285
|
"""
|
2317
2286
|
|
2318
|
-
|
2319
|
-
class PythonUDFDefinition:
|
2287
|
+
class UDFDefinition(BaseModel):
|
2320
2288
|
"""
|
2321
2289
|
The information needed by the plugin uploader to put a Python UDF definition into the setup script.
|
2322
2290
|
Do not use this class directly in plugins, instead use the omnata_udf decorator.
|
2323
2291
|
"""
|
2324
|
-
name: str
|
2325
|
-
|
2326
|
-
|
2327
|
-
|
2328
|
-
|
2329
|
-
|
2330
|
-
|
2331
|
-
|
2332
|
-
|
2333
|
-
|
2334
|
-
packages_str = ', '.join([f"'{p}'" for p in self.packages])
|
2335
|
-
return f"""CREATE OR REPLACE FUNCTION UDFS.{self.name}({param_str})
|
2336
|
-
RETURNS {self.result_data_type}
|
2337
|
-
LANGUAGE PYTHON
|
2338
|
-
RUNTIME_VERSION=3.10
|
2339
|
-
COMMENT = $${self.description}$$
|
2340
|
-
PACKAGES = ({packages_str})
|
2341
|
-
IMPORTS = ('/app.zip')
|
2342
|
-
HANDLER='{self.handler}';
|
2343
|
-
"""
|
2344
|
-
|
2345
|
-
@dataclass
|
2346
|
-
class JavaUDFDefinition:
|
2347
|
-
"""
|
2348
|
-
The information needed by the plugin uploader to put a java UDF definition into the setup script.
|
2349
|
-
"""
|
2350
|
-
name: str
|
2351
|
-
description: str
|
2352
|
-
params: List[SnowflakeFunctionParameter]
|
2353
|
-
result_data_type: str
|
2354
|
-
packages: List[str]
|
2355
|
-
imports: List[str]
|
2356
|
-
handler: str
|
2357
|
-
expose_to_consumer: bool
|
2292
|
+
name: str = Field(..., title="The name of the UDF")
|
2293
|
+
language: Literal['python','java'] = Field(..., title="The language of the UDF")
|
2294
|
+
runtime_version: str = Field(..., title="The runtime version of the UDF (language dependent)")
|
2295
|
+
description: str = Field(..., title="A description of the UDF")
|
2296
|
+
params: List[SnowflakeFunctionParameter] = Field(..., title="The parameters of the UDF")
|
2297
|
+
result_data_type: str = Field(..., title="The data type returned by the UDF")
|
2298
|
+
handler: str = Field(..., title="The handler class/function for the UDF")
|
2299
|
+
expose_to_consumer: bool = Field(..., title="Whether the UDF should be exposed to consumers")
|
2300
|
+
imports: Optional[List[str]] = Field(None, title="A list of imports required by the UDF")
|
2301
|
+
packages: Optional[List[str]] = Field(None, title="A list of packages required by the UDF")
|
2358
2302
|
|
2359
2303
|
def __str__(self):
|
2360
2304
|
param_str = ', '.join([str(param) for param in self.params])
|
@@ -2362,8 +2306,8 @@ class JavaUDFDefinition:
|
|
2362
2306
|
imports_str = ', '.join([f"'{i}'" for i in self.imports])
|
2363
2307
|
return f"""CREATE OR REPLACE FUNCTION UDFS.{self.name}({param_str})
|
2364
2308
|
RETURNS {self.result_data_type}
|
2365
|
-
LANGUAGE
|
2366
|
-
RUNTIME_VERSION=
|
2309
|
+
LANGUAGE {self.language.upper()}
|
2310
|
+
RUNTIME_VERSION={self.runtime_version}
|
2367
2311
|
COMMENT = $${self.description}$$
|
2368
2312
|
PACKAGES = ({packages_str})
|
2369
2313
|
IMPORTS = ({imports_str})
|
@@ -2447,7 +2391,7 @@ def omnata_udtf(
|
|
2447
2391
|
|
2448
2392
|
return class_decorator
|
2449
2393
|
|
2450
|
-
def find_udtf_classes(path:str = '.') -> List[
|
2394
|
+
def find_udtf_classes(path:str = '.') -> List[UDTFDefinition]:
|
2451
2395
|
"""
|
2452
2396
|
Finds all classes in the specified directory which have the 'omnata_udtf' decorator applied
|
2453
2397
|
"""
|
@@ -2466,15 +2410,16 @@ def find_udtf_classes(path:str = '.') -> List[PythonUDTFDefinition | JavaUDTFDef
|
|
2466
2410
|
for name, obj in inspect.getmembers(module, inspect.isclass):
|
2467
2411
|
# Check if the class has the specified attribute
|
2468
2412
|
if hasattr(obj, '_is_omnata_udtf'):
|
2469
|
-
matching_classes.append(
|
2413
|
+
matching_classes.append(UDTFDefinition(
|
2470
2414
|
name=obj._omnata_udtf_name,
|
2415
|
+
|
2471
2416
|
description=obj._omnata_udtf_description,
|
2472
2417
|
params=obj._omnata_udtf_params,
|
2473
2418
|
result_columns=obj._omnata_udtf_result_columns,
|
2474
2419
|
expose_to_consumer=obj._omnata_udtf_expose_to_consumer,
|
2475
2420
|
handler=obj.__module__+'.'+obj.__name__
|
2476
2421
|
))
|
2477
|
-
elif isinstance(obj,
|
2422
|
+
elif isinstance(obj, UDTFDefinition) and cast(UDTFDefinition,obj).language == 'java':
|
2478
2423
|
matching_classes.append(obj)
|
2479
2424
|
|
2480
2425
|
return matching_classes
|
@@ -2547,7 +2492,7 @@ def omnata_udf(
|
|
2547
2492
|
|
2548
2493
|
return decorator
|
2549
2494
|
|
2550
|
-
def find_udf_functions(path:str = '.') -> List[
|
2495
|
+
def find_udf_functions(path:str = '.') -> List[UDFDefinition]:
|
2551
2496
|
"""
|
2552
2497
|
Finds all functions in the specified directory which have the 'omnata_udf' decorator applied
|
2553
2498
|
"""
|
@@ -2566,8 +2511,11 @@ def find_udf_functions(path:str = '.') -> List[PythonUDFDefinition | JavaUDFDefi
|
|
2566
2511
|
for name, obj in inspect.getmembers(module, inspect.isfunction):
|
2567
2512
|
# Check if the class has the specified attribute
|
2568
2513
|
if hasattr(obj, '_is_omnata_udf'):
|
2569
|
-
matching_classes.append(
|
2514
|
+
matching_classes.append(UDFDefinition(
|
2570
2515
|
name=obj._omnata_udf_name,
|
2516
|
+
language='python',
|
2517
|
+
runtime_version='3.10',
|
2518
|
+
imports=['/app.zip'],
|
2571
2519
|
description=obj._omnata_udf_description,
|
2572
2520
|
params=obj._omnata_udf_params,
|
2573
2521
|
result_data_type=obj._omnata_udf_result_data_type,
|
@@ -2575,7 +2523,7 @@ def find_udf_functions(path:str = '.') -> List[PythonUDFDefinition | JavaUDFDefi
|
|
2575
2523
|
packages=[],
|
2576
2524
|
handler=obj.__module__+'.'+obj.__name__
|
2577
2525
|
))
|
2578
|
-
elif isinstance(obj,
|
2526
|
+
elif isinstance(obj, UDFDefinition) and cast(UDFDefinition,obj).language == 'java':
|
2579
2527
|
matching_classes.append(obj)
|
2580
2528
|
|
2581
2529
|
return matching_classes
|
File without changes
|
File without changes
|
File without changes
|
{omnata_plugin_runtime-0.5.7a152 → omnata_plugin_runtime-0.5.7a153}/src/omnata_plugin_runtime/api.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|