omnata-plugin-runtime 0.5.7a140__tar.gz → 0.5.7a145__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omnata-plugin-runtime
3
- Version: 0.5.7a140
3
+ Version: 0.5.7a145
4
4
  Summary: Classes and common runtime components for building and running Omnata Plugins
5
5
  Author: James Weakley
6
6
  Author-email: james.weakley@omnata.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "omnata-plugin-runtime"
3
- version = "0.5.7-a140"
3
+ version = "0.5.7-a145"
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"
@@ -6,6 +6,7 @@ Includes data container classes and defines the contract for a plugin.
6
6
  from __future__ import annotations
7
7
  from inspect import signature
8
8
  import sys
9
+ from types import FunctionType
9
10
  from typing import Union
10
11
  if tuple(sys.version_info[:2]) >= (3, 9):
11
12
  # Python 3.9 and above
@@ -2254,6 +2255,117 @@ class SnowflakeUDTFResultColumn:
2254
2255
  data_type: str
2255
2256
  description: str
2256
2257
 
2258
+ @dataclass
2259
+ class PythonUDTFDefinition:
2260
+ """
2261
+ The information needed by the plugin uploader to put a Python UDTF definition into the setup script.
2262
+ Do not use this class directly in plugins, instead use the consumer_udtf decorator.
2263
+ """
2264
+ name: str
2265
+ description: str
2266
+ params: List[SnowflakeFunctionParameter]
2267
+ result_columns: List[SnowflakeUDTFResultColumn]
2268
+ handler: str
2269
+ packages: Optional[List[str]] = None
2270
+
2271
+ def __str__(self):
2272
+ param_str = ', '.join([str(param) for param in self.params])
2273
+ table_result_columns = ', '.join([f"{col.name} {col.data_type}" for col in self.result_columns])
2274
+ packages_str = ', '.join([f"'{p}'" for p in self.packages])
2275
+ return f"""CREATE OR REPLACE FUNCTION UDFS.{self.name}({param_str})
2276
+ RETURNS TABLE({table_result_columns})
2277
+ LANGUAGE PYTHON
2278
+ RUNTIME_VERSION=3.10
2279
+ COMMENT = $${self.description}$$
2280
+ PACKAGES = ({packages_str})
2281
+ IMPORTS = ('/app.zip')
2282
+ HANDLER='{self.handler}';
2283
+ """
2284
+
2285
+ @dataclass
2286
+ class JavaUDTFDefinition:
2287
+ """
2288
+ The information needed by the plugin uploader to put a Java UDTF definition into the setup script.
2289
+ These are created directly in python, since we don't want the omnata cli to need to do any Java reflection.
2290
+ Any .jar files placed in the udf_direct_imports directory will be uploaded to the stage and can be
2291
+ added to the imports parameter as (e.g.) '/my_jar.jar'.
2292
+ """
2293
+ name: str
2294
+ description: str
2295
+ params: List[SnowflakeFunctionParameter]
2296
+ result_columns: List[SnowflakeUDTFResultColumn]
2297
+ packages: List[str]
2298
+ imports: List[str]
2299
+ handler: str
2300
+
2301
+ def __str__(self):
2302
+ param_str = ', '.join([str(param) for param in self.params])
2303
+ table_result_columns = ', '.join([f"{col.name} {col.data_type}" for col in self.result_columns])
2304
+ packages_str = ', '.join([f"'{p}'" for p in self.packages])
2305
+ imports_str = ', '.join([f"'{i}'" for i in self.imports])
2306
+ return f"""CREATE OR REPLACE FUNCTION UDFS.{self.name}({param_str})
2307
+ RETURNS TABLE({table_result_columns})
2308
+ LANGUAGE PYTHON
2309
+ RUNTIME_VERSION=3.10
2310
+ COMMENT = $${self.description}$$
2311
+ PACKAGES = ({packages_str})
2312
+ IMPORTS = ({imports_str})
2313
+ HANDLER='{self.handler}';
2314
+ """
2315
+
2316
+ @dataclass
2317
+ class PythonUDFDefinition:
2318
+ """
2319
+ The information needed by the plugin uploader to put a Python UDF definition into the setup script.
2320
+ Do not use this class directly in plugins, instead use the consumer_udf decorator.
2321
+ """
2322
+ name: str
2323
+ description: str
2324
+ params: List[SnowflakeFunctionParameter]
2325
+ result_data_type: str
2326
+ handler: str
2327
+ packages: Optional[List[str]] = None
2328
+
2329
+ def __str__(self):
2330
+ param_str = ', '.join([str(param) for param in self.params])
2331
+ packages_str = ', '.join([f"'{p}'" for p in self.packages])
2332
+ return f"""CREATE OR REPLACE FUNCTION UDFS.{self.name}({param_str})
2333
+ RETURNS {self.result_data_type}
2334
+ LANGUAGE PYTHON
2335
+ RUNTIME_VERSION=3.10
2336
+ COMMENT = $${self.description}$$
2337
+ PACKAGES = ({packages_str})
2338
+ IMPORTS = ('/app.zip')
2339
+ HANDLER='{self.handler}';
2340
+ """
2341
+
2342
+ @dataclass
2343
+ class JavaUDFDefinition:
2344
+ """
2345
+ The information needed by the plugin uploader to put a java UDF definition into the setup script.
2346
+ """
2347
+ name: str
2348
+ description: str
2349
+ params: List[SnowflakeFunctionParameter]
2350
+ result_data_type: str
2351
+ packages: List[str]
2352
+ imports: List[str]
2353
+ handler: str
2354
+
2355
+ def __str__(self):
2356
+ param_str = ', '.join([str(param) for param in self.params])
2357
+ packages_str = ', '.join([f"'{p}'" for p in self.packages])
2358
+ imports_str = ', '.join([f"'{i}'" for i in self.imports])
2359
+ return f"""CREATE OR REPLACE FUNCTION UDFS.{self.name}({param_str})
2360
+ RETURNS {self.result_data_type}
2361
+ LANGUAGE PYTHON
2362
+ RUNTIME_VERSION=3.10
2363
+ COMMENT = $${self.description}$$
2364
+ PACKAGES = ({packages_str})
2365
+ IMPORTS = ({imports_str})
2366
+ HANDLER='{self.handler}';
2367
+ """
2368
+
2257
2369
  def consumer_udtf(
2258
2370
  name:str,
2259
2371
  description: str,
@@ -2317,7 +2429,7 @@ def consumer_udtf(
2317
2429
 
2318
2430
  return class_decorator
2319
2431
 
2320
- def find_consumer_udtf_classes(path:str = '.'):
2432
+ def find_consumer_udtf_classes(path:str = '.') -> List[PythonUDTFDefinition | JavaUDTFDefinition]:
2321
2433
  """
2322
2434
  Finds all classes in the specified directory which have the 'consumer_udtf' decorator applied
2323
2435
  """
@@ -2336,7 +2448,16 @@ def find_consumer_udtf_classes(path:str = '.'):
2336
2448
  for name, obj in inspect.getmembers(module, inspect.isclass):
2337
2449
  # Check if the class has the specified attribute
2338
2450
  if hasattr(obj, '_is_omnata_consumer_udtf'):
2451
+ matching_classes.append(PythonUDTFDefinition(
2452
+ name=obj._omnata_consumer_udtf_name,
2453
+ description=obj._omnata_consumer_udtf_description,
2454
+ params=obj._omnata_consumer_udtf_params,
2455
+ result_columns=obj._omnata_consumer_udtf_result_columns,
2456
+ handler=obj.__module__+'.'+obj.__name__
2457
+ ))
2458
+ elif isinstance(obj, JavaUDTFDefinition):
2339
2459
  matching_classes.append(obj)
2460
+
2340
2461
  return matching_classes
2341
2462
 
2342
2463
 
@@ -2393,7 +2514,7 @@ def consumer_udf(
2393
2514
 
2394
2515
  return decorator
2395
2516
 
2396
- def find_consumer_udf_functions(path:str = '.'):
2517
+ def find_consumer_udf_functions(path:str = '.') -> List[PythonUDFDefinition | JavaUDFDefinition]:
2397
2518
  """
2398
2519
  Finds all functions in the specified directory which have the 'consumer_udf' decorator applied
2399
2520
  """
@@ -2412,6 +2533,15 @@ def find_consumer_udf_functions(path:str = '.'):
2412
2533
  for name, obj in inspect.getmembers(module, inspect.isfunction):
2413
2534
  # Check if the class has the specified attribute
2414
2535
  if hasattr(obj, '_is_omnata_consumer_udf'):
2536
+ matching_classes.append(PythonUDFDefinition(
2537
+ name=obj._omnata_consumer_udf_name,
2538
+ description=obj._omnata_consumer_udf_description,
2539
+ params=obj._omnata_consumer_udf_params,
2540
+ result_data_type=obj._omnata_consumer_udf_result_data_type,
2541
+ packages=[],
2542
+ handler=obj.__module__+'.'+obj.__name__
2543
+ ))
2544
+ elif isinstance(obj, JavaUDFDefinition):
2415
2545
  matching_classes.append(obj)
2416
2546
 
2417
2547
  return matching_classes