Huib
02/20/2024, 8:59 PM@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:
(
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:
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)?Huib
02/20/2024, 9:02 PMselect id, name just works) but select * doesn’t (returns_cn as the column name, where n is the index)Huib
02/20/2024, 10:14 PMcol('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 errorsElizaveta Batanina
03/20/2024, 5:28 PM