Adrien Arcuri
03/05/2024, 11:29 AM\ and double quotes "" in result then using multiple JSON_ARRAYAGG and JSON_OBJECT in successive JSON aggregation. I am stuck.
Apache Flink: v1.15.
---
Result: observe backslash \ between json and double quote between object {} and array []:
[
{
"my_code": "code1",
"challenges":"["{\"count":50, \"challenge\":106, \"my_rank":1}"]"
},
{
"my_code": "code2",
"challenges":"["{\"count":50, \"challenge\":106, \"my_rank":1}"]"
}
]
Code:
SQL_A as (
SELECT
offers,
my_code,
JSON_ARRAYAGG(
JSON_OBJECT(
KEY 'challenge' VALUE challenge,
KEY 'my_rank' VALUE my_rank,
KEY 'count' VALUE count
)
) as challenges
FROM
ranked_competitions
WHERE
bet_rank_per_offer_catalog_per_sport <= 5
GROUP BY
offers, sport_code
),
SQL_B as (
SELECT
offers,
JSON_ARRAYAGG(
JSON_OBJECT(
KEY 'my_code' VALUE my_code,
KEY 'challenges' VALUE challenges
)
) as
FROM
SQL_A
GROUP BY
offers
)