Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 09:26 AM
@elgeo @alm - passing a parameter within a function is not currently available. we can create a python UDF that generate the underlying code to pass the parameter. Then do a select statement to pass the dynamic value to execute the function.
Say for example,
def sayHello(*args):
query = """
CREATE OR REPLACE FUNCTION F_NAME(v_table_name STRING,
v_where_value INT)
RETURNS INT
RETURN SELECT MAX(id) FROM v_table_name WHERE code = {0}
"""
df = spark.sql(query.format(*args))
print(df.show(truncate=False))
return
%sql
select F_NAME('v_where_value')
Please note: The above code snippet is not syntax verified.