data = splitgraph`SELECT COALESCE(
CASE
WHEN biome = ANY('{"CHACO HUMEDO", "CHACO SECO"}') THEN 'CHACO'
WHEN biome = 'AMAZONIA' THEN 'AMAZON'
WHEN biome = 'MATA ATLANTICA' THEN 'ATLANTIC FOREST'
WHEN biome = ANY('{"DELTA E ISLAS DEL PARANA", "ESPINAL", "MONTE DE LLANURAS Y MESETAS", "YUNGAS"}') THEN 'OTHER'
WHEN biome = 'CAATINGA' THEN 'CERRADO'
ELSE biome END, country_of_production
) AS key1,
CASE
WHEN deforestation_commitments IS NULL THEN 'Not assessed'
WHEN deforestation_commitments && '{"NONE", "None", "No"}' THEN 'No ZDC'
ELSE 'ZDC' END AS key2,
SUM(${indicator}) AS value
FROM "trase/supply-chains"."supply-chains"
WHERE true
AND commodity = '${commodity.toUpperCase()}'
${commodity === "Palm oil" ? `AND country_of_production = 'INDONESIA'` : ``}
${
commodity === "Cocoa"
? `AND country_of_production = ANY('{"GHANA", "COTE D''IVOIRE"}')`
: ``
}
AND economic_bloc = 'EUROPEAN UNION'
AND country_of_production != 'GHANA'
AND year = ${year}
GROUP BY key1, key2`.then((res) =>
res
.map((d) => ({ ...d, key1: titleCase(d.key1), key2: d.key2 }))
.filter((d) =>
commodity === "Soy" && year === 2018 ? d.value > 200 : true
)
)