I’m using a python UDF to parse an incoming messag...
# troubleshooting
h
I’m using a python UDF to parse an incoming message into an appropriate flat format. For simplicity, let’s say this is my udf definition:
Copy code
@udf(
    result_type=DataTypes.ROW([
        DataTypes.FIELD("id", DataTypes.STRING()),
        DataTypes.FIELD("name", DataTypes.STRING()),
    ])
)
def parse_json(json_str: str) -> Row:
    return Row(id='a', name='b')
Calling this UDF is easy:
Copy code
(
    table
    .add_or_replace_columns(
        call(parse_json, col('raw_message')).alias('parsed')
    )
)
So. Cool. We now have a table with the info we need. Although not quite. The new info is tucked away in the
parsed
field, but I’d really like to have them on the root level. From other SQL(ish) tools, i’m used to be able to do:
Copy code
select *, parsed.* from tbl
but this fails with an
java.lang.IndexOutOfBoundsException: Index 7 out of bounds for length 5
Am I missing something? Is there an easy way to do what I’m trying to build? (add fields with a UDF, in the root level)?
Also, interestingly, if I don’t add the alias, i can select the fields from the row from the root level (
select id, name
just works) but
select *
doesn’t (returns_cn as the column name, where n is the index)
I’m starting to think this is a bug. The above IndexOutOfBoundsException only occurs when there is another field present, taken from a nested field, like
col('nested').get('field').alias('nested_field')
If I don’t include any other nested fields, I can get some things to work, but with it included basically everything I try errors
e
Hey, did you manage to fix it? I am also getting this error