omnata-plugin-runtime 0.5.9a160__tar.gz → 0.5.10__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.9a160
3
+ Version: 0.5.10
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.9-a160"
3
+ version = "0.5.10"
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"
@@ -112,6 +112,90 @@ class PluginManifest(SubscriptableBaseModel):
112
112
  supported_outbound_strategies: List[OutboundSyncStrategy]
113
113
 
114
114
 
115
+ class SnowflakeFunctionParameter(BaseModel):
116
+ """
117
+ Represents a parameter for a Snowflake UDF or UDTF
118
+ """
119
+ name: str
120
+ description: str
121
+ data_type: str
122
+ default_value_clause: Optional[str] = None
123
+
124
+ def __str__(self):
125
+ if self.default_value_clause:
126
+ return f"{self.name} {self.data_type} default {self.default_value_clause}"
127
+ return f"{self.name} {self.data_type}"
128
+
129
+ class SnowflakeUDTFResultColumn(BaseModel):
130
+ """
131
+ Represents a result column for a Snowflake UDTF
132
+ """
133
+ name: str
134
+ data_type: str
135
+ def __str__(self):
136
+ return f"{self.name} {self.data_type}"
137
+
138
+ class UDTFDefinition(BaseModel):
139
+ """
140
+ The information needed by the plugin uploader to put a Python UDTF definition into the setup script.
141
+ Do not use this class directly in plugins, instead use the omnata_udtf decorator.
142
+ """
143
+ name: str = Field(..., title="The name of the UDTF")
144
+ language: Literal['python','java'] = Field(..., title="The language of the UDF")
145
+ runtime_version: str = Field(..., title="The runtime version of the UDF (language dependent)")
146
+ description: str = Field(..., title="A description of the UDTF")
147
+ params: List[SnowflakeFunctionParameter] = Field(..., title="The parameters of the UDTF")
148
+ result_columns: List[SnowflakeUDTFResultColumn] = Field(..., title="The result columns of the UDTF")
149
+ handler: str = Field(..., title="The handler class/function for the UDTF")
150
+ expose_to_consumer: bool = Field(..., title="Whether the UDTF should be exposed to consumers")
151
+ imports: Optional[List[str]] = Field(None, title="A list of imports required by the UDF")
152
+ packages: Optional[List[str]] = Field(None, title="A list of packages required by the UDTF")
153
+
154
+ def __str__(self):
155
+ param_str = ', '.join([str(param) for param in self.params])
156
+ table_result_columns = ', '.join([f"{col.name} {col.data_type}" for col in self.result_columns])
157
+ packages_str = ', '.join([f"'{p}'" for p in self.packages])
158
+ imports_str = ', '.join([f"'{i}'" for i in self.imports])
159
+ return f"""CREATE OR REPLACE FUNCTION UDFS.{self.name}({param_str})
160
+ RETURNS TABLE({table_result_columns})
161
+ LANGUAGE {self.language.upper()}
162
+ RUNTIME_VERSION={self.runtime_version}
163
+ COMMENT = $${self.description}$$
164
+ PACKAGES = ({packages_str})
165
+ IMPORTS = ({imports_str})
166
+ HANDLER='{self.handler}';
167
+ """
168
+
169
+ class UDFDefinition(BaseModel):
170
+ """
171
+ The information needed by the plugin uploader to put a Python UDF definition into the setup script.
172
+ Do not use this class directly in plugins, instead use the omnata_udf decorator.
173
+ """
174
+ name: str = Field(..., title="The name of the UDF")
175
+ language: Literal['python','java'] = Field(..., title="The language of the UDF")
176
+ runtime_version: str = Field(..., title="The runtime version of the UDF (language dependent)")
177
+ description: str = Field(..., title="A description of the UDF")
178
+ params: List[SnowflakeFunctionParameter] = Field(..., title="The parameters of the UDF")
179
+ result_data_type: str = Field(..., title="The data type returned by the UDF")
180
+ handler: str = Field(..., title="The handler class/function for the UDF")
181
+ expose_to_consumer: bool = Field(..., title="Whether the UDF should be exposed to consumers")
182
+ imports: Optional[List[str]] = Field(None, title="A list of imports required by the UDF")
183
+ packages: Optional[List[str]] = Field(None, title="A list of packages required by the UDF")
184
+
185
+ def __str__(self):
186
+ param_str = ', '.join([str(param) for param in self.params])
187
+ packages_str = ', '.join([f"'{p}'" for p in self.packages])
188
+ imports_str = ', '.join([f"'{i}'" for i in self.imports])
189
+ return f"""CREATE OR REPLACE FUNCTION UDFS.{self.name}({param_str})
190
+ RETURNS {self.result_data_type}
191
+ LANGUAGE {self.language.upper()}
192
+ RUNTIME_VERSION={self.runtime_version}
193
+ COMMENT = $${self.description}$$
194
+ PACKAGES = ({packages_str})
195
+ IMPORTS = ({imports_str})
196
+ HANDLER='{self.handler}';
197
+ """
198
+
115
199
  class PluginInfo(BaseModel):
116
200
  """
117
201
  Manifest plus other derived information about a plugin which is determined during upload.
@@ -2234,90 +2318,6 @@ def get_nested_value(nested_dict:Dict, keys:List[str]):
2234
2318
  return reduce(lambda d, key: d.get(key) if isinstance(d, dict) else None, keys, nested_dict)
2235
2319
 
2236
2320
 
2237
- class SnowflakeFunctionParameter(BaseModel):
2238
- """
2239
- Represents a parameter for a Snowflake UDF or UDTF
2240
- """
2241
- name: str
2242
- description: str
2243
- data_type: str
2244
- default_value_clause: Optional[str] = None
2245
-
2246
- def __str__(self):
2247
- if self.default_value_clause:
2248
- return f"{self.name} {self.data_type} default {self.default_value_clause}"
2249
- return f"{self.name} {self.data_type}"
2250
-
2251
- class SnowflakeUDTFResultColumn(BaseModel):
2252
- """
2253
- Represents a result column for a Snowflake UDTF
2254
- """
2255
- name: str
2256
- data_type: str
2257
- def __str__(self):
2258
- return f"{self.name} {self.data_type}"
2259
-
2260
- class UDTFDefinition(BaseModel):
2261
- """
2262
- The information needed by the plugin uploader to put a Python UDTF definition into the setup script.
2263
- Do not use this class directly in plugins, instead use the omnata_udtf decorator.
2264
- """
2265
- name: str = Field(..., title="The name of the UDTF")
2266
- language: Literal['python','java'] = Field(..., title="The language of the UDF")
2267
- runtime_version: str = Field(..., title="The runtime version of the UDF (language dependent)")
2268
- description: str = Field(..., title="A description of the UDTF")
2269
- params: List[SnowflakeFunctionParameter] = Field(..., title="The parameters of the UDTF")
2270
- result_columns: List[SnowflakeUDTFResultColumn] = Field(..., title="The result columns of the UDTF")
2271
- handler: str = Field(..., title="The handler class/function for the UDTF")
2272
- expose_to_consumer: bool = Field(..., title="Whether the UDTF should be exposed to consumers")
2273
- imports: Optional[List[str]] = Field(None, title="A list of imports required by the UDF")
2274
- packages: Optional[List[str]] = Field(None, title="A list of packages required by the UDTF")
2275
-
2276
- def __str__(self):
2277
- param_str = ', '.join([str(param) for param in self.params])
2278
- table_result_columns = ', '.join([f"{col.name} {col.data_type}" for col in self.result_columns])
2279
- packages_str = ', '.join([f"'{p}'" for p in self.packages])
2280
- imports_str = ', '.join([f"'{i}'" for i in self.imports])
2281
- return f"""CREATE OR REPLACE FUNCTION UDFS.{self.name}({param_str})
2282
- RETURNS TABLE({table_result_columns})
2283
- LANGUAGE {self.language.upper()}
2284
- RUNTIME_VERSION={self.runtime_version}
2285
- COMMENT = $${self.description}$$
2286
- PACKAGES = ({packages_str})
2287
- IMPORTS = ({imports_str})
2288
- HANDLER='{self.handler}';
2289
- """
2290
-
2291
- class UDFDefinition(BaseModel):
2292
- """
2293
- The information needed by the plugin uploader to put a Python UDF definition into the setup script.
2294
- Do not use this class directly in plugins, instead use the omnata_udf decorator.
2295
- """
2296
- name: str = Field(..., title="The name of the UDF")
2297
- language: Literal['python','java'] = Field(..., title="The language of the UDF")
2298
- runtime_version: str = Field(..., title="The runtime version of the UDF (language dependent)")
2299
- description: str = Field(..., title="A description of the UDF")
2300
- params: List[SnowflakeFunctionParameter] = Field(..., title="The parameters of the UDF")
2301
- result_data_type: str = Field(..., title="The data type returned by the UDF")
2302
- handler: str = Field(..., title="The handler class/function for the UDF")
2303
- expose_to_consumer: bool = Field(..., title="Whether the UDF should be exposed to consumers")
2304
- imports: Optional[List[str]] = Field(None, title="A list of imports required by the UDF")
2305
- packages: Optional[List[str]] = Field(None, title="A list of packages required by the UDF")
2306
-
2307
- def __str__(self):
2308
- param_str = ', '.join([str(param) for param in self.params])
2309
- packages_str = ', '.join([f"'{p}'" for p in self.packages])
2310
- imports_str = ', '.join([f"'{i}'" for i in self.imports])
2311
- return f"""CREATE OR REPLACE FUNCTION UDFS.{self.name}({param_str})
2312
- RETURNS {self.result_data_type}
2313
- LANGUAGE {self.language.upper()}
2314
- RUNTIME_VERSION={self.runtime_version}
2315
- COMMENT = $${self.description}$$
2316
- PACKAGES = ({packages_str})
2317
- IMPORTS = ({imports_str})
2318
- HANDLER='{self.handler}';
2319
- """
2320
-
2321
2321
  def omnata_udtf(
2322
2322
  name:str,
2323
2323
  description: str,
@@ -2432,8 +2432,9 @@ def find_udtf_classes(path:str = '.') -> List[UDTFDefinition]:
2432
2432
  udtf_obj = cast(UDTFDefinition,obj)
2433
2433
  if udtf_obj.language == 'java':
2434
2434
  # because the decorator wasn't used, we need to check if we need to add the connection_parameters parameter
2435
- if udtf_obj.expose_to_consumer and udtf_obj.params[0].name.upper() != 'CONNECTION_PARAMETERS':
2436
- udtf_obj.params = [SnowflakeFunctionParameter(
2435
+ if udtf_obj.expose_to_consumer:
2436
+ if len(udtf_obj.params) == 0 or udtf_obj.params[0].name.upper() != 'CONNECTION_PARAMETERS':
2437
+ udtf_obj.params = [SnowflakeFunctionParameter(
2437
2438
  name='CONNECTION_PARAMETERS',
2438
2439
  data_type='OBJECT',
2439
2440
  description='The connection object, obtained from calling PLUGIN.PLUGIN_CONNECTION.')] + udtf_obj.params
@@ -2547,8 +2548,9 @@ def find_udf_functions(path:str = '.') -> List[UDFDefinition]:
2547
2548
  udf_obj = cast(UDFDefinition,obj)
2548
2549
  if udf_obj.language == 'java':
2549
2550
  # because the decorator wasn't used, we need to check if we need to add the connection_parameters parameter
2550
- if udf_obj.expose_to_consumer and udf_obj.params[0].name.upper() != 'CONNECTION_PARAMETERS':
2551
- udf_obj.params = [SnowflakeFunctionParameter(
2551
+ if udf_obj.expose_to_consumer:
2552
+ if len(udf_obj.params) == 0 or udf_obj.params[0].name.upper() != 'CONNECTION_PARAMETERS':
2553
+ udf_obj.params = [SnowflakeFunctionParameter(
2552
2554
  name='CONNECTION_PARAMETERS',
2553
2555
  data_type='OBJECT',
2554
2556
  description='The connection object, obtained from calling PLUGIN.PLUGIN_CONNECTION.')] + udf_obj.params