flow-models/macros/evm/udf_decode_hash_array.sql

32 lines
733 B
MySQL
Raw Normal View History

{% macro run_create_udf_decode_hash_array() %}
{% set sql %}
CREATE
OR REPLACE FUNCTION {{ target.database }}.streamline.udf_decode_hash_array(raw_array ARRAY)
RETURNS STRING
LANGUAGE PYTHON
2025-10-03 02:39:19 +00:00
RUNTIME_VERSION = '3.9'
HANDLER = 'decode_hash_array'
AS
$$
def decode_hash_array(raw_array):
try:
# Parse the JSON array
data = raw_array
# Extract and convert values
hex_values = [format(int(item['value']), '02x') for item in data]
# Concatenate and add prefix
result = '0x' + ''.join(hex_values)
return result.lower()
except Exception as e:
return f"Error: {str(e)}"
$$
;
{% endset %}
{% do run_query(sql) %}
{% endmacro %}