omnata-plugin-runtime 0.5.7a141__tar.gz → 0.5.7a146__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omnata-plugin-runtime
3
- Version: 0.5.7a141
3
+ Version: 0.5.7a146
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-a141"
3
+ version = "0.5.7-a146"
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"
@@ -2255,13 +2255,128 @@ class SnowflakeUDTFResultColumn:
2255
2255
  data_type: str
2256
2256
  description: str
2257
2257
 
2258
- def consumer_udtf(
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 omnata_udtf decorator.
2263
+ """
2264
+ name: str
2265
+ description: str
2266
+ params: List[SnowflakeFunctionParameter]
2267
+ result_columns: List[SnowflakeUDTFResultColumn]
2268
+ handler: str
2269
+ expose_to_consumer: bool
2270
+ packages: Optional[List[str]] = None
2271
+
2272
+ def __str__(self):
2273
+ param_str = ', '.join([str(param) for param in self.params])
2274
+ table_result_columns = ', '.join([f"{col.name} {col.data_type}" for col in self.result_columns])
2275
+ packages_str = ', '.join([f"'{p}'" for p in self.packages])
2276
+ return f"""CREATE OR REPLACE FUNCTION UDFS.{self.name}({param_str})
2277
+ RETURNS TABLE({table_result_columns})
2278
+ LANGUAGE PYTHON
2279
+ RUNTIME_VERSION=3.10
2280
+ COMMENT = $${self.description}$$
2281
+ PACKAGES = ({packages_str})
2282
+ IMPORTS = ('/app.zip')
2283
+ HANDLER='{self.handler}';
2284
+ """
2285
+
2286
+ @dataclass
2287
+ class JavaUDTFDefinition:
2288
+ """
2289
+ The information needed by the plugin uploader to put a Java UDTF definition into the setup script.
2290
+ These are created directly in python, since we don't want the omnata cli to need to do any Java reflection.
2291
+ Any .jar files placed in the udf_direct_imports directory will be uploaded to the stage and can be
2292
+ added to the imports parameter as (e.g.) '/my_jar.jar'.
2293
+ """
2294
+ name: str
2295
+ description: str
2296
+ params: List[SnowflakeFunctionParameter]
2297
+ result_columns: List[SnowflakeUDTFResultColumn]
2298
+ packages: List[str]
2299
+ imports: List[str]
2300
+ handler: str
2301
+
2302
+ def __str__(self):
2303
+ param_str = ', '.join([str(param) for param in self.params])
2304
+ table_result_columns = ', '.join([f"{col.name} {col.data_type}" for col in self.result_columns])
2305
+ packages_str = ', '.join([f"'{p}'" for p in self.packages])
2306
+ imports_str = ', '.join([f"'{i}'" for i in self.imports])
2307
+ return f"""CREATE OR REPLACE FUNCTION UDFS.{self.name}({param_str})
2308
+ RETURNS TABLE({table_result_columns})
2309
+ LANGUAGE PYTHON
2310
+ RUNTIME_VERSION=3.10
2311
+ COMMENT = $${self.description}$$
2312
+ PACKAGES = ({packages_str})
2313
+ IMPORTS = ({imports_str})
2314
+ HANDLER='{self.handler}';
2315
+ """
2316
+
2317
+ @dataclass
2318
+ class PythonUDFDefinition:
2319
+ """
2320
+ The information needed by the plugin uploader to put a Python UDF definition into the setup script.
2321
+ Do not use this class directly in plugins, instead use the omnata_udf decorator.
2322
+ """
2323
+ name: str
2324
+ description: str
2325
+ params: List[SnowflakeFunctionParameter]
2326
+ result_data_type: str
2327
+ handler: str
2328
+ expose_to_consumer: bool
2329
+ packages: Optional[List[str]] = None
2330
+
2331
+ def __str__(self):
2332
+ param_str = ', '.join([str(param) for param in self.params])
2333
+ packages_str = ', '.join([f"'{p}'" for p in self.packages])
2334
+ return f"""CREATE OR REPLACE FUNCTION UDFS.{self.name}({param_str})
2335
+ RETURNS {self.result_data_type}
2336
+ LANGUAGE PYTHON
2337
+ RUNTIME_VERSION=3.10
2338
+ COMMENT = $${self.description}$$
2339
+ PACKAGES = ({packages_str})
2340
+ IMPORTS = ('/app.zip')
2341
+ HANDLER='{self.handler}';
2342
+ """
2343
+
2344
+ @dataclass
2345
+ class JavaUDFDefinition:
2346
+ """
2347
+ The information needed by the plugin uploader to put a java UDF definition into the setup script.
2348
+ """
2349
+ name: str
2350
+ description: str
2351
+ params: List[SnowflakeFunctionParameter]
2352
+ result_data_type: str
2353
+ packages: List[str]
2354
+ imports: List[str]
2355
+ handler: str
2356
+ expose_to_consumer: bool
2357
+
2358
+ def __str__(self):
2359
+ param_str = ', '.join([str(param) for param in self.params])
2360
+ packages_str = ', '.join([f"'{p}'" for p in self.packages])
2361
+ imports_str = ', '.join([f"'{i}'" for i in self.imports])
2362
+ return f"""CREATE OR REPLACE FUNCTION UDFS.{self.name}({param_str})
2363
+ RETURNS {self.result_data_type}
2364
+ LANGUAGE PYTHON
2365
+ RUNTIME_VERSION=3.10
2366
+ COMMENT = $${self.description}$$
2367
+ PACKAGES = ({packages_str})
2368
+ IMPORTS = ({imports_str})
2369
+ HANDLER='{self.handler}';
2370
+ """
2371
+
2372
+ def omnata_udtf(
2259
2373
  name:str,
2260
2374
  description: str,
2261
2375
  params: List[SnowflakeFunctionParameter],
2262
- result_columns: List[SnowflakeUDTFResultColumn]):
2376
+ result_columns: List[SnowflakeUDTFResultColumn],
2377
+ expose_to_consumer: bool):
2263
2378
  """
2264
- A decorator for a class which should be automatically exposed to the consumer as a UDTF
2379
+ A decorator for a class which should create a UDTF in the UDFS schema of the native app
2265
2380
  """
2266
2381
  def class_decorator(cls):
2267
2382
  # Get the original 'process' method from the class
@@ -2309,18 +2424,19 @@ def consumer_udtf(
2309
2424
  return original_process(self, parameters, *args, **kwargs)
2310
2425
  # Replace the original 'process' method with the wrapped version
2311
2426
  setattr(cls, 'process', wrapped_process)
2312
- cls._is_omnata_consumer_udtf = True
2313
- cls._omnata_consumer_udtf_name = name
2314
- cls._omnata_consumer_udtf_description = description
2315
- cls._omnata_consumer_udtf_params = params
2316
- cls._omnata_consumer_udtf_result_columns = result_columns
2427
+ cls._is_omnata_udtf = True
2428
+ cls._omnata_udtf_name = name
2429
+ cls._omnata_udtf_description = description
2430
+ cls._omnata_udtf_params = params
2431
+ cls._omnata_udtf_result_columns = result_columns
2432
+ cls._omnata_udtf_expose_to_consumer = expose_to_consumer
2317
2433
  return cls
2318
2434
 
2319
2435
  return class_decorator
2320
2436
 
2321
- def find_consumer_udtf_classes(path:str = '.') -> List[type]:
2437
+ def find_udtf_classes(path:str = '.') -> List[PythonUDTFDefinition | JavaUDTFDefinition]:
2322
2438
  """
2323
- Finds all classes in the specified directory which have the 'consumer_udtf' decorator applied
2439
+ Finds all classes in the specified directory which have the 'omnata_udtf' decorator applied
2324
2440
  """
2325
2441
  # Get the directory's absolute path
2326
2442
  current_dir = os.path.abspath(path)
@@ -2336,16 +2452,27 @@ def find_consumer_udtf_classes(path:str = '.') -> List[type]:
2336
2452
  # Iterate over all members of the module
2337
2453
  for name, obj in inspect.getmembers(module, inspect.isclass):
2338
2454
  # Check if the class has the specified attribute
2339
- if hasattr(obj, '_is_omnata_consumer_udtf'):
2455
+ if hasattr(obj, '_is_omnata_udtf'):
2456
+ matching_classes.append(PythonUDTFDefinition(
2457
+ name=obj._omnata_udtf_name,
2458
+ description=obj._omnata_udtf_description,
2459
+ params=obj._omnata_udtf_params,
2460
+ result_columns=obj._omnata_udtf_result_columns,
2461
+ expose_to_consumer=obj._omnata_udtf_expose_to_consumer,
2462
+ handler=obj.__module__+'.'+obj.__name__
2463
+ ))
2464
+ elif isinstance(obj, JavaUDTFDefinition):
2340
2465
  matching_classes.append(obj)
2466
+
2341
2467
  return matching_classes
2342
2468
 
2343
2469
 
2344
- def consumer_udf(
2470
+ def omnata_udf(
2345
2471
  name: str,
2346
2472
  description: str,
2347
2473
  params: List[SnowflakeFunctionParameter],
2348
- result_data_type: str):
2474
+ result_data_type: str,
2475
+ expose_to_consumer: bool):
2349
2476
  """
2350
2477
  A decorator for a function which should be automatically exposed to the consumer as a UDF
2351
2478
  """
@@ -2385,18 +2512,19 @@ def consumer_udf(
2385
2512
  # Pass the validated arguments to the function
2386
2513
  return func(parameters, *args, **kwargs)
2387
2514
 
2388
- wrapper._is_omnata_consumer_udf = True
2389
- wrapper._omnata_consumer_udf_name = name
2390
- wrapper._omnata_consumer_udf_description = description
2391
- wrapper._omnata_consumer_udf_params = params
2392
- wrapper._omnata_consumer_udf_result_data_type = result_data_type
2515
+ wrapper._is_omnata_udf = True
2516
+ wrapper._omnata_udf_name = name
2517
+ wrapper._omnata_udf_description = description
2518
+ wrapper._omnata_udf_params = params
2519
+ wrapper._omnata_udf_result_data_type = result_data_type
2520
+ wrapper._omnata_udf_expose_to_consumer = expose_to_consumer
2393
2521
  return wrapper
2394
2522
 
2395
2523
  return decorator
2396
2524
 
2397
- def find_consumer_udf_functions(path:str = '.') -> List[function]:
2525
+ def find_udf_functions(path:str = '.') -> List[PythonUDFDefinition | JavaUDFDefinition]:
2398
2526
  """
2399
- Finds all functions in the specified directory which have the 'consumer_udf' decorator applied
2527
+ Finds all functions in the specified directory which have the 'omnata_udf' decorator applied
2400
2528
  """
2401
2529
  # Get the current directory's absolute path
2402
2530
  current_dir = os.path.abspath(path)
@@ -2412,7 +2540,17 @@ def find_consumer_udf_functions(path:str = '.') -> List[function]:
2412
2540
  # Iterate over all members of the module
2413
2541
  for name, obj in inspect.getmembers(module, inspect.isfunction):
2414
2542
  # Check if the class has the specified attribute
2415
- if hasattr(obj, '_is_omnata_consumer_udf'):
2543
+ if hasattr(obj, '_is_omnata_udf'):
2544
+ matching_classes.append(PythonUDFDefinition(
2545
+ name=obj._omnata_udf_name,
2546
+ description=obj._omnata_udf_description,
2547
+ params=obj._omnata_udf_params,
2548
+ result_data_type=obj._omnata_udf_result_data_type,
2549
+ expose_to_consumer=obj._omnata_udf_expose_to_consumer,
2550
+ packages=[],
2551
+ handler=obj.__module__+'.'+obj.__name__
2552
+ ))
2553
+ elif isinstance(obj, JavaUDFDefinition):
2416
2554
  matching_classes.append(obj)
2417
2555
 
2418
2556
  return matching_classes