SatishChGit commented on code in PR #39217:
URL: https://github.com/apache/airflow/pull/39217#discussion_r1589565825
##########
airflow/providers/teradata/hooks/teradata.py:
##########
@@ -32,6 +32,17 @@
if TYPE_CHECKING:
from airflow.models.connection import Connection
+PARAM_TYPES = {bool, float, int, str}
+
+
+def _map_param(value):
+ if value in PARAM_TYPES:
+ # In this branch, value is a Python type; calling it produces
+ # an instance of the type which is understood by the Teradata driver
+ # in the out parameter mapping mechanism.
+ value = value()
+ return value
Review Comment:
This function is used to translate stored procedure out parameters into a
format understandable by the driver. For instance, `str `will be converted to
an empty string (''). Stored procedures can be invoked with output parameters
in various ways, as illustrated below.
```
TeradataStoredProcedureOperator(
task_id="opr_sp_types",
procedure="TEST_PROCEDURE",
parameters=[3, 1, int, str],
)
```
This will result in the statement: `{CALL TEST_PROCEDURE(?,?,?,?)}, with
parameters: [3, 1, 0, '']`.
If we omit the usage of this function, the statement would be converted to`
{CALL TEST_PROCEDURE(?,?,?,?)}, with parameters: [3, 1, <class 'int'>, <class
'str'>],` which leads to failure with an error.
Similarly, consider another invocation of the
`TeradataStoredProcedureOperator`:
```
TeradataStoredProcedureOperator(
task_id="opr_sp_place_holder",
procedure="TEST_PROCEDURE",
parameters=[3, 1, "?", "?"],
)
```
This will translate to the statement: {CALL TEST_PROCEDURE(?,?,?,?)}, with
parameters: [3, 1, ?, ?].
Example DAG -
https://github.com/apache/airflow/blob/1747e64f51f53a50a62ed31550be9ecf0c5e4ac7/tests/system/providers/teradata/example_teradata_call_sp.py
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]