omnata-plugin-runtime 0.5.7a147__py3-none-any.whl → 0.5.7a149__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.
@@ -2381,56 +2381,68 @@ def omnata_udtf(
2381
2381
  """
2382
2382
  def class_decorator(cls):
2383
2383
  # Get the original 'process' method from the class
2384
+ if not hasattr(cls, 'process'):
2385
+ raise ValueError("The class must have a 'process' method.")
2384
2386
  original_process = getattr(cls, 'process')
2385
2387
  sig = signature(original_process)
2386
2388
  function_params = sig.parameters
2387
- if len(function_params) < 2:
2388
- raise ValueError("The function must have the self parameter, plus at least the mandatory 'connection_parameters' parameter.")
2389
- # Ensure the first argument is mandatory and positional
2389
+ if len(function_params) < 1:
2390
+ raise ValueError("The 'process' function must have at least one parameter.")
2391
+
2390
2392
  first_param_name = list(function_params.keys())[0]
2391
-
2392
2393
  if first_param_name != 'self':
2393
- raise ValueError(f"The first argument should be 'self', instead it was '{first_param_name}'.")
2394
+ raise ValueError(f"The first argument for the 'process' function should be 'self', instead it was '{first_param_name}'.")
2394
2395
 
2395
- second_param_name = list(function_params.keys())[1]
2396
+ cls._is_omnata_udtf = True
2397
+ cls._omnata_udtf_name = name
2398
+ cls._omnata_udtf_description = description
2399
+ cls._omnata_udtf_params = params
2400
+ cls._omnata_udtf_result_columns = result_columns
2401
+ cls._omnata_udtf_expose_to_consumer = expose_to_consumer
2396
2402
 
2403
+ if not expose_to_consumer:
2404
+ # If not exposing to the consumer, there are no further requirements
2405
+ return cls
2406
+
2407
+ if len(function_params) < 2:
2408
+ raise ValueError("When exposing the udtf to consumers, the 'process' function must have the self parameter, plus at least the mandatory 'connection_parameters' parameter.")
2409
+ second_param_name = list(function_params.keys())[1]
2397
2410
  if second_param_name != 'connection_parameters':
2398
2411
  raise ValueError(f"The second argument should be 'connection_parameters', instead it was {second_param_name}.")
2399
-
2400
-
2401
2412
  if function_params[second_param_name].annotation != ConnectionConfigurationParameters:
2402
2413
  raise ValueError(f"The second argument must be a ConnectionConfigurationParameters, instead it was a {function_params[second_param_name].annotation}.")
2403
2414
 
2404
- @wraps(original_process)
2405
- def wrapped_process(self, connection_parameters, *args, **kwargs):
2406
- if connection_parameters is None:
2407
- raise ValueError("Connection not found")
2415
+ if params[0].name.upper() != 'CONNECTION_PARAMETERS':
2416
+ params = [SnowflakeFunctionParameter(
2417
+ name='CONNECTION_PARAMETERS',
2418
+ data_type='OBJECT',
2419
+ description='The connection object, obtained from calling PLUGIN.PLUGIN_CONNECTION.')] + params
2420
+ cls._omnata_udtf_params = params
2421
+ if len(params) != len(function_params) -1:
2422
+ raise ValueError(f"You must document all the parameters of the 'process' function in the @omnata_udtf decorator in the same order ('connection_parameters' will be included automatically).")
2408
2423
 
2424
+ @wraps(original_process)
2425
+ def wrapped_process(self, connection_parameter_arg, *args, **kwargs):
2426
+ if connection_parameter_arg is None:
2427
+ raise ValueError("Connection not found")
2428
+
2409
2429
  # convert the connection parameters dictionary to a ConnectionConfigurationParameters object which includes the real secrets
2410
- if 'other_secrets_name' in connection_parameters:
2430
+ if 'other_secrets_name' in connection_parameter_arg:
2411
2431
  # this is the new way, where the sync engine only passes the name of the secret
2412
2432
  oauth_secrets_name = None
2413
- if 'oauth_secret_name' in connection_parameters:
2414
- oauth_secrets_name = connection_parameters['oauth_secret_name']
2415
- del connection_parameters['oauth_secret_name']
2416
- result = get_secrets(oauth_secrets_name,connection_parameters['other_secrets_name'])
2417
- connection_parameters['connection_secrets'] = result
2418
- del connection_parameters['other_secrets_name']
2419
- parameters = ConnectionConfigurationParameters.model_validate(connection_parameters)
2420
- else:
2421
- # deprecated way, where the sync engine passes the secrets directly
2422
- parameters = ConnectionConfigurationParameters.model_validate(connection_parameters)
2433
+ if 'oauth_secret_name' in connection_parameter_arg:
2434
+ oauth_secrets_name = connection_parameter_arg['oauth_secret_name']
2435
+ del connection_parameter_arg['oauth_secret_name']
2436
+ result = get_secrets(oauth_secrets_name,connection_parameter_arg['other_secrets_name'])
2437
+ connection_parameter_arg['connection_secrets'] = result
2438
+ del connection_parameter_arg['other_secrets_name']
2439
+
2440
+ parameters = ConnectionConfigurationParameters.model_validate(connection_parameter_arg)
2423
2441
 
2424
2442
  # Pass the validated arguments to the function
2425
2443
  return original_process(self, parameters, *args, **kwargs)
2426
2444
  # Replace the original 'process' method with the wrapped version
2427
2445
  setattr(cls, 'process', wrapped_process)
2428
- cls._is_omnata_udtf = True
2429
- cls._omnata_udtf_name = name
2430
- cls._omnata_udtf_description = description
2431
- cls._omnata_udtf_params = params
2432
- cls._omnata_udtf_result_columns = result_columns
2433
- cls._omnata_udtf_expose_to_consumer = expose_to_consumer
2434
2446
  return cls
2435
2447
 
2436
2448
  return class_decorator
@@ -2475,11 +2487,22 @@ def omnata_udf(
2475
2487
  result_data_type: str,
2476
2488
  expose_to_consumer: bool):
2477
2489
  """
2478
- A decorator for a function which should be automatically exposed to the consumer as a UDF
2490
+ A decorator for a function which will be created in the native application.
2479
2491
  """
2480
2492
  def decorator(func):
2481
2493
  sig = signature(func)
2482
2494
  function_params = sig.parameters
2495
+
2496
+ if not expose_to_consumer:
2497
+ # If not exposing to the consumer, there are no further requirements
2498
+ func._is_omnata_udf = True
2499
+ func._omnata_udf_name = name
2500
+ func._omnata_udf_description = description
2501
+ func._omnata_udf_params = params
2502
+ func._omnata_udf_result_data_type = result_data_type
2503
+ func._omnata_udf_expose_to_consumer = expose_to_consumer
2504
+ return func
2505
+
2483
2506
  if len(function_params) == 0:
2484
2507
  raise ValueError("The function must have at least one parameter.")
2485
2508
  # Ensure the first argument is mandatory and positional
@@ -2488,27 +2511,29 @@ def omnata_udf(
2488
2511
  raise ValueError(f"The first argument should be 'connection_parameters', instead it was '{first_param_name}'.")
2489
2512
  if function_params[first_param_name].annotation != ConnectionConfigurationParameters:
2490
2513
  raise ValueError(f"The first argument must be a ConnectionConfigurationParameters, instead it was a {function_params[first_param_name].annotation}.")
2514
+ if params[0].name.upper() != 'CONNECTION_PARAMETERS':
2515
+ params = [SnowflakeFunctionParameter(
2516
+ name='CONNECTION_PARAMETERS',
2517
+ data_type='OBJECT',
2518
+ description='The connection object, obtained from calling PLUGIN.PLUGIN_CONNECTION.')] + params
2519
+ func._omnata_udf_params = params
2520
+ if len(params) != len(function_params):
2521
+ raise ValueError(f"You must document all the parameters of the function in the @omnata_udf decorator in the same order ('connection_parameters' will be included automatically).")
2491
2522
 
2492
2523
  @wraps(func)
2493
- def wrapper(self, connection_parameters, *args, **kwargs):
2494
- if connection_parameters is None:
2495
- raise ValueError("Connection not found")
2496
-
2497
-
2524
+ def wrapper(connection_parameter_arg, *args, **kwargs):
2498
2525
  # convert the connection parameters dictionary to a ConnectionConfigurationParameters object which includes the real secrets
2499
- if 'other_secrets_name' in connection_parameters:
2526
+ if 'other_secrets_name' in connection_parameter_arg:
2500
2527
  # this is the new way, where the sync engine only passes the name of the secret
2501
2528
  oauth_secrets_name = None
2502
- if 'oauth_secret_name' in connection_parameters:
2503
- oauth_secrets_name = connection_parameters['oauth_secret_name']
2504
- del connection_parameters['oauth_secret_name']
2505
- result = get_secrets(oauth_secrets_name,connection_parameters['other_secrets_name'])
2506
- connection_parameters['connection_secrets'] = result
2507
- del connection_parameters['other_secrets_name']
2508
- parameters = ConnectionConfigurationParameters.model_validate(connection_parameters)
2509
- else:
2510
- # deprecated way, where the sync engine passes the secrets directly
2511
- parameters = ConnectionConfigurationParameters.model_validate(connection_parameters)
2529
+ if 'oauth_secret_name' in connection_parameter_arg:
2530
+ oauth_secrets_name = connection_parameter_arg['oauth_secret_name']
2531
+ del connection_parameter_arg['oauth_secret_name']
2532
+ result = get_secrets(oauth_secrets_name,connection_parameter_arg['other_secrets_name'])
2533
+ connection_parameter_arg['connection_secrets'] = result
2534
+ del connection_parameter_arg['other_secrets_name']
2535
+
2536
+ parameters = ConnectionConfigurationParameters.model_validate(connection_parameter_arg)
2512
2537
 
2513
2538
  # Pass the validated arguments to the function
2514
2539
  return func(parameters, *args, **kwargs)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omnata-plugin-runtime
3
- Version: 0.5.7a147
3
+ Version: 0.5.7a149
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
@@ -3,10 +3,10 @@ omnata_plugin_runtime/api.py,sha256=FxzTqri4no8ClkOm7vZADG8aD47jcGBCTTQDEORmOJM,
3
3
  omnata_plugin_runtime/configuration.py,sha256=TI6GaVFhewVawBCaYN34GujY57qEP6q2nik4YpSEk5s,38100
4
4
  omnata_plugin_runtime/forms.py,sha256=GzSPEwcijsoPCXEO1mHiE8ylvX_KSE5TkhwqkymA2Ss,19755
5
5
  omnata_plugin_runtime/logging.py,sha256=bn7eKoNWvtuyTk7RTwBS9UARMtqkiICtgMtzq3KA2V0,3272
6
- omnata_plugin_runtime/omnata_plugin.py,sha256=mgGxL7W2tnKGUUW6uUYBRYNabhu5sJVCf1y3GX-eJ3o,125323
6
+ omnata_plugin_runtime/omnata_plugin.py,sha256=kbEo288aeciuHzHWLodvkWa-jWLrwjPn0NFQxmOd9ns,127063
7
7
  omnata_plugin_runtime/plugin_entrypoints.py,sha256=PFSLsYEVnWHVvSoOYTtTK2JY6pp6_8_eYP53WqLRiPE,27975
8
8
  omnata_plugin_runtime/rate_limiting.py,sha256=DVQ_bc-mVLBkrU1PTns1MWXhHiLpSB5HkWCcdePtJ2A,25611
9
- omnata_plugin_runtime-0.5.7a147.dist-info/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
10
- omnata_plugin_runtime-0.5.7a147.dist-info/METADATA,sha256=_6tMzoqnFJM3jV4Lomk7A2vJselwa5YiiaoBzFRtMUw,1985
11
- omnata_plugin_runtime-0.5.7a147.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
12
- omnata_plugin_runtime-0.5.7a147.dist-info/RECORD,,
9
+ omnata_plugin_runtime-0.5.7a149.dist-info/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
10
+ omnata_plugin_runtime-0.5.7a149.dist-info/METADATA,sha256=GA-eNt-5EUBEgjQc0jCVpm1_ESmhEquO-z-ZRnUq0bg,1985
11
+ omnata_plugin_runtime-0.5.7a149.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
12
+ omnata_plugin_runtime-0.5.7a149.dist-info/RECORD,,