I have this schema
I want to get one single ARRAY of STRUCTS that merges (feature,numerical_value) with already array of structs of categorical_value. Be aware that category can be empty string as well, that we want to skip.
I managed to do it this way, but I am looking for an alternative shorter way:
select centroid_id,array_agg(struct(name,value) order by centroid_id) as cluster from (
select centroid_id,concat(feature,'_',category) as name,value
FROM
ML.CENTROIDS(MODEL `modelv1`), unnest(categorical_value)
where length(category)>0
union all
select centroid_id,feature as name,numerical_value as value
FROM
ML.CENTROIDS(MODEL `modelv1`)
where numerical_value is not null
)
group by centroid_id
order by centroid_id
