:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(hogql): convert a missing currency without dividing by zero (#108113)
Lucas Ricoye2293cee4965
diff --git a/posthog/hogql/database/schema/test/__snapshots__/test_groups_revenue_analytics.ambr b/posthog/hogql/database/schema/test/__snapshots__/test_groups_revenue_analytics.ambrindex cf94ffcedbe0..fa4e10819f91 100644--- a/posthog/hogql/database/schema/test/__snapshots__/test_groups_revenue_analytics.ambr+++ b/posthog/hogql/database/schema/test/__snapshots__/test_groups_revenue_analytics.ambr@@ -47,7 +47,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -93,7 +93,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -146,7 +146,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -332,7 +332,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -395,7 +395,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -512,7 +512,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -558,7 +558,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -611,7 +611,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -778,7 +778,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -841,7 +841,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -1019,7 +1019,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -1082,7 +1082,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -1260,7 +1260,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -1323,7 +1323,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -1501,7 +1501,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -1564,7 +1564,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -1743,7 +1743,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -1806,7 +1806,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -1915,7 +1915,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -1961,7 +1961,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -2014,7 +2014,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -2192,7 +2192,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -2255,7 +2255,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,diff --git a/posthog/hogql/database/schema/test/__snapshots__/test_groups_revenue_analytics.new_events_schema.ambr b/posthog/hogql/database/schema/test/__snapshots__/test_groups_revenue_analytics.new_events_schema.ambrindex 95ee1cac5118..8f97f7abf6fc 100644--- a/posthog/hogql/database/schema/test/__snapshots__/test_groups_revenue_analytics.new_events_schema.ambr+++ b/posthog/hogql/database/schema/test/__snapshots__/test_groups_revenue_analytics.new_events_schema.ambr@@ -91,32 +91,35 @@if(isNull('USD'), accurateCastOrNull(currency_aware_amount,'Decimal64(10)'), if(equals('USD','USD'), toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(0,- 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(1,- 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))))) AS amount+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(0,+ 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(1,+ 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id,@@ -207,32 +210,35 @@if(isNull('USD'), accurateCastOrNull(currency_aware_amount,'Decimal64(10)'), if(equals('USD','USD'), toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(0,- 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(1,- 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))))) AS amount+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(0,+ 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(1,+ 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id,@@ -330,32 +336,35 @@if(isNull('USD'), accurateCastOrNull(currency_aware_amount,'Decimal64(10)'), if(equals('USD','USD'), toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(0,- 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(1,- 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))))) AS amount+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(0,+ 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(1,+ 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id,@@ -522,7 +531,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -568,7 +577,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -621,7 +630,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -759,32 +768,35 @@if(isNull('USD'), accurateCastOrNull(currency_aware_amount,'Decimal64(10)'), if(equals('USD','USD'), toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(0,- 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(1,- 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))))) AS amount+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(0,+ 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(1,+ 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id,@@ -875,32 +887,35 @@if(isNull('USD'), accurateCastOrNull(currency_aware_amount,'Decimal64(10)'), if(equals('USD','USD'), toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(0,- 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(1,- 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))))) AS amount+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(0,+ 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(1,+ 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id,@@ -998,32 +1013,35 @@if(isNull('USD'), accurateCastOrNull(currency_aware_amount,'Decimal64(10)'), if(equals('USD','USD'), toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(0,- 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(1,- 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))))) AS amount+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(0,+ 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(1,+ 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id,diff --git a/posthog/hogql/database/schema/test/__snapshots__/test_persons_revenue_analytics.ambr b/posthog/hogql/database/schema/test/__snapshots__/test_persons_revenue_analytics.ambrindex 4df9d56c148c..2d67837b0ec4 100644--- a/posthog/hogql/database/schema/test/__snapshots__/test_persons_revenue_analytics.ambr+++ b/posthog/hogql/database/schema/test/__snapshots__/test_persons_revenue_analytics.ambr@@ -94,7 +94,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -147,7 +147,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -326,7 +326,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -389,7 +389,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -578,7 +578,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -641,7 +641,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -716,492 +716,467 @@SELECT persons.id AS id,persons__revenue_analytics.revenue AS revenue,persons__revenue_analytics.revenue AS `$virt_revenue`- FROM- (SELECT argMax(person.id, person.version) AS persons___id,- person.id AS id- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS persons- LEFT JOIN- (SELECT 99999 AS team_id,- person_id AS person_id,- sum(revenue) AS revenue,- sum(mrr) AS mrr- FROM- (SELECT 99999 AS team_id,- accurateCastOrNull(revenue_analytics_customer__persons.id, 'UUID') AS person_id,- coalesce(revenue_agg.revenue, accurateCastOrNull(0, 'Decimal64(10)')) AS revenue,- coalesce(mrr_agg.mrr, accurateCastOrNull(0, 'Decimal64(10)')) AS mrr- FROM- (SELECT inner.id AS id,- inner.source_label AS source_label,- inner.timestamp AS timestamp,- inner.name AS name,- inner.email AS email,- inner.phone AS phone,- inner.address AS address,- if(notEquals(JSONExtractString(inner.metadata, 'posthog_person_distinct_id'), ''), toJSONString(mapUpdate(mapFromArrays(JSONExtractKeys(ifNull(inner.metadata, '{}')), arrayMap(k -> JSONExtractString(ifNull(inner.metadata, '{}'), k), JSONExtractKeys(ifNull(inner.metadata, '{}')))), map('posthog_person_distinct_id_source', 'customer'))), if(notEquals(inner.resolved_distinct_id, ''), toJSONString(mapUpdate(mapFromArrays(JSONExtractKeys(ifNull(inner.metadata, '{}')), arrayMap(k -> JSONExtractString(ifNull(inner.metadata, '{}'), k), JSONExtractKeys(ifNull(inner.metadata, '{}')))), map('posthog_person_distinct_id', inner.resolved_distinct_id, 'posthog_person_distinct_id_source', inner.resolved_source))), inner.metadata)) AS metadata,- inner.country AS country,- inner.cohort AS cohort,- inner.initial_coupon AS initial_coupon,- inner.initial_coupon_id AS initial_coupon_id- FROM- (SELECT outer.id AS id,- 'stripe.posthog_test' AS source_label,- parseDateTime64BestEffortOrNull(toString(outer.created), 6, 'UTC') AS timestamp,- outer.name AS name,- outer.email AS email,- outer.phone AS phone,- outer.address AS address,- outer.metadata AS metadata,- JSONExtractString(address, 'country') AS country,- cohort_inner.cohort AS cohort,- cohort_inner.initial_coupon AS initial_coupon,- cohort_inner.initial_coupon_id AS initial_coupon_id,- ifNull(resolved.resolved_distinct_id, '') AS resolved_distinct_id,- ifNull(resolved.resolved_source, '') AS resolved_source- FROM- (SELECT *- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_customers/posthog_test_stripe_customer/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `name` String, `email` String, `phone` String, `address` String, `created` DateTime, `metadata` String')) AS outer- LEFT JOIN- (SELECT invoice.customer AS customer_id,- formatDateTime(toStartOfMonth(min(parseDateTime64BestEffortOrNull(toString(invoice.created), 6, 'UTC'))), '%Y-%m') AS cohort,- argMin(JSONExtractString(invoice.discount, 'coupon', 'name'), parseDateTime64BestEffortOrNull(toString(invoice.created), 6, 'UTC')) AS initial_coupon,- argMin(JSONExtractString(invoice.discount, 'coupon', 'id'), parseDateTime64BestEffortOrNull(toString(invoice.created), 6, 'UTC')) AS initial_coupon_id- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS invoice- GROUP BY invoice.customer) AS cohort_inner ON equals(cohort_inner.customer_id, outer.id)- LEFT JOIN- (SELECT child_meta.customer_id AS customer_id,- argMax(child_meta.distinct_id, child_meta.created_at) AS resolved_distinct_id,- argMax(child_meta.source_ref, child_meta.created_at) AS resolved_source- FROM- (SELECT posthog_test_stripe_invoice.customer AS customer_id,- JSONExtractString(posthog_test_stripe_invoice.metadata, 'posthog_person_distinct_id') AS distinct_id,- concat('invoice', '::', ifNull(toString(posthog_test_stripe_invoice.id), '')) AS source_ref,- parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS posthog_test_stripe_invoice- WHERE notEquals(JSONExtractString(posthog_test_stripe_invoice.metadata, 'posthog_person_distinct_id'), '')) AS child_meta- GROUP BY child_meta.customer_id) AS resolved ON equals(resolved.customer_id, outer.id)) AS inner- ORDER BY timestamp DESC- LIMIT 1 BY id) AS revenue_analytics_customer- LEFT JOIN- (SELECT persons.id AS id,- persons__pdi.distinct_id AS revenue_analytics_customer__persons___pdi___distinct_id- FROM- (SELECT argMax(person.id, person.version) AS persons___id,- person.id AS id- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS persons- LEFT JOIN- (SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id,- person_distinct_id2.distinct_id AS distinct_id- FROM person_distinct_id2- WHERE equals(person_distinct_id2.team_id, 99999)- GROUP BY person_distinct_id2.distinct_id- HAVING equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0) SETTINGS optimize_aggregation_in_order=1) AS persons__pdi ON equals(persons.persons___id, persons__pdi.person_id)) AS revenue_analytics_customer__persons ON equals(revenue_analytics_customer.email, revenue_analytics_customer__persons.revenue_analytics_customer__persons___pdi___distinct_id)- LEFT JOIN- (SELECT revenue_analytics_revenue_item.customer_id AS customer_id,- sum(revenue_analytics_revenue_item.amount) AS revenue- FROM- (SELECT if(ifNull(greater(invoice.period_months, 1), 0), concat(ifNull(toString(invoice.invoice_item_id), ''), '_', ifNull(toString(invoice.month_index), '')), invoice.invoice_item_id) AS id,- invoice.invoice_item_id AS invoice_item_id,- 'stripe.posthog_test' AS source_label,- addMonths(invoice.timestamp, invoice.month_index) AS timestamp,- invoice.created_at AS created_at,- ifNull(notEmpty(invoice.subscription_id), 0) AS is_recurring,- invoice.product_id AS product_id,- invoice.customer_id AS customer_id,- NULL AS group_0_key,- NULL AS group_1_key,- NULL AS group_2_key,- NULL AS group_3_key,- NULL AS group_4_key,- invoice.id AS invoice_id,- invoice.subscription_id AS subscription_id,- NULL AS session_id,- NULL AS event_name,- JSONExtractString(invoice.discount, 'coupon', 'name') AS coupon,- JSONExtractString(invoice.discount, 'coupon', 'id') AS coupon_id,- upper(invoice.currency) AS original_currency,- accurateCastOrNull(invoice.amount_captured, 'Decimal64(10)') AS original_amount,- in(original_currency,- ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider,- if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,- divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,- 'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount- FROM- (SELECT posthog_test_stripe_invoice.id AS id,- parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,- posthog_test_stripe_invoice.customer AS customer_id,- posthog_test_stripe_invoice.subscription AS subscription_id,- posthog_test_stripe_invoice.discount AS discount,- arrayJoin(JSONExtractArrayRaw(assumeNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(posthog_test_stripe_invoice.lines, 'data'), ''), 'null'), '^"|"$', '')))) AS data,- JSONExtractString(data, 'id') AS invoice_item_id,- JSONExtractUInt(data, 'amount') AS amount_before_discount,- coalesce(arraySum(arrayMap(x -> JSONExtractInt(x, 'amount'), JSONExtractArrayRaw(data, 'discount_amounts'))), 0) AS discount_amount,- greatest(minus(amount_before_discount, discount_amount), 0) AS amount_captured,- JSONExtractString(data, 'currency') AS currency,- JSONExtractString(data, 'price', 'product') AS product_id,- fromUnixTimestamp(JSONExtractUInt(data, 'period', 'start')) AS period_start,- fromUnixTimestamp(JSONExtractUInt(data, 'period', 'end')) AS period_end,- greatest(toInt16(round(divide(dateDiff('day', ifNull(period_start, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC')), ifNull(period_end, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC'))), 30.44))), 1) AS period_months,- arrayJoin(range(0, period_months)) AS month_index,- ifNull(period_start, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC')) AS timestamp- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS posthog_test_stripe_invoice- WHERE if(isNull(posthog_test_stripe_invoice.paid), equals(posthog_test_stripe_invoice.status, 'paid'), posthog_test_stripe_invoice.paid)) AS invoice) AS revenue_analytics_revenue_item- GROUP BY customer_id) AS revenue_agg ON equals(revenue_analytics_customer.id, revenue_agg.customer_id)- LEFT JOIN- (SELECT `stripe.posthog_test.mrr_revenue_view`.customer_id AS customer_id,- sum(`stripe.posthog_test.mrr_revenue_view`.mrr) AS mrr- FROM- (SELECT union.source_label AS source_label,- union.customer_id AS customer_id,- union.subscription_id AS subscription_id,- argMax(union.amount, union.timestamp) AS mrr- FROM- (SELECT revenue_item.source_label AS source_label,- revenue_item.customer_id AS customer_id,- revenue_item.subscription_id AS subscription_id,- toStartOfMonth(toTimeZone(revenue_item.timestamp, 'UTC')) AS timestamp,- sum(revenue_item.amount) AS amount- FROM- (SELECT if(ifNull(greater(invoice.period_months, 1), 0), concat(ifNull(toString(invoice.invoice_item_id), ''), '_', ifNull(toString(invoice.month_index), '')), invoice.invoice_item_id) AS id,- invoice.invoice_item_id AS invoice_item_id,- 'stripe.posthog_test' AS source_label,- addMonths(invoice.timestamp, invoice.month_index) AS timestamp,- invoice.created_at AS created_at,- ifNull(notEmpty(invoice.subscription_id), 0) AS is_recurring,- invoice.product_id AS product_id,- invoice.customer_id AS customer_id,- NULL AS group_0_key,- NULL AS group_1_key,- NULL AS group_2_key,- NULL AS group_3_key,- NULL AS group_4_key,- invoice.id AS invoice_id,- invoice.subscription_id AS subscription_id,- NULL AS session_id,- NULL AS event_name,- JSONExtractString(invoice.discount, 'coupon', 'name') AS coupon,- JSONExtractString(invoice.discount, 'coupon', 'id') AS coupon_id,- upper(invoice.currency) AS original_currency,- accurateCastOrNull(invoice.amount_captured, 'Decimal64(10)') AS original_amount,- in(original_currency,- ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider,- if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,- divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,- 'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount- FROM- (SELECT posthog_test_stripe_invoice.id AS id,- parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,- posthog_test_stripe_invoice.customer AS customer_id,- posthog_test_stripe_invoice.subscription AS subscription_id,- posthog_test_stripe_invoice.discount AS discount,- arrayJoin(JSONExtractArrayRaw(assumeNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(posthog_test_stripe_invoice.lines, 'data'), ''), 'null'), '^"|"$', '')))) AS data,- JSONExtractString(data, 'id') AS invoice_item_id,- JSONExtractUInt(data, 'amount') AS amount_before_discount,- coalesce(arraySum(arrayMap(x -> JSONExtractInt(x, 'amount'), JSONExtractArrayRaw(data, 'discount_amounts'))), 0) AS discount_amount,- greatest(minus(amount_before_discount, discount_amount), 0) AS amount_captured,- JSONExtractString(data, 'currency') AS currency,- JSONExtractString(data, 'price', 'product') AS product_id,- fromUnixTimestamp(JSONExtractUInt(data, 'period', 'start')) AS period_start,- fromUnixTimestamp(JSONExtractUInt(data, 'period', 'end')) AS period_end,- greatest(toInt16(round(divide(dateDiff('day', ifNull(period_start, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC')), ifNull(period_end, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC'))), 30.44))), 1) AS period_months,- arrayJoin(range(0, period_months)) AS month_index,- ifNull(period_start, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC')) AS timestamp- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS posthog_test_stripe_invoice- WHERE if(isNull(posthog_test_stripe_invoice.paid), equals(posthog_test_stripe_invoice.status, 'paid'), posthog_test_stripe_invoice.paid)) AS invoice) AS revenue_item- WHERE and(revenue_item.is_recurring, isNotNull(revenue_item.subscription_id), ifNull(greaterOrEquals(timestamp, toStartOfMonth(addDays(toDateTime64('2025-05-30 00:00:00.000000', 6, 'UTC'), -60))), 0), ifNull(lessOrEquals(timestamp, toDateTime64('2025-05-30 00:00:00.000000', 6, 'UTC')), 0))- GROUP BY revenue_item.source_label,- revenue_item.customer_id,- revenue_item.subscription_id, timestamp- ORDER BY timestamp DESC- UNION ALL SELECT `stripe.posthog_test.subscription_revenue_view`.source_label AS source_label,- `stripe.posthog_test.subscription_revenue_view`.customer_id AS customer_id,- `stripe.posthog_test.subscription_revenue_view`.id AS subscription_id,- toTimeZone(`stripe.posthog_test.subscription_revenue_view`.ended_at, 'UTC') AS timestamp,- accurateCastOrNull(0, 'Decimal64(10)') AS amount- FROM- (SELECT '' AS id,- '' AS source_label,- '' AS plan_id,- '' AS product_id,- '' AS customer_id,- '' AS status,- toDateTime64('1970-01-01 00:00:00.000000', 6, 'UTC') AS started_at,- toDateTime64('1970-01-01 00:00:00.000000', 6, 'UTC') AS ended_at,- '' AS metadata- WHERE 0) AS `stripe.posthog_test.subscription_revenue_view`- WHERE and(ifNull(greaterOrEquals(timestamp, toStartOfMonth(addDays(toDateTime64('2025-05-30 00:00:00.000000', 6, 'UTC'), -60))), 0), ifNull(lessOrEquals(timestamp, toDateTime64('2025-05-30 00:00:00.000000', 6, 'UTC')), 0))- ORDER BY timestamp DESC) AS- union- GROUP BY source_label,- customer_id,- subscription_id- ORDER BY customer_id ASC,- subscription_id ASC) AS `stripe.posthog_test.mrr_revenue_view`- GROUP BY customer_id) AS mrr_agg ON equals(revenue_analytics_customer.id, mrr_agg.customer_id))- WHERE ifNull(notEquals(person_id, accurateCastOrNull('00000000-0000-0000-0000-000000000000', 'UUID')), isNotNull(person_id)- or isNotNull(accurateCastOrNull('00000000-0000-0000-0000-000000000000', 'UUID')))- GROUP BY person_id) AS persons__revenue_analytics ON equals(persons.persons___id, persons__revenue_analytics.person_id)- ORDER BY persons.id ASC- LIMIT 100 SETTINGS format_csv_allow_double_quotes=1,- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestPersonsRevenueAnalytics.test_get_revenue_for_schema_source_for_id_join- '''- SELECT persons.id AS id,- persons__revenue_analytics.revenue AS revenue- FROM- (SELECT argMax(person.id, person.version) AS persons___id,- person.id AS id- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS persons- LEFT JOIN- (SELECT 99999 AS team_id,- person_id AS person_id,- sum(revenue) AS revenue,- sum(mrr) AS mrr- FROM- (SELECT 99999 AS team_id,- accurateCastOrNull(revenue_analytics_customer__persons.id, 'UUID') AS person_id,- coalesce(revenue_agg.revenue, accurateCastOrNull(0, 'Decimal64(10)')) AS revenue,- coalesce(mrr_agg.mrr, accurateCastOrNull(0, 'Decimal64(10)')) AS mrr- FROM- (SELECT inner.id AS id,- inner.source_label AS source_label,- inner.timestamp AS timestamp,- inner.name AS name,- inner.email AS email,- inner.phone AS phone,- inner.address AS address,- if(notEquals(JSONExtractString(inner.metadata, 'posthog_person_distinct_id'), ''), toJSONString(mapUpdate(mapFromArrays(JSONExtractKeys(ifNull(inner.metadata, '{}')), arrayMap(k -> JSONExtractString(ifNull(inner.metadata, '{}'), k), JSONExtractKeys(ifNull(inner.metadata, '{}')))), map('posthog_person_distinct_id_source', 'customer'))), if(notEquals(inner.resolved_distinct_id, ''), toJSONString(mapUpdate(mapFromArrays(JSONExtractKeys(ifNull(inner.metadata, '{}')), arrayMap(k -> JSONExtractString(ifNull(inner.metadata, '{}'), k), JSONExtractKeys(ifNull(inner.metadata, '{}')))), map('posthog_person_distinct_id', inner.resolved_distinct_id, 'posthog_person_distinct_id_source', inner.resolved_source))), inner.metadata)) AS metadata,- inner.country AS country,- inner.cohort AS cohort,- inner.initial_coupon AS initial_coupon,- inner.initial_coupon_id AS initial_coupon_id- FROM- (SELECT outer.id AS id,- 'stripe.posthog_test' AS source_label,- parseDateTime64BestEffortOrNull(toString(outer.created), 6, 'UTC') AS timestamp,- outer.name AS name,- outer.email AS email,- outer.phone AS phone,- outer.address AS address,- outer.metadata AS metadata,- JSONExtractString(address, 'country') AS country,- cohort_inner.cohort AS cohort,- cohort_inner.initial_coupon AS initial_coupon,- cohort_inner.initial_coupon_id AS initial_coupon_id,- ifNull(resolved.resolved_distinct_id, '') AS resolved_distinct_id,- ifNull(resolved.resolved_source, '') AS resolved_source- FROM- (SELECT *- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_customers/posthog_test_stripe_customer/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `name` String, `email` String, `phone` String, `address` String, `created` DateTime, `metadata` String')) AS outer- LEFT JOIN- (SELECT invoice.customer AS customer_id,- formatDateTime(toStartOfMonth(min(parseDateTime64BestEffortOrNull(toString(invoice.created), 6, 'UTC'))), '%Y-%m') AS cohort,- argMin(JSONExtractString(invoice.discount, 'coupon', 'name'), parseDateTime64BestEffortOrNull(toString(invoice.created), 6, 'UTC')) AS initial_coupon,- argMin(JSONExtractString(invoice.discount, 'coupon', 'id'), parseDateTime64BestEffortOrNull(toString(invoice.created), 6, 'UTC')) AS initial_coupon_id- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS invoice- GROUP BY invoice.customer) AS cohort_inner ON equals(cohort_inner.customer_id, outer.id)- LEFT JOIN- (SELECT child_meta.customer_id AS customer_id,- argMax(child_meta.distinct_id, child_meta.created_at) AS resolved_distinct_id,- argMax(child_meta.source_ref, child_meta.created_at) AS resolved_source- FROM- (SELECT posthog_test_stripe_invoice.customer AS customer_id,- JSONExtractString(posthog_test_stripe_invoice.metadata, 'posthog_person_distinct_id') AS distinct_id,- concat('invoice', '::', ifNull(toString(posthog_test_stripe_invoice.id), '')) AS source_ref,- parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS posthog_test_stripe_invoice- WHERE notEquals(JSONExtractString(posthog_test_stripe_invoice.metadata, 'posthog_person_distinct_id'), '')) AS child_meta- GROUP BY child_meta.customer_id) AS resolved ON equals(resolved.customer_id, outer.id)) AS inner- ORDER BY timestamp DESC- LIMIT 1 BY id) AS revenue_analytics_customer- LEFT JOIN- (SELECT persons.id AS id,- persons__pdi.distinct_id AS revenue_analytics_customer__persons___pdi___distinct_id- FROM- (SELECT argMax(person.id, person.version) AS persons___id,- person.id AS id- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS persons- LEFT JOIN- (SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id,- person_distinct_id2.distinct_id AS distinct_id- FROM person_distinct_id2- WHERE equals(person_distinct_id2.team_id, 99999)- GROUP BY person_distinct_id2.distinct_id- HAVING equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0) SETTINGS optimize_aggregation_in_order=1) AS persons__pdi ON equals(persons.persons___id, persons__pdi.person_id)) AS revenue_analytics_customer__persons ON equals(revenue_analytics_customer.id, revenue_analytics_customer__persons.revenue_analytics_customer__persons___pdi___distinct_id)- LEFT JOIN- (SELECT revenue_analytics_revenue_item.customer_id AS customer_id,- sum(revenue_analytics_revenue_item.amount) AS revenue- FROM- (SELECT if(ifNull(greater(invoice.period_months, 1), 0), concat(ifNull(toString(invoice.invoice_item_id), ''), '_', ifNull(toString(invoice.month_index), '')), invoice.invoice_item_id) AS id,- invoice.invoice_item_id AS invoice_item_id,- 'stripe.posthog_test' AS source_label,- addMonths(invoice.timestamp, invoice.month_index) AS timestamp,- invoice.created_at AS created_at,- ifNull(notEmpty(invoice.subscription_id), 0) AS is_recurring,- invoice.product_id AS product_id,- invoice.customer_id AS customer_id,- NULL AS group_0_key,- NULL AS group_1_key,- NULL AS group_2_key,- NULL AS group_3_key,- NULL AS group_4_key,- invoice.id AS invoice_id,- invoice.subscription_id AS subscription_id,- NULL AS session_id,- NULL AS event_name,- JSONExtractString(invoice.discount, 'coupon', 'name') AS coupon,- JSONExtractString(invoice.discount, 'coupon', 'id') AS coupon_id,- upper(invoice.currency) AS original_currency,- accurateCastOrNull(invoice.amount_captured, 'Decimal64(10)') AS original_amount,- in(original_currency,- ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider,- if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,- divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,- 'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount- FROM- (SELECT posthog_test_stripe_invoice.id AS id,- parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,- posthog_test_stripe_invoice.customer AS customer_id,- posthog_test_stripe_invoice.subscription AS subscription_id,- posthog_test_stripe_invoice.discount AS discount,- arrayJoin(JSONExtractArrayRaw(assumeNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(posthog_test_stripe_invoice.lines, 'data'), ''), 'null'), '^"|"$', '')))) AS data,- JSONExtractString(data, 'id') AS invoice_item_id,- JSONExtractUInt(data, 'amount') AS amount_before_discount,- coalesce(arraySum(arrayMap(x -> JSONExtractInt(x, 'amount'), JSONExtractArrayRaw(data, 'discount_amounts'))), 0) AS discount_amount,- greatest(minus(amount_before_discount, discount_amount), 0) AS amount_captured,- JSONExtractString(data, 'currency') AS currency,- JSONExtractString(data, 'price', 'product') AS product_id,- fromUnixTimestamp(JSONExtractUInt(data, 'period', 'start')) AS period_start,- fromUnixTimestamp(JSONExtractUInt(data, 'period', 'end')) AS period_end,- greatest(toInt16(round(divide(dateDiff('day', ifNull(period_start, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC')), ifNull(period_end, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC'))), 30.44))), 1) AS period_months,- arrayJoin(range(0, period_months)) AS month_index,- ifNull(period_start, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC')) AS timestamp- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS posthog_test_stripe_invoice- WHERE if(isNull(posthog_test_stripe_invoice.paid), equals(posthog_test_stripe_invoice.status, 'paid'), posthog_test_stripe_invoice.paid)) AS invoice) AS revenue_analytics_revenue_item- GROUP BY customer_id) AS revenue_agg ON equals(revenue_analytics_customer.id, revenue_agg.customer_id)- LEFT JOIN- (SELECT `stripe.posthog_test.mrr_revenue_view`.customer_id AS customer_id,- sum(`stripe.posthog_test.mrr_revenue_view`.mrr) AS mrr- FROM- (SELECT union.source_label AS source_label,- union.customer_id AS customer_id,- union.subscription_id AS subscription_id,- argMax(union.amount, union.timestamp) AS mrr- FROM- (SELECT revenue_item.source_label AS source_label,- revenue_item.customer_id AS customer_id,- revenue_item.subscription_id AS subscription_id,- toStartOfMonth(toTimeZone(revenue_item.timestamp, 'UTC')) AS timestamp,- sum(revenue_item.amount) AS amount- FROM- (SELECT if(ifNull(greater(invoice.period_months, 1), 0), concat(ifNull(toString(invoice.invoice_item_id), ''), '_', ifNull(toString(invoice.month_index), '')), invoice.invoice_item_id) AS id,- invoice.invoice_item_id AS invoice_item_id,- 'stripe.posthog_test' AS source_label,- addMonths(invoice.timestamp, invoice.month_index) AS timestamp,- invoice.created_at AS created_at,- ifNull(notEmpty(invoice.subscription_id), 0) AS is_recurring,- invoice.product_id AS product_id,- invoice.customer_id AS customer_id,- NULL AS group_0_key,- NULL AS group_1_key,- NULL AS group_2_key,- NULL AS group_3_key,- NULL AS group_4_key,- invoice.id AS invoice_id,- invoice.subscription_id AS subscription_id,- NULL AS session_id,- NULL AS event_name,- JSONExtractString(invoice.discount, 'coupon', 'name') AS coupon,- JSONExtractString(invoice.discount, 'coupon', 'id') AS coupon_id,- upper(invoice.currency) AS original_currency,- accurateCastOrNull(invoice.amount_captured, 'Decimal64(10)') AS original_amount,- in(original_currency,- ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider,- if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,- divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,- 'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount- FROM- (SELECT posthog_test_stripe_invoice.id AS id,- parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,- posthog_test_stripe_invoice.customer AS customer_id,- posthog_test_stripe_invoice.subscription AS subscription_id,- posthog_test_stripe_invoice.discount AS discount,- arrayJoin(JSONExtractArrayRaw(assumeNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(posthog_test_stripe_invoice.lines, 'data'), ''), 'null'), '^"|"$', '')))) AS data,- JSONExtractString(data, 'id') AS invoice_item_id,- JSONExtractUInt(data, 'amount') AS amount_before_discount,- coalesce(arraySum(arrayMap(x -> JSONExtractInt(x, 'amount'), JSONExtractArrayRaw(data, 'discount_amounts'))), 0) AS discount_amount,- greatest(minus(amount_before_discount, discount_amount), 0) AS amount_captured,- JSONExtractString(data, 'currency') AS currency,- JSONExtractString(data, 'price', 'product') AS product_id,- fromUnixTimestamp(JSONExtractUInt(data, 'period', 'start')) AS period_start,- fromUnixTimestamp(JSONExtractUInt(data, 'period', 'end')) AS period_end,- greatest(toInt16(round(divide(dateDiff('day', ifNull(period_start, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC')), ifNull(period_end, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC'))), 30.44))), 1) AS period_months,- arrayJoin(range(0, period_months)) AS month_index,- ifNull(period_start, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC')) AS timestamp- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS posthog_test_stripe_invoice- WHERE if(isNull(posthog_test_stripe_invoice.paid), equals(posthog_test_stripe_invoice.status, 'paid'), posthog_test_stripe_invoice.paid)) AS invoice) AS revenue_item- WHERE and(revenue_item.is_recurring, isNotNull(revenue_item.subscription_id), ifNull(greaterOrEquals(timestamp, toStartOfMonth(addDays(toDateTime64('2025-05-30 00:00:00.000000', 6, 'UTC'), -60))), 0), ifNull(lessOrEquals(timestamp, toDateTime64('2025-05-30 00:00:00.000000', 6, 'UTC')), 0))- GROUP BY revenue_item.source_label,- revenue_item.customer_id,- revenue_item.subscription_id, timestamp- ORDER BY timestamp DESC- UNION ALL SELECT `stripe.posthog_test.subscription_revenue_view`.source_label AS source_label,- `stripe.posthog_test.subscription_revenue_view`.customer_id AS customer_id,- `stripe.posthog_test.subscription_revenue_view`.id AS subscription_id,- toTimeZone(`stripe.posthog_test.subscription_revenue_view`.ended_at, 'UTC') AS timestamp,- accurateCastOrNull(0, 'Decimal64(10)') AS amount- FROM- (SELECT '' AS id,- '' AS source_label,- '' AS plan_id,- '' AS product_id,- '' AS customer_id,- '' AS status,- toDateTime64('1970-01-01 00:00:00.000000', 6, 'UTC') AS started_at,- toDateTime64('1970-01-01 00:00:00.000000', 6, 'UTC') AS ended_at,- '' AS metadata- WHERE 0) AS `stripe.posthog_test.subscription_revenue_view`- WHERE and(ifNull(greaterOrEquals(timestamp, toStartOfMonth(addDays(toDateTime64('2025-05-30 00:00:00.000000', 6, 'UTC'), -60))), 0), ifNull(lessOrEquals(timestamp, toDateTime64('2025-05-30 00:00:00.000000', 6, 'UTC')), 0))- ORDER BY timestamp DESC) AS- union- GROUP BY source_label,- customer_id,- subscription_id- ORDER BY customer_id ASC,- subscription_id ASC) AS `stripe.posthog_test.mrr_revenue_view`- GROUP BY customer_id) AS mrr_agg ON equals(revenue_analytics_customer.id, mrr_agg.customer_id))- WHERE ifNull(notEquals(person_id, accurateCastOrNull('00000000-0000-0000-0000-000000000000', 'UUID')), isNotNull(person_id)- or isNotNull(accurateCastOrNull('00000000-0000-0000-0000-000000000000', 'UUID')))- GROUP BY person_id) AS persons__revenue_analytics ON equals(persons.persons___id, persons__revenue_analytics.person_id)+ FROM (+ SELECT argMax(person.id,+ person.version) AS persons___id,+ person.id AS id+ FROM person+ WHERE equals(person.team_id,+ 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted,+ person.version), 0), less(argMax(toTimeZone(person.created_at,+ 'UTC'), person.version), plus(now64(6,+ 'UTC'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS persons+ LEFT JOIN (+ SELECT 99999 AS team_id,+ person_id AS person_id,+ sum(revenue) AS revenue,+ sum(mrr) AS mrr+ FROM (+ SELECT 99999 AS team_id,+ accurateCastOrNull(revenue_analytics_customer__persons.id,+ 'UUID') AS person_id,+ coalesce(revenue_agg.revenue,+ accurateCastOrNull(0,+ 'Decimal64(10)')) AS revenue,+ coalesce(mrr_agg.mrr,+ accurateCastOrNull(0,+ 'Decimal64(10)')) AS mrr+ FROM (+ SELECT inner.id AS id,+ inner.source_label AS source_label,+ inner.timestamp AS timestamp,+ inner.name AS name,+ inner.email AS email,+ inner.phone AS phone,+ inner.address AS address,+ if(notEquals(JSONExtractString(inner.metadata,+ 'posthog_person_distinct_id'), ''), toJSONString(mapUpdate(mapFromArrays(JSONExtractKeys(ifNull(inner.metadata,+ '{}')), arrayMap(k -> JSONExtractString(ifNull(inner.metadata,+ '{}'), k), JSONExtractKeys(ifNull(inner.metadata,+ '{}')))), map('posthog_person_distinct_id_source',+ 'customer'))), if(notEquals(inner.resolved_distinct_id,+ ''), toJSONString(mapUpdate(mapFromArrays(JSONExtractKeys(ifNull(inner.metadata,+ '{}')), arrayMap(k -> JSONExtractString(ifNull(inner.metadata,+ '{}'), k), JSONExtractKeys(ifNull(inner.metadata,+ '{}')))), map('posthog_person_distinct_id',+ inner.resolved_distinct_id,+ 'posthog_person_distinct_id_source',+ inner.resolved_source))), inner.metadata)) AS metadata,+ inner.country AS country,+ inner.cohort AS cohort,+ inner.initial_coupon AS initial_coupon,+ inner.initial_coupon_id AS initial_coupon_id+ FROM (+ SELECT outer.id AS id,+ 'stripe.posthog_test' AS source_label,+ parseDateTime64BestEffortOrNull(toString(outer.created), 6,+ 'UTC') AS timestamp,+ outer.name AS name,+ outer.email AS email,+ outer.phone AS phone,+ outer.address AS address,+ outer.metadata AS metadata,+ JSONExtractString(address,+ 'country') AS country,+ cohort_inner.cohort AS cohort,+ cohort_inner.initial_coupon AS initial_coupon,+ cohort_inner.initial_coupon_id AS initial_coupon_id,+ ifNull(resolved.resolved_distinct_id,+ '') AS resolved_distinct_id,+ ifNull(resolved.resolved_source,+ '') AS resolved_source+ FROM (+ SELECT *+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_customers/posthog_test_stripe_customer/*.csv',+ 'object_storage_root_user',+ 'object_storage_root_password',+ 'CSVWithNames',+ '`id` String, `name` String, `email` String, `phone` String, `address` String, `created` DateTime, `metadata` String')) AS outer+ LEFT JOIN (+ SELECT invoice.customer AS customer_id,+ formatDateTime(toStartOfMonth(min(parseDateTime64BestEffortOrNull(toString(invoice.created), 6,+ 'UTC'))), '%Y-%m') AS cohort,+ argMin(JSONExtractString(invoice.discount,+ 'coupon',+ 'name'), parseDateTime64BestEffortOrNull(toString(invoice.created), 6,+ 'UTC')) AS initial_coupon,+ argMin(JSONExtractString(invoice.discount,+ 'coupon',+ 'id'), parseDateTime64BestEffortOrNull(toString(invoice.created), 6,+ 'UTC')) AS initial_coupon_id+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv',+ 'object_storage_root_user',+ 'object_storage_root_password',+ 'CSVWithNames',+ '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS invoice+ GROUP BY invoice.customer) AS cohort_inner ON equals(cohort_inner.customer_id,+ outer.id)+ LEFT JOIN (+ SELECT child_meta.customer_id AS customer_id,+ argMax(child_meta.distinct_id,+ child_meta.created_at) AS resolved_distinct_id,+ argMax(child_meta.source_ref,+ child_meta.created_at) AS resolved_source+ FROM (+ SELECT posthog_test_stripe_invoice.customer AS customer_id,+ JSONExtractString(posthog_test_stripe_invoice.metadata,+ 'posthog_person_distinct_id') AS distinct_id,+ concat('invoice',+ '::',+ ifNull(toString(posthog_test_stripe_invoice.id), '')) AS source_ref,+ parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,+ 'UTC') AS created_at+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv',+ 'object_storage_root_user',+ 'object_storage_root_password',+ 'CSVWithNames',+ '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS posthog_test_stripe_invoice+ WHERE notEquals(JSONExtractString(posthog_test_stripe_invoice.metadata,+ 'posthog_person_distinct_id'), '')) AS child_meta+ GROUP BY child_meta.customer_id) AS resolved ON equals(resolved.customer_id,+ outer.id)) AS inner+ ORDER BY timestamp DESC+ LIMIT 1 BY id) AS revenue_analytics_customer+ LEFT JOIN (+ SELECT persons.id AS id,+ persons__pdi.distinct_id AS revenue_analytics_customer__persons___pdi___distinct_id+ FROM (+ SELECT argMax(person.id,+ person.version) AS persons___id,+ person.id AS id+ FROM person+ WHERE equals(person.team_id,+ 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted,+ person.version), 0), less(argMax(toTimeZone(person.created_at,+ 'UTC'), person.version), plus(now64(6,+ 'UTC'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS persons+ LEFT JOIN (+ SELECT argMax(person_distinct_id2.person_id,+ person_distinct_id2.version) AS person_id,+ person_distinct_id2.distinct_id AS distinct_id+ FROM person_distinct_id2+ WHERE equals(person_distinct_id2.team_id,+ 99999)+ GROUP BY person_distinct_id2.distinct_id+ HAVING equals(argMax(person_distinct_id2.is_deleted,+ person_distinct_id2.version), 0) SETTINGS optimize_aggregation_in_order=1) AS persons__pdi ON equals(persons.persons___id,+ persons__pdi.person_id)) AS revenue_analytics_customer__persons ON equals(revenue_analytics_customer.email,+ revenue_analytics_customer__persons.revenue_analytics_customer__persons___pdi___distinct_id)+ LEFT JOIN (+ SELECT revenue_analytics_revenue_item.customer_id AS customer_id,+ sum(revenue_analytics_revenue_item.amount) AS revenue+ FROM (+ SELECT if(ifNull(greater(invoice.period_months,+ 1), 0), concat(ifNull(toString(invoice.invoice_item_id), ''), '_',+ ifNull(toString(invoice.month_index), '')), invoice.invoice_item_id) AS id,+ invoice.invoice_item_id AS invoice_item_id,+ 'stripe.posthog_test' AS source_label,+ addMonths(invoice.timestamp,+ invoice.month_index) AS timestamp,+ invoice.created_at AS created_at,+ ifNull(notEmpty(invoice.subscription_id), 0) AS is_recurring,+ invoice.product_id AS product_id,+ invoice.customer_id AS customer_id,+ NULL AS group_0_key,+ NULL AS group_1_key,+ NULL AS group_2_key,+ NULL AS group_3_key,+ NULL AS group_4_key,+ invoice.id AS invoice_id,+ invoice.subscription_id AS subscription_id,+ NULL AS session_id,+ NULL AS event_name,+ JSONExtractString(invoice.discount,+ 'coupon',+ 'name') AS coupon,+ JSONExtractString(invoice.discount,+ 'coupon',+ 'id') AS coupon_id,+ upper(invoice.currency) AS original_currency,+ accurateCastOrNull(invoice.amount_captured,+ 'Decimal64(10)') AS original_amount,+ in(original_currency,+ ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider,+ if(enable_currency_aware_divider,+ accurateCastOrNull(1,+ 'Decimal64(10)'), accurateCastOrNull(100,+ 'Decimal64(10)')) AS currency_aware_divider,+ divideDecimal(original_amount,+ currency_aware_divider) AS currency_aware_amount,+ 'GBP' AS currency,+ divideDecimal(if(equals(original_currency,+ currency), toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ original_currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(0,+ 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ original_currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(1,+ 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ original_currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10))))), accurateCastOrNull(invoice.period_months,+ 'Decimal64(10)')) AS amount+ FROM (+ SELECT posthog_test_stripe_invoice.id AS id,+ parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,+ 'UTC') AS created_at,+ posthog_test_stripe_invoice.customer AS customer_id,+ posthog_test_stripe_invoice.subscription AS subscription_id,+ posthog_test_stripe_invoice.discount AS discount,+ arrayJoin(JSONExtractArrayRaw(assumeNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(posthog_test_stripe_invoice.lines,+ 'data'), ''), 'null'), '^"|"$',+ '')))) AS data,+ JSONExtractString(data,+ 'id') AS invoice_item_id,+ JSONExtractUInt(data,+ 'amount') AS amount_before_discount,+ coalesce(arraySum(arrayMap(x -> JSONExtractInt(x,+ 'amount'), JSONExtractArrayRaw(data,+ 'discount_amounts'))), 0) AS discount_amount,+ greatest(minus(amount_before_discount,+ discount_amount), 0) AS amount_captured,+ JSONExtractString(data,+ 'currency') AS currency,+ JSONExtractString(data,+ 'price',+ 'product') AS product_id,+ fromUnixTimestamp(JSONExtractUInt(data,+ 'period',+ 'start')) AS period_start,+ fromUnixTimestamp(JSONExtractUInt(data,+ 'period',+ 'end')) AS period_end,+ greatest(toInt16(round(divide(dateDiff('day',+ ifNull(period_start,+ parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,+ 'UTC')), ifNull(period_end,+ parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,+ 'UTC'))), 30.44))), 1) AS period_months,+ arrayJoin(range(0,+ period_months)) AS month_index,+ ifNull(period_start,+ parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,+ 'UTC')) AS timestamp+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv',+ 'object_storage_root_user',+ 'object_storage_root_password',+ 'CSVWithNames',+ '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS posthog_test_stripe_invoice+ WHERE if(isNull(posthog_test_stripe_invoice.paid), equals(posthog_test_stripe_invoice.status,+ 'paid'), posthog_test_stripe_invoice.paid)) AS invoice) AS revenue_analytics_revenue_item+ GROUP BY customer_id) AS revenue_agg ON equals(revenue_analytics_customer.id,+ revenue_agg.customer_id)+ LEFT JOIN (+ SELECT `stripe.posthog_test.mrr_revenue_view`.customer_id AS customer_id,+ sum(`stripe.posthog_test.mrr_revenue_view`.mrr) AS mrr+ FROM (+ SELECT union.source_label AS source_label,+ union.customer_id AS customer_id,+ union.subscription_id AS subscription_id,+ argMax(union.amount,+ union.timestamp) AS mrr+ FROM (+ SELECT revenue_item.source_label AS source_label,+ revenue_item.customer_id AS customer_id,+ revenue_item.subscription_id AS subscription_id,+ toStartOfMonth(toTimeZone(revenue_item.timestamp,+ 'UTC')) AS timestamp,+ sum(revenue_item.amount) AS amount+ FROM (+ SELECT if(ifNull(greater(invoice.period_months,+ 1), 0), concat(ifNull(toString(invoice.invoice_item_id), ''), '_',+ ifNull(toString(invoice.month_index), '')), invoice.invoice_item_id) AS id,+ invoice.invoice_item_id AS invoice_item_id,+ 'stripe.posthog_test' AS source_label,+ addMonths(invoice.timestamp,+ invoice.month_index) AS timestamp,+ invoice.created_at AS created_at,+ ifNull(notEmpty(invoice.subscription_id), 0) AS is_recurring,+ invoice.product_id AS product_id,+ invoice.customer_id AS customer_id,+ NULL AS group_0_key,+ NULL AS group_1_key,+ NULL AS group_2_key,+ NULL AS group_3_key,+ NULL AS group_4_key,+ invoice.id AS invoice_id,+ invoice.subscription_id AS subscription_id,+ NULL AS session_id,+ NULL AS event_name,+ JSONExtractString(invoice.discount,+ 'coupon',+ 'name') AS coupon,+ JSONExtractString(invoice.discount,+ 'coupon',+ 'id') AS coupon_id,+ upper(invoice.currency) AS original_currency,+ accurateCastOrNull(invoice.amount_captured,+ 'Decimal64(10)') AS original_amount,+ in(original_currency,+ ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider,+ if(enable_currency_aware_divider,+ accurateCastOrNull(1,+ 'Decimal64(10)'), accurateCastOrNull(100,+ 'Decimal64(10)')) AS currency_aware_divider,+ divideDecimal(original_amount,+ currency_aware_divider) AS currency_aware_amount,+ 'GBP' AS currency,+ divideDecimal(if(equals(original_currency,+ currency), toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ original_currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(0,+ 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ original_currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(1,+ 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ original_currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10))))), accurateCastOrNull(invoice.period_months,+ 'Decimal64(10)')) AS amount+ FROM (+ SELECT posthog_test_stripe_invoice.id AS id,+ parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,+ 'UTC') AS created_at,+ posthog_test_stripe_invoice.customer AS customer_id,+ posthog_test_stripe_invoice.subscription AS subscription_id,+ posthog_test_stripe_invoice.discount AS discount,+ arrayJoin(JSONExtractArrayRaw(assumeNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(posthog_test_stripe_invoice.lines,+ 'data'), ''), 'null'), '^"|"$',+ '')))) AS data,+ JSONExtractString(data,+ 'id') AS invoice_item_id,+ JSONExtractUInt(data,+ 'amount') AS amount_before_discount,+ coalesce(arraySum(arrayMap(x -> JSONExtractInt(x,+ 'amount'), JSONExtractArrayRaw(data,+ 'discount_amounts'))), 0) AS discount_amount,+ greatest(minus(amount_before_discount,+ discount_amount), 0) AS amount_captured,+ JSONExtractString(data,+ 'currency') AS currency,+ JSONExtractString(data,+ 'price',+ 'product') AS product_id,+ fromUnixTimestamp(JSONExtractUInt(data,+ 'period',+ 'start')) AS period_start,+ fromUnixTimestamp(JSONExtractUInt(data,+ 'period',+ 'end')) AS period_end,+ greatest(toInt16(round(divide(dateDiff('day',+ ifNull(period_start,+ parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,+ 'UTC')), ifNull(period_end,+ parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,+ 'UTC'))), 30.44))), 1) AS period_months,+ arrayJoin(range(0,+ period_months)) AS month_index,+ ifNull(period_start,+ parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,+ 'UTC')) AS timestamp+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv',+ 'object_storage_root_user',+ 'object_storage_root_password',+ 'CSVWithNames',+ '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS posthog_test_stripe_invoice+ WHERE if(isNull(posthog_test_stripe_invoice.paid), equals(posthog_test_stripe_invoice.status,+ 'paid'), posthog_test_stripe_invoice.paid)) AS invoice) AS revenue_item WHERE and(revenue_item.is_recurring,+ isNotNull(revenue_item.subscription_id), ifNull(greaterOrEquals(timestamp, toStartOfMonth(addDays(toDateTime64('2025-05-30 00:00:00.000000',+ 6,+ 'UTC'), -60))), 0), ifNull(lessOrEquals(timestamp, toDateTime64('2025-05-30 00:00:00.000000',+ 6,+ 'UTC')), 0))+ GROUP BY revenue_item.source_label,+ revenue_item.customer_id,+ revenue_item.subscription_id, timestamp+ ORDER BY timestamp DESC+ UNION ALL+ SELECT `stripe.posthog_test.subscription_revenue_view`.source_label AS source_label,+ `stripe.posthog_test.subscription_revenue_view`.customer_id AS customer_id,+ `stripe.posthog_test.subscription_revenue_view`.id AS subscription_id,+ toTimeZone(`stripe.posthog_test.subscription_revenue_view`.ended_at,+ 'UTC') AS timestamp,+ accurateCastOrNull(0,+ 'Decimal64(10)') AS amount+ FROM (+ SELECT '' AS id,+ '' AS source_label,+ '' AS plan_id,+ '' AS product_id,+ '' AS customer_id,+ '' AS status,+ toDateTime64('1970-01-01 00:00:00.000000',+ 6,+ 'UTC') AS started_at,+ toDateTime64('1970-01-01 00:00:00.000000',+ 6,+ 'UTC') AS ended_at,+ '' AS metadata+ WHERE 0) AS `stripe.posthog_test.subscription_revenue_view` WHERE and(ifNull(greaterOrEquals(timestamp, toStartOfMonth(addDays(toDateTime64('2025-05-30 00:00:00.000000',+ 6,+ 'UTC'), -60))), 0), ifNull(lessOrEquals(timestamp, toDateTime64('2025-05-30 00:00:00.000000',+ 6,+ 'UTC')), 0))+ ORDER BY timestamp DESC) AS+ union+ GROUP BY source_label,+ customer_id,+ subscription_id+ ORDER BY customer_id ASC,+ subscription_id ASC) AS `stripe.posthog_test.mrr_revenue_view`+ GROUP BY customer_id) AS mrr_agg ON equals(revenue_analytics_customer.id,+ mrr_agg.customer_id))+ WHERE ifNull(notEquals(person_id,+ accurateCastOrNull('00000000-0000-0000-0000-000000000000',+ 'UUID')), isNotNull(person_id)+ or isNotNull(accurateCastOrNull('00000000-0000-0000-0000-000000000000',+ 'UUID')))+ GROUP BY person_id) AS persons__revenue_analytics ON equals(persons.persons___id,+ persons__revenue_analytics.person_id)ORDER BY persons.id ASCLIMIT 100 SETTINGS format_csv_allow_double_quotes=1,readonly=2,@@ -1218,10 +1193,10 @@use_hive_partitioning=0'''# ----# name: TestPersonsRevenueAnalytics.test_get_revenue_for_schema_source_for_id_join.1+# name: TestPersonsRevenueAnalytics.test_get_revenue_for_schema_source_for_id_join'''SELECT persons.id AS id,- persons__revenue_analytics.revenue AS `$virt_revenue`+ persons__revenue_analytics.revenue AS revenueFROM(SELECT argMax(person.id, person.version) AS persons___id,person.id AS id@@ -1338,7 +1313,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -1401,7 +1376,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -1471,10 +1446,9 @@use_hive_partitioning=0'''# ----# name: TestPersonsRevenueAnalytics.test_get_revenue_for_schema_source_for_metadata_join+# name: TestPersonsRevenueAnalytics.test_get_revenue_for_schema_source_for_id_join.1'''SELECT persons.id AS id,- persons__revenue_analytics.revenue AS revenue,persons__revenue_analytics.revenue AS `$virt_revenue`FROM(SELECT argMax(person.id, person.version) AS persons___id,@@ -1561,7 +1535,7 @@FROM person_distinct_id2WHERE equals(person_distinct_id2.team_id, 99999)GROUP BY person_distinct_id2.distinct_id- HAVING equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0) SETTINGS optimize_aggregation_in_order=1) AS persons__pdi ON equals(persons.persons___id, persons__pdi.person_id)) AS revenue_analytics_customer__persons ON equals(JSONExtractString(revenue_analytics_customer.metadata, 'id'), revenue_analytics_customer__persons.revenue_analytics_customer__persons___pdi___distinct_id)+ HAVING equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0) SETTINGS optimize_aggregation_in_order=1) AS persons__pdi ON equals(persons.persons___id, persons__pdi.person_id)) AS revenue_analytics_customer__persons ON equals(revenue_analytics_customer.id, revenue_analytics_customer__persons.revenue_analytics_customer__persons___pdi___distinct_id)LEFT JOIN(SELECT revenue_analytics_revenue_item.customer_id AS customer_id,sum(revenue_analytics_revenue_item.amount) AS revenue@@ -1592,7 +1566,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -1655,7 +1629,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -1725,6 +1699,488 @@use_hive_partitioning=0'''# ---+# name: TestPersonsRevenueAnalytics.test_get_revenue_for_schema_source_for_metadata_join+ '''+ SELECT persons.id AS id,+ persons__revenue_analytics.revenue AS revenue,+ persons__revenue_analytics.revenue AS `$virt_revenue`+ FROM (+ SELECT argMax(person.id,+ person.version) AS persons___id,+ person.id AS id+ FROM person+ WHERE equals(person.team_id,+ 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted,+ person.version), 0), less(argMax(toTimeZone(person.created_at,+ 'UTC'), person.version), plus(now64(6,+ 'UTC'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS persons+ LEFT JOIN (+ SELECT 99999 AS team_id,+ person_id AS person_id,+ sum(revenue) AS revenue,+ sum(mrr) AS mrr+ FROM (+ SELECT 99999 AS team_id,+ accurateCastOrNull(revenue_analytics_customer__persons.id,+ 'UUID') AS person_id,+ coalesce(revenue_agg.revenue,+ accurateCastOrNull(0,+ 'Decimal64(10)')) AS revenue,+ coalesce(mrr_agg.mrr,+ accurateCastOrNull(0,+ 'Decimal64(10)')) AS mrr+ FROM (+ SELECT inner.id AS id,+ inner.source_label AS source_label,+ inner.timestamp AS timestamp,+ inner.name AS name,+ inner.email AS email,+ inner.phone AS phone,+ inner.address AS address,+ if(notEquals(JSONExtractString(inner.metadata,+ 'posthog_person_distinct_id'), ''), toJSONString(mapUpdate(mapFromArrays(JSONExtractKeys(ifNull(inner.metadata,+ '{}')), arrayMap(k -> JSONExtractString(ifNull(inner.metadata,+ '{}'), k), JSONExtractKeys(ifNull(inner.metadata,+ '{}')))), map('posthog_person_distinct_id_source',+ 'customer'))), if(notEquals(inner.resolved_distinct_id,+ ''), toJSONString(mapUpdate(mapFromArrays(JSONExtractKeys(ifNull(inner.metadata,+ '{}')), arrayMap(k -> JSONExtractString(ifNull(inner.metadata,+ '{}'), k), JSONExtractKeys(ifNull(inner.metadata,+ '{}')))), map('posthog_person_distinct_id',+ inner.resolved_distinct_id,+ 'posthog_person_distinct_id_source',+ inner.resolved_source))), inner.metadata)) AS metadata,+ inner.country AS country,+ inner.cohort AS cohort,+ inner.initial_coupon AS initial_coupon,+ inner.initial_coupon_id AS initial_coupon_id+ FROM (+ SELECT outer.id AS id,+ 'stripe.posthog_test' AS source_label,+ parseDateTime64BestEffortOrNull(toString(outer.created), 6,+ 'UTC') AS timestamp,+ outer.name AS name,+ outer.email AS email,+ outer.phone AS phone,+ outer.address AS address,+ outer.metadata AS metadata,+ JSONExtractString(address,+ 'country') AS country,+ cohort_inner.cohort AS cohort,+ cohort_inner.initial_coupon AS initial_coupon,+ cohort_inner.initial_coupon_id AS initial_coupon_id,+ ifNull(resolved.resolved_distinct_id,+ '') AS resolved_distinct_id,+ ifNull(resolved.resolved_source,+ '') AS resolved_source+ FROM (+ SELECT *+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_customers/posthog_test_stripe_customer/*.csv',+ 'object_storage_root_user',+ 'object_storage_root_password',+ 'CSVWithNames',+ '`id` String, `name` String, `email` String, `phone` String, `address` String, `created` DateTime, `metadata` String')) AS outer+ LEFT JOIN (+ SELECT invoice.customer AS customer_id,+ formatDateTime(toStartOfMonth(min(parseDateTime64BestEffortOrNull(toString(invoice.created), 6,+ 'UTC'))), '%Y-%m') AS cohort,+ argMin(JSONExtractString(invoice.discount,+ 'coupon',+ 'name'), parseDateTime64BestEffortOrNull(toString(invoice.created), 6,+ 'UTC')) AS initial_coupon,+ argMin(JSONExtractString(invoice.discount,+ 'coupon',+ 'id'), parseDateTime64BestEffortOrNull(toString(invoice.created), 6,+ 'UTC')) AS initial_coupon_id+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv',+ 'object_storage_root_user',+ 'object_storage_root_password',+ 'CSVWithNames',+ '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS invoice+ GROUP BY invoice.customer) AS cohort_inner ON equals(cohort_inner.customer_id,+ outer.id)+ LEFT JOIN (+ SELECT child_meta.customer_id AS customer_id,+ argMax(child_meta.distinct_id,+ child_meta.created_at) AS resolved_distinct_id,+ argMax(child_meta.source_ref,+ child_meta.created_at) AS resolved_source+ FROM (+ SELECT posthog_test_stripe_invoice.customer AS customer_id,+ JSONExtractString(posthog_test_stripe_invoice.metadata,+ 'posthog_person_distinct_id') AS distinct_id,+ concat('invoice',+ '::',+ ifNull(toString(posthog_test_stripe_invoice.id), '')) AS source_ref,+ parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,+ 'UTC') AS created_at+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv',+ 'object_storage_root_user',+ 'object_storage_root_password',+ 'CSVWithNames',+ '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS posthog_test_stripe_invoice+ WHERE notEquals(JSONExtractString(posthog_test_stripe_invoice.metadata,+ 'posthog_person_distinct_id'), '')) AS child_meta+ GROUP BY child_meta.customer_id) AS resolved ON equals(resolved.customer_id,+ outer.id)) AS inner+ ORDER BY timestamp DESC+ LIMIT 1 BY id) AS revenue_analytics_customer+ LEFT JOIN (+ SELECT persons.id AS id,+ persons__pdi.distinct_id AS revenue_analytics_customer__persons___pdi___distinct_id+ FROM (+ SELECT argMax(person.id,+ person.version) AS persons___id,+ person.id AS id+ FROM person+ WHERE equals(person.team_id,+ 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted,+ person.version), 0), less(argMax(toTimeZone(person.created_at,+ 'UTC'), person.version), plus(now64(6,+ 'UTC'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS persons+ LEFT JOIN (+ SELECT argMax(person_distinct_id2.person_id,+ person_distinct_id2.version) AS person_id,+ person_distinct_id2.distinct_id AS distinct_id+ FROM person_distinct_id2+ WHERE equals(person_distinct_id2.team_id,+ 99999)+ GROUP BY person_distinct_id2.distinct_id+ HAVING equals(argMax(person_distinct_id2.is_deleted,+ person_distinct_id2.version), 0) SETTINGS optimize_aggregation_in_order=1) AS persons__pdi ON equals(persons.persons___id,+ persons__pdi.person_id)) AS revenue_analytics_customer__persons ON equals(JSONExtractString(revenue_analytics_customer.metadata,+ 'id'), revenue_analytics_customer__persons.revenue_analytics_customer__persons___pdi___distinct_id)+ LEFT JOIN (+ SELECT revenue_analytics_revenue_item.customer_id AS customer_id,+ sum(revenue_analytics_revenue_item.amount) AS revenue+ FROM (+ SELECT if(ifNull(greater(invoice.period_months,+ 1), 0), concat(ifNull(toString(invoice.invoice_item_id), ''), '_',+ ifNull(toString(invoice.month_index), '')), invoice.invoice_item_id) AS id,+ invoice.invoice_item_id AS invoice_item_id,+ 'stripe.posthog_test' AS source_label,+ addMonths(invoice.timestamp,+ invoice.month_index) AS timestamp,+ invoice.created_at AS created_at,+ ifNull(notEmpty(invoice.subscription_id), 0) AS is_recurring,+ invoice.product_id AS product_id,+ invoice.customer_id AS customer_id,+ NULL AS group_0_key,+ NULL AS group_1_key,+ NULL AS group_2_key,+ NULL AS group_3_key,+ NULL AS group_4_key,+ invoice.id AS invoice_id,+ invoice.subscription_id AS subscription_id,+ NULL AS session_id,+ NULL AS event_name,+ JSONExtractString(invoice.discount,+ 'coupon',+ 'name') AS coupon,+ JSONExtractString(invoice.discount,+ 'coupon',+ 'id') AS coupon_id,+ upper(invoice.currency) AS original_currency,+ accurateCastOrNull(invoice.amount_captured,+ 'Decimal64(10)') AS original_amount,+ in(original_currency,+ ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider,+ if(enable_currency_aware_divider,+ accurateCastOrNull(1,+ 'Decimal64(10)'), accurateCastOrNull(100,+ 'Decimal64(10)')) AS currency_aware_divider,+ divideDecimal(original_amount,+ currency_aware_divider) AS currency_aware_amount,+ 'GBP' AS currency,+ divideDecimal(if(equals(original_currency,+ currency), toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ original_currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(0,+ 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ original_currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(1,+ 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ original_currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10))))), accurateCastOrNull(invoice.period_months,+ 'Decimal64(10)')) AS amount+ FROM (+ SELECT posthog_test_stripe_invoice.id AS id,+ parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,+ 'UTC') AS created_at,+ posthog_test_stripe_invoice.customer AS customer_id,+ posthog_test_stripe_invoice.subscription AS subscription_id,+ posthog_test_stripe_invoice.discount AS discount,+ arrayJoin(JSONExtractArrayRaw(assumeNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(posthog_test_stripe_invoice.lines,+ 'data'), ''), 'null'), '^"|"$',+ '')))) AS data,+ JSONExtractString(data,+ 'id') AS invoice_item_id,+ JSONExtractUInt(data,+ 'amount') AS amount_before_discount,+ coalesce(arraySum(arrayMap(x -> JSONExtractInt(x,+ 'amount'), JSONExtractArrayRaw(data,+ 'discount_amounts'))), 0) AS discount_amount,+ greatest(minus(amount_before_discount,+ discount_amount), 0) AS amount_captured,+ JSONExtractString(data,+ 'currency') AS currency,+ JSONExtractString(data,+ 'price',+ 'product') AS product_id,+ fromUnixTimestamp(JSONExtractUInt(data,+ 'period',+ 'start')) AS period_start,+ fromUnixTimestamp(JSONExtractUInt(data,+ 'period',+ 'end')) AS period_end,+ greatest(toInt16(round(divide(dateDiff('day',+ ifNull(period_start,+ parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,+ 'UTC')), ifNull(period_end,+ parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,+ 'UTC'))), 30.44))), 1) AS period_months,+ arrayJoin(range(0,+ period_months)) AS month_index,+ ifNull(period_start,+ parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,+ 'UTC')) AS timestamp+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv',+ 'object_storage_root_user',+ 'object_storage_root_password',+ 'CSVWithNames',+ '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS posthog_test_stripe_invoice+ WHERE if(isNull(posthog_test_stripe_invoice.paid), equals(posthog_test_stripe_invoice.status,+ 'paid'), posthog_test_stripe_invoice.paid)) AS invoice) AS revenue_analytics_revenue_item+ GROUP BY customer_id) AS revenue_agg ON equals(revenue_analytics_customer.id,+ revenue_agg.customer_id)+ LEFT JOIN (+ SELECT `stripe.posthog_test.mrr_revenue_view`.customer_id AS customer_id,+ sum(`stripe.posthog_test.mrr_revenue_view`.mrr) AS mrr+ FROM (+ SELECT union.source_label AS source_label,+ union.customer_id AS customer_id,+ union.subscription_id AS subscription_id,+ argMax(union.amount,+ union.timestamp) AS mrr+ FROM (+ SELECT revenue_item.source_label AS source_label,+ revenue_item.customer_id AS customer_id,+ revenue_item.subscription_id AS subscription_id,+ toStartOfMonth(toTimeZone(revenue_item.timestamp,+ 'UTC')) AS timestamp,+ sum(revenue_item.amount) AS amount+ FROM (+ SELECT if(ifNull(greater(invoice.period_months,+ 1), 0), concat(ifNull(toString(invoice.invoice_item_id), ''), '_',+ ifNull(toString(invoice.month_index), '')), invoice.invoice_item_id) AS id,+ invoice.invoice_item_id AS invoice_item_id,+ 'stripe.posthog_test' AS source_label,+ addMonths(invoice.timestamp,+ invoice.month_index) AS timestamp,+ invoice.created_at AS created_at,+ ifNull(notEmpty(invoice.subscription_id), 0) AS is_recurring,+ invoice.product_id AS product_id,+ invoice.customer_id AS customer_id,+ NULL AS group_0_key,+ NULL AS group_1_key,+ NULL AS group_2_key,+ NULL AS group_3_key,+ NULL AS group_4_key,+ invoice.id AS invoice_id,+ invoice.subscription_id AS subscription_id,+ NULL AS session_id,+ NULL AS event_name,+ JSONExtractString(invoice.discount,+ 'coupon',+ 'name') AS coupon,+ JSONExtractString(invoice.discount,+ 'coupon',+ 'id') AS coupon_id,+ upper(invoice.currency) AS original_currency,+ accurateCastOrNull(invoice.amount_captured,+ 'Decimal64(10)') AS original_amount,+ in(original_currency,+ ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider,+ if(enable_currency_aware_divider,+ accurateCastOrNull(1,+ 'Decimal64(10)'), accurateCastOrNull(100,+ 'Decimal64(10)')) AS currency_aware_divider,+ divideDecimal(original_amount,+ currency_aware_divider) AS currency_aware_amount,+ 'GBP' AS currency,+ divideDecimal(if(equals(original_currency,+ currency), toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ original_currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(0,+ 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ original_currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(1,+ 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ original_currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10))))), accurateCastOrNull(invoice.period_months,+ 'Decimal64(10)')) AS amount+ FROM (+ SELECT posthog_test_stripe_invoice.id AS id,+ parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,+ 'UTC') AS created_at,+ posthog_test_stripe_invoice.customer AS customer_id,+ posthog_test_stripe_invoice.subscription AS subscription_id,+ posthog_test_stripe_invoice.discount AS discount,+ arrayJoin(JSONExtractArrayRaw(assumeNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(posthog_test_stripe_invoice.lines,+ 'data'), ''), 'null'), '^"|"$',+ '')))) AS data,+ JSONExtractString(data,+ 'id') AS invoice_item_id,+ JSONExtractUInt(data,+ 'amount') AS amount_before_discount,+ coalesce(arraySum(arrayMap(x -> JSONExtractInt(x,+ 'amount'), JSONExtractArrayRaw(data,+ 'discount_amounts'))), 0) AS discount_amount,+ greatest(minus(amount_before_discount,+ discount_amount), 0) AS amount_captured,+ JSONExtractString(data,+ 'currency') AS currency,+ JSONExtractString(data,+ 'price',+ 'product') AS product_id,+ fromUnixTimestamp(JSONExtractUInt(data,+ 'period',+ 'start')) AS period_start,+ fromUnixTimestamp(JSONExtractUInt(data,+ 'period',+ 'end')) AS period_end,+ greatest(toInt16(round(divide(dateDiff('day',+ ifNull(period_start,+ parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,+ 'UTC')), ifNull(period_end,+ parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,+ 'UTC'))), 30.44))), 1) AS period_months,+ arrayJoin(range(0,+ period_months)) AS month_index,+ ifNull(period_start,+ parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,+ 'UTC')) AS timestamp+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv',+ 'object_storage_root_user',+ 'object_storage_root_password',+ 'CSVWithNames',+ '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS posthog_test_stripe_invoice+ WHERE if(isNull(posthog_test_stripe_invoice.paid), equals(posthog_test_stripe_invoice.status,+ 'paid'), posthog_test_stripe_invoice.paid)) AS invoice) AS revenue_item WHERE and(revenue_item.is_recurring,+ isNotNull(revenue_item.subscription_id), ifNull(greaterOrEquals(timestamp, toStartOfMonth(addDays(toDateTime64('2025-05-30 00:00:00.000000',+ 6,+ 'UTC'), -60))), 0), ifNull(lessOrEquals(timestamp, toDateTime64('2025-05-30 00:00:00.000000',+ 6,+ 'UTC')), 0))+ GROUP BY revenue_item.source_label,+ revenue_item.customer_id,+ revenue_item.subscription_id, timestamp+ ORDER BY timestamp DESC+ UNION ALL+ SELECT `stripe.posthog_test.subscription_revenue_view`.source_label AS source_label,+ `stripe.posthog_test.subscription_revenue_view`.customer_id AS customer_id,+ `stripe.posthog_test.subscription_revenue_view`.id AS subscription_id,+ toTimeZone(`stripe.posthog_test.subscription_revenue_view`.ended_at,+ 'UTC') AS timestamp,+ accurateCastOrNull(0,+ 'Decimal64(10)') AS amount+ FROM (+ SELECT '' AS id,+ '' AS source_label,+ '' AS plan_id,+ '' AS product_id,+ '' AS customer_id,+ '' AS status,+ toDateTime64('1970-01-01 00:00:00.000000',+ 6,+ 'UTC') AS started_at,+ toDateTime64('1970-01-01 00:00:00.000000',+ 6,+ 'UTC') AS ended_at,+ '' AS metadata+ WHERE 0) AS `stripe.posthog_test.subscription_revenue_view` WHERE and(ifNull(greaterOrEquals(timestamp, toStartOfMonth(addDays(toDateTime64('2025-05-30 00:00:00.000000',+ 6,+ 'UTC'), -60))), 0), ifNull(lessOrEquals(timestamp, toDateTime64('2025-05-30 00:00:00.000000',+ 6,+ 'UTC')), 0))+ ORDER BY timestamp DESC) AS+ union+ GROUP BY source_label,+ customer_id,+ subscription_id+ ORDER BY customer_id ASC,+ subscription_id ASC) AS `stripe.posthog_test.mrr_revenue_view`+ GROUP BY customer_id) AS mrr_agg ON equals(revenue_analytics_customer.id,+ mrr_agg.customer_id))+ WHERE ifNull(notEquals(person_id,+ accurateCastOrNull('00000000-0000-0000-0000-000000000000',+ 'UUID')), isNotNull(person_id)+ or isNotNull(accurateCastOrNull('00000000-0000-0000-0000-000000000000',+ 'UUID')))+ GROUP BY person_id) AS persons__revenue_analytics ON equals(persons.persons___id,+ persons__revenue_analytics.person_id)+ ORDER BY persons.id ASC+ LIMIT 100 SETTINGS format_csv_allow_double_quotes=1,+ readonly=2,+ max_execution_time=60,+ allow_experimental_object_type=1,+ max_ast_elements=4000000,+ max_expanded_ast_elements=4000000,+ max_bytes_before_external_group_by=0,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---# name: TestPersonsRevenueAnalytics.test_person_id_joins_directly_against_persons_id_0_events'''SELECT persons.id AS id,@@ -1816,7 +2272,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -1869,7 +2325,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -2047,7 +2503,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -2110,7 +2566,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -2296,7 +2752,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -2349,7 +2805,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -2541,7 +2997,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -2604,7 +3060,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -2706,7 +3162,7 @@LEFT JOIN (SELECT revenue_analytics_revenue_item.customer_id AS customer_id, sum(revenue_analytics_revenue_item.amount) AS revenueFROM (- SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.`$group_0` AS group_0_key, events.`$group_1` AS group_1_key, events.`$group_2` AS group_2_key, events.`$group_3` AS group_3_key, events.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'GBP' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'GBP'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'GBP', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.`$group_0` AS group_0_key, events.`$group_1` AS group_1_key, events.`$group_2` AS group_2_key, events.`$group_3` AS group_3_key, events.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'GBP' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'GBP'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'GBP', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id@@ -2724,7 +3180,7 @@FROM (SELECT revenue_item.source_label AS source_label, revenue_item.customer_id AS customer_id, revenue_item.subscription_id AS subscription_id, toStartOfMonth(toTimeZone(revenue_item.timestamp, 'UTC')) AS timestamp, sum(revenue_item.amount) AS amountFROM (- SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.`$group_0` AS group_0_key, events.`$group_1` AS group_1_key, events.`$group_2` AS group_2_key, events.`$group_3` AS group_3_key, events.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'GBP' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'GBP'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'GBP', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.`$group_0` AS group_0_key, events.`$group_1` AS group_1_key, events.`$group_2` AS group_2_key, events.`$group_3` AS group_3_key, events.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'GBP' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'GBP'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'GBP', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id@@ -2786,7 +3242,7 @@LEFT JOIN (SELECT revenue_analytics_revenue_item.customer_id AS customer_id, sum(revenue_analytics_revenue_item.amount) AS revenueFROM (- SELECT if(ifNull(greater(invoice.period_months, 1), 0), concat(ifNull(toString(invoice.invoice_item_id), ''), '_', ifNull(toString(invoice.month_index), '')), invoice.invoice_item_id) AS id, invoice.invoice_item_id AS invoice_item_id, 'stripe.posthog_test' AS source_label, addMonths(invoice.timestamp, invoice.month_index) AS timestamp, invoice.created_at AS created_at, ifNull(notEmpty(invoice.subscription_id), 0) AS is_recurring, invoice.product_id AS product_id, invoice.customer_id AS customer_id, NULL AS group_0_key, NULL AS group_1_key, NULL AS group_2_key, NULL AS group_3_key, NULL AS group_4_key, invoice.id AS invoice_id, invoice.subscription_id AS subscription_id, NULL AS session_id, NULL AS event_name, JSONExtractString(invoice.discount, 'coupon', 'name') AS coupon, JSONExtractString(invoice.discount, 'coupon', 'id') AS coupon_id, upper(invoice.currency) AS original_currency, accurateCastOrNull(invoice.amount_captured, 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'GBP' AS currency, divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ SELECT if(ifNull(greater(invoice.period_months, 1), 0), concat(ifNull(toString(invoice.invoice_item_id), ''), '_', ifNull(toString(invoice.month_index), '')), invoice.invoice_item_id) AS id, invoice.invoice_item_id AS invoice_item_id, 'stripe.posthog_test' AS source_label, addMonths(invoice.timestamp, invoice.month_index) AS timestamp, invoice.created_at AS created_at, ifNull(notEmpty(invoice.subscription_id), 0) AS is_recurring, invoice.product_id AS product_id, invoice.customer_id AS customer_id, NULL AS group_0_key, NULL AS group_1_key, NULL AS group_2_key, NULL AS group_3_key, NULL AS group_4_key, invoice.id AS invoice_id, invoice.subscription_id AS subscription_id, NULL AS session_id, NULL AS event_name, JSONExtractString(invoice.discount, 'coupon', 'name') AS coupon, JSONExtractString(invoice.discount, 'coupon', 'id') AS coupon_id, upper(invoice.currency) AS original_currency, accurateCastOrNull(invoice.amount_captured, 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'GBP' AS currency, divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM (SELECT posthog_test_stripe_invoice.id AS id, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at, posthog_test_stripe_invoice.customer AS customer_id, posthog_test_stripe_invoice.subscription AS subscription_id, posthog_test_stripe_invoice.discount AS discount, arrayJoin(JSONExtractArrayRaw(assumeNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(posthog_test_stripe_invoice.lines, 'data'), ''), 'null'), '^"|"$', '')))) AS data, JSONExtractString(data, 'id') AS invoice_item_id, JSONExtractUInt(data, 'amount') AS amount_before_discount, coalesce(arraySum(arrayMap(x -> JSONExtractInt(x, 'amount'), JSONExtractArrayRaw(data, 'discount_amounts'))), 0) AS discount_amount, greatest(minus(amount_before_discount, discount_amount), 0) AS amount_captured, JSONExtractString(data, 'currency') AS currency, JSONExtractString(data, 'price', 'product') AS product_id, fromUnixTimestamp(JSONExtractUInt(data, 'period', 'start')) AS period_start, fromUnixTimestamp(JSONExtractUInt(data, 'period', 'end')) AS period_end, greatest(toInt16(round(divide(dateDiff('day', ifNull(period_start, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC')), ifNull(period_end, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC'))), 30.44))), 1) AS period_months, arrayJoin(range(0, period_months)) AS month_index, ifNull(period_start, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC')) AS timestampFROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS posthog_test_stripe_invoice@@ -2799,7 +3255,7 @@FROM (SELECT revenue_item.source_label AS source_label, revenue_item.customer_id AS customer_id, revenue_item.subscription_id AS subscription_id, toStartOfMonth(toTimeZone(revenue_item.timestamp, 'UTC')) AS timestamp, sum(revenue_item.amount) AS amountFROM (- SELECT if(ifNull(greater(invoice.period_months, 1), 0), concat(ifNull(toString(invoice.invoice_item_id), ''), '_', ifNull(toString(invoice.month_index), '')), invoice.invoice_item_id) AS id, invoice.invoice_item_id AS invoice_item_id, 'stripe.posthog_test' AS source_label, addMonths(invoice.timestamp, invoice.month_index) AS timestamp, invoice.created_at AS created_at, ifNull(notEmpty(invoice.subscription_id), 0) AS is_recurring, invoice.product_id AS product_id, invoice.customer_id AS customer_id, NULL AS group_0_key, NULL AS group_1_key, NULL AS group_2_key, NULL AS group_3_key, NULL AS group_4_key, invoice.id AS invoice_id, invoice.subscription_id AS subscription_id, NULL AS session_id, NULL AS event_name, JSONExtractString(invoice.discount, 'coupon', 'name') AS coupon, JSONExtractString(invoice.discount, 'coupon', 'id') AS coupon_id, upper(invoice.currency) AS original_currency, accurateCastOrNull(invoice.amount_captured, 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'GBP' AS currency, divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ SELECT if(ifNull(greater(invoice.period_months, 1), 0), concat(ifNull(toString(invoice.invoice_item_id), ''), '_', ifNull(toString(invoice.month_index), '')), invoice.invoice_item_id) AS id, invoice.invoice_item_id AS invoice_item_id, 'stripe.posthog_test' AS source_label, addMonths(invoice.timestamp, invoice.month_index) AS timestamp, invoice.created_at AS created_at, ifNull(notEmpty(invoice.subscription_id), 0) AS is_recurring, invoice.product_id AS product_id, invoice.customer_id AS customer_id, NULL AS group_0_key, NULL AS group_1_key, NULL AS group_2_key, NULL AS group_3_key, NULL AS group_4_key, invoice.id AS invoice_id, invoice.subscription_id AS subscription_id, NULL AS session_id, NULL AS event_name, JSONExtractString(invoice.discount, 'coupon', 'name') AS coupon, JSONExtractString(invoice.discount, 'coupon', 'id') AS coupon_id, upper(invoice.currency) AS original_currency, accurateCastOrNull(invoice.amount_captured, 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'GBP' AS currency, divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM (SELECT posthog_test_stripe_invoice.id AS id, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at, posthog_test_stripe_invoice.customer AS customer_id, posthog_test_stripe_invoice.subscription AS subscription_id, posthog_test_stripe_invoice.discount AS discount, arrayJoin(JSONExtractArrayRaw(assumeNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(posthog_test_stripe_invoice.lines, 'data'), ''), 'null'), '^"|"$', '')))) AS data, JSONExtractString(data, 'id') AS invoice_item_id, JSONExtractUInt(data, 'amount') AS amount_before_discount, coalesce(arraySum(arrayMap(x -> JSONExtractInt(x, 'amount'), JSONExtractArrayRaw(data, 'discount_amounts'))), 0) AS discount_amount, greatest(minus(amount_before_discount, discount_amount), 0) AS amount_captured, JSONExtractString(data, 'currency') AS currency, JSONExtractString(data, 'price', 'product') AS product_id, fromUnixTimestamp(JSONExtractUInt(data, 'period', 'start')) AS period_start, fromUnixTimestamp(JSONExtractUInt(data, 'period', 'end')) AS period_end, greatest(toInt16(round(divide(dateDiff('day', ifNull(period_start, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC')), ifNull(period_end, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC'))), 30.44))), 1) AS period_months, arrayJoin(range(0, period_months)) AS month_index, ifNull(period_start, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC')) AS timestampFROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS posthog_test_stripe_invoice@@ -2936,7 +3392,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -2999,7 +3455,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -3272,33 +3728,36 @@'GBP' AS currency,divideDecimal(if(equals(original_currency,currency), toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- original_currency,- toDate(ifNull(timestamp, toDateTime(0,- 'UTC'))), toDecimal64(0,- 10)) = 0,- toDecimal128(0,- 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- original_currency,- toDate(ifNull(timestamp, toDateTime(0,- 'UTC'))), toDecimal64(0,- 10)) = 0,- toDecimal128(1,- 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- original_currency,- toDate(ifNull(timestamp, toDateTime(0,- 'UTC'))), toDecimal64(0,- 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- currency,- toDate(ifNull(timestamp, toDateTime(0,- 'UTC'))), toDecimal64(0,- 10))))), accurateCastOrNull(invoice.period_months,- 'Decimal64(10)')) AS amount+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ original_currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(0,+ 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ original_currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(1,+ 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ original_currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10))))), accurateCastOrNull(invoice.period_months,+ 'Decimal64(10)')) AS amountFROM (SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,@@ -3406,33 +3865,36 @@'GBP' AS currency,divideDecimal(if(equals(original_currency,currency), toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- original_currency,- toDate(ifNull(timestamp, toDateTime(0,- 'UTC'))), toDecimal64(0,- 10)) = 0,- toDecimal128(0,- 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- original_currency,- toDate(ifNull(timestamp, toDateTime(0,- 'UTC'))), toDecimal64(0,- 10)) = 0,- toDecimal128(1,- 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- original_currency,- toDate(ifNull(timestamp, toDateTime(0,- 'UTC'))), toDecimal64(0,- 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- currency,- toDate(ifNull(timestamp, toDateTime(0,- 'UTC'))), toDecimal64(0,- 10))))), accurateCastOrNull(invoice.period_months,- 'Decimal64(10)')) AS amount+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ original_currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(0,+ 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ original_currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(1,+ 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ original_currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ currency,+ toDate(ifNull(timestamp, toDateTime(0,+ 'UTC'))), toDecimal64(0,+ 10))))), accurateCastOrNull(invoice.period_months,+ 'Decimal64(10)')) AS amountFROM (SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6,@@ -3627,7 +4089,7 @@LEFT JOIN (SELECT revenue_analytics_revenue_item.customer_id AS customer_id, sum(revenue_analytics_revenue_item.amount) AS revenueFROM (- SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(events__pdi.person_id) AS customer_id, events.`$group_0` AS group_0_key, events.`$group_1` AS group_1_key, events.`$group_2` AS group_2_key, events.`$group_3` AS group_3_key, events.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(events__pdi.person_id) AS customer_id, events.`$group_0` AS group_0_key, events.`$group_1` AS group_1_key, events.`$group_2` AS group_2_key, events.`$group_3` AS group_3_key, events.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsINNER JOIN (SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id@@ -3645,7 +4107,7 @@FROM (SELECT revenue_item.source_label AS source_label, revenue_item.customer_id AS customer_id, revenue_item.subscription_id AS subscription_id, toStartOfMonth(toTimeZone(revenue_item.timestamp, 'UTC')) AS timestamp, sum(revenue_item.amount) AS amountFROM (- SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(events__pdi.person_id) AS customer_id, events.`$group_0` AS group_0_key, events.`$group_1` AS group_1_key, events.`$group_2` AS group_2_key, events.`$group_3` AS group_3_key, events.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(events__pdi.person_id) AS customer_id, events.`$group_0` AS group_0_key, events.`$group_1` AS group_1_key, events.`$group_2` AS group_2_key, events.`$group_3` AS group_3_key, events.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsINNER JOIN (SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id@@ -3797,7 +4259,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsWHERE and(equals(events.team_id, 99999), and(equals(events.event, 'purchase'), 1, isNotNull(amount)))ORDER BY timestamp DESC) AS revenue_analytics_revenue_item@@ -3843,7 +4305,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsWHERE and(equals(events.team_id, 99999), and(equals(events.event, 'purchase'), 1, isNotNull(amount)))ORDER BY timestamp DESC) AS revenue_item@@ -3971,7 +4433,7 @@LEFT JOIN (SELECT revenue_analytics_revenue_item.customer_id AS customer_id, sum(revenue_analytics_revenue_item.amount) AS revenueFROM (- SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.`$group_0` AS group_0_key, events.`$group_1` AS group_1_key, events.`$group_2` AS group_2_key, events.`$group_3` AS group_3_key, events.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.`$group_0` AS group_0_key, events.`$group_1` AS group_1_key, events.`$group_2` AS group_2_key, events.`$group_3` AS group_3_key, events.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id@@ -3989,7 +4451,7 @@FROM (SELECT revenue_item.source_label AS source_label, revenue_item.customer_id AS customer_id, revenue_item.subscription_id AS subscription_id, toStartOfMonth(toTimeZone(revenue_item.timestamp, 'UTC')) AS timestamp, sum(revenue_item.amount) AS amountFROM (- SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.`$group_0` AS group_0_key, events.`$group_1` AS group_1_key, events.`$group_2` AS group_2_key, events.`$group_3` AS group_3_key, events.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.`$group_0` AS group_0_key, events.`$group_1` AS group_1_key, events.`$group_2` AS group_2_key, events.`$group_3` AS group_3_key, events.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id@@ -4104,7 +4566,7 @@LEFT JOIN (SELECT revenue_analytics_revenue_item.customer_id AS customer_id, sum(revenue_analytics_revenue_item.amount) AS revenueFROM (- SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.`$group_0` AS group_0_key, events.`$group_1` AS group_1_key, events.`$group_2` AS group_2_key, events.`$group_3` AS group_3_key, events.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.`$group_0` AS group_0_key, events.`$group_1` AS group_1_key, events.`$group_2` AS group_2_key, events.`$group_3` AS group_3_key, events.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id@@ -4122,7 +4584,7 @@FROM (SELECT revenue_item.source_label AS source_label, revenue_item.customer_id AS customer_id, revenue_item.subscription_id AS subscription_id, toStartOfMonth(toTimeZone(revenue_item.timestamp, 'UTC')) AS timestamp, sum(revenue_item.amount) AS amountFROM (- SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.`$group_0` AS group_0_key, events.`$group_1` AS group_1_key, events.`$group_2` AS group_2_key, events.`$group_3` AS group_3_key, events.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.`$group_0` AS group_0_key, events.`$group_1` AS group_1_key, events.`$group_2` AS group_2_key, events.`$group_3` AS group_3_key, events.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_iddiff --git a/posthog/hogql/database/schema/test/__snapshots__/test_persons_revenue_analytics.new_events_schema.ambr b/posthog/hogql/database/schema/test/__snapshots__/test_persons_revenue_analytics.new_events_schema.ambrindex 0b1141a6511d..c02f2d6f6fd1 100644--- a/posthog/hogql/database/schema/test/__snapshots__/test_persons_revenue_analytics.new_events_schema.ambr+++ b/posthog/hogql/database/schema/test/__snapshots__/test_persons_revenue_analytics.new_events_schema.ambr@@ -94,7 +94,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -147,7 +147,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -297,7 +297,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -350,7 +350,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'USD' AS currency,- if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -562,32 +562,35 @@if(isNull('USD'), accurateCastOrNull(currency_aware_amount,'Decimal64(10)'), if(equals('USD','USD'), toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(0,- 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(1,- 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))))) AS amount+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(0,+ 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(1,+ 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id,@@ -686,32 +689,35 @@if(isNull('USD'), accurateCastOrNull(currency_aware_amount,'Decimal64(10)'), if(equals('USD','USD'), toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(0,- 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(1,- 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))))) AS amount+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(0,+ 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(1,+ 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id,@@ -864,7 +870,7 @@LEFT JOIN (SELECT revenue_analytics_revenue_item.customer_id AS customer_id, sum(revenue_analytics_revenue_item.amount) AS revenueFROM (- SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.properties.`$group_0` AS group_0_key, events.properties.`$group_1` AS group_1_key, events.properties.`$group_2` AS group_2_key, events.properties.`$group_3` AS group_3_key, events.properties.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.properties.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), if(isNull(nullIf(toString(events.properties.revenue), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.revenue, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.revenue), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.revenue), '[]'), '{}'), toString(events.properties.revenue))))), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'GBP' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'GBP'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'GBP', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.properties.`$group_0` AS group_0_key, events.properties.`$group_1` AS group_1_key, events.properties.`$group_2` AS group_2_key, events.properties.`$group_3` AS group_3_key, events.properties.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.properties.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), if(isNull(nullIf(toString(events.properties.revenue), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.revenue, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.revenue), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.revenue), '[]'), '{}'), toString(events.properties.revenue))))), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'GBP' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'GBP'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'GBP', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id@@ -882,7 +888,7 @@FROM (SELECT revenue_item.source_label AS source_label, revenue_item.customer_id AS customer_id, revenue_item.subscription_id AS subscription_id, toStartOfMonth(toTimeZone(revenue_item.timestamp, 'UTC')) AS timestamp, sum(revenue_item.amount) AS amountFROM (- SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.properties.`$group_0` AS group_0_key, events.properties.`$group_1` AS group_1_key, events.properties.`$group_2` AS group_2_key, events.properties.`$group_3` AS group_3_key, events.properties.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.properties.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), if(isNull(nullIf(toString(events.properties.revenue), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.revenue, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.revenue), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.revenue), '[]'), '{}'), toString(events.properties.revenue))))), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'GBP' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'GBP'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'GBP', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.properties.`$group_0` AS group_0_key, events.properties.`$group_1` AS group_1_key, events.properties.`$group_2` AS group_2_key, events.properties.`$group_3` AS group_3_key, events.properties.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.properties.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), if(isNull(nullIf(toString(events.properties.revenue), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.revenue, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.revenue), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.revenue), '[]'), '{}'), toString(events.properties.revenue))))), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'GBP' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'GBP'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'GBP', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id@@ -944,7 +950,7 @@LEFT JOIN (SELECT revenue_analytics_revenue_item.customer_id AS customer_id, sum(revenue_analytics_revenue_item.amount) AS revenueFROM (- SELECT if(ifNull(greater(invoice.period_months, 1), 0), concat(ifNull(toString(invoice.invoice_item_id), ''), '_', ifNull(toString(invoice.month_index), '')), invoice.invoice_item_id) AS id, invoice.invoice_item_id AS invoice_item_id, 'stripe.posthog_test' AS source_label, addMonths(invoice.timestamp, invoice.month_index) AS timestamp, invoice.created_at AS created_at, ifNull(notEmpty(invoice.subscription_id), 0) AS is_recurring, invoice.product_id AS product_id, invoice.customer_id AS customer_id, NULL AS group_0_key, NULL AS group_1_key, NULL AS group_2_key, NULL AS group_3_key, NULL AS group_4_key, invoice.id AS invoice_id, invoice.subscription_id AS subscription_id, NULL AS session_id, NULL AS event_name, JSONExtractString(invoice.discount, 'coupon', 'name') AS coupon, JSONExtractString(invoice.discount, 'coupon', 'id') AS coupon_id, upper(invoice.currency) AS original_currency, accurateCastOrNull(invoice.amount_captured, 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'GBP' AS currency, divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ SELECT if(ifNull(greater(invoice.period_months, 1), 0), concat(ifNull(toString(invoice.invoice_item_id), ''), '_', ifNull(toString(invoice.month_index), '')), invoice.invoice_item_id) AS id, invoice.invoice_item_id AS invoice_item_id, 'stripe.posthog_test' AS source_label, addMonths(invoice.timestamp, invoice.month_index) AS timestamp, invoice.created_at AS created_at, ifNull(notEmpty(invoice.subscription_id), 0) AS is_recurring, invoice.product_id AS product_id, invoice.customer_id AS customer_id, NULL AS group_0_key, NULL AS group_1_key, NULL AS group_2_key, NULL AS group_3_key, NULL AS group_4_key, invoice.id AS invoice_id, invoice.subscription_id AS subscription_id, NULL AS session_id, NULL AS event_name, JSONExtractString(invoice.discount, 'coupon', 'name') AS coupon, JSONExtractString(invoice.discount, 'coupon', 'id') AS coupon_id, upper(invoice.currency) AS original_currency, accurateCastOrNull(invoice.amount_captured, 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'GBP' AS currency, divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM (SELECT posthog_test_stripe_invoice.id AS id, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at, posthog_test_stripe_invoice.customer AS customer_id, posthog_test_stripe_invoice.subscription AS subscription_id, posthog_test_stripe_invoice.discount AS discount, arrayJoin(JSONExtractArrayRaw(assumeNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(posthog_test_stripe_invoice.lines, 'data'), ''), 'null'), '^"|"$', '')))) AS data, JSONExtractString(data, 'id') AS invoice_item_id, JSONExtractUInt(data, 'amount') AS amount_before_discount, coalesce(arraySum(arrayMap(x -> JSONExtractInt(x, 'amount'), JSONExtractArrayRaw(data, 'discount_amounts'))), 0) AS discount_amount, greatest(minus(amount_before_discount, discount_amount), 0) AS amount_captured, JSONExtractString(data, 'currency') AS currency, JSONExtractString(data, 'price', 'product') AS product_id, fromUnixTimestamp(JSONExtractUInt(data, 'period', 'start')) AS period_start, fromUnixTimestamp(JSONExtractUInt(data, 'period', 'end')) AS period_end, greatest(toInt16(round(divide(dateDiff('day', ifNull(period_start, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC')), ifNull(period_end, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC'))), 30.44))), 1) AS period_months, arrayJoin(range(0, period_months)) AS month_index, ifNull(period_start, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC')) AS timestampFROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS posthog_test_stripe_invoice@@ -957,7 +963,7 @@FROM (SELECT revenue_item.source_label AS source_label, revenue_item.customer_id AS customer_id, revenue_item.subscription_id AS subscription_id, toStartOfMonth(toTimeZone(revenue_item.timestamp, 'UTC')) AS timestamp, sum(revenue_item.amount) AS amountFROM (- SELECT if(ifNull(greater(invoice.period_months, 1), 0), concat(ifNull(toString(invoice.invoice_item_id), ''), '_', ifNull(toString(invoice.month_index), '')), invoice.invoice_item_id) AS id, invoice.invoice_item_id AS invoice_item_id, 'stripe.posthog_test' AS source_label, addMonths(invoice.timestamp, invoice.month_index) AS timestamp, invoice.created_at AS created_at, ifNull(notEmpty(invoice.subscription_id), 0) AS is_recurring, invoice.product_id AS product_id, invoice.customer_id AS customer_id, NULL AS group_0_key, NULL AS group_1_key, NULL AS group_2_key, NULL AS group_3_key, NULL AS group_4_key, invoice.id AS invoice_id, invoice.subscription_id AS subscription_id, NULL AS session_id, NULL AS event_name, JSONExtractString(invoice.discount, 'coupon', 'name') AS coupon, JSONExtractString(invoice.discount, 'coupon', 'id') AS coupon_id, upper(invoice.currency) AS original_currency, accurateCastOrNull(invoice.amount_captured, 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'GBP' AS currency, divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ SELECT if(ifNull(greater(invoice.period_months, 1), 0), concat(ifNull(toString(invoice.invoice_item_id), ''), '_', ifNull(toString(invoice.month_index), '')), invoice.invoice_item_id) AS id, invoice.invoice_item_id AS invoice_item_id, 'stripe.posthog_test' AS source_label, addMonths(invoice.timestamp, invoice.month_index) AS timestamp, invoice.created_at AS created_at, ifNull(notEmpty(invoice.subscription_id), 0) AS is_recurring, invoice.product_id AS product_id, invoice.customer_id AS customer_id, NULL AS group_0_key, NULL AS group_1_key, NULL AS group_2_key, NULL AS group_3_key, NULL AS group_4_key, invoice.id AS invoice_id, invoice.subscription_id AS subscription_id, NULL AS session_id, NULL AS event_name, JSONExtractString(invoice.discount, 'coupon', 'name') AS coupon, JSONExtractString(invoice.discount, 'coupon', 'id') AS coupon_id, upper(invoice.currency) AS original_currency, accurateCastOrNull(invoice.amount_captured, 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'GBP' AS currency, divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM (SELECT posthog_test_stripe_invoice.id AS id, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at, posthog_test_stripe_invoice.customer AS customer_id, posthog_test_stripe_invoice.subscription AS subscription_id, posthog_test_stripe_invoice.discount AS discount, arrayJoin(JSONExtractArrayRaw(assumeNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(posthog_test_stripe_invoice.lines, 'data'), ''), 'null'), '^"|"$', '')))) AS data, JSONExtractString(data, 'id') AS invoice_item_id, JSONExtractUInt(data, 'amount') AS amount_before_discount, coalesce(arraySum(arrayMap(x -> JSONExtractInt(x, 'amount'), JSONExtractArrayRaw(data, 'discount_amounts'))), 0) AS discount_amount, greatest(minus(amount_before_discount, discount_amount), 0) AS amount_captured, JSONExtractString(data, 'currency') AS currency, JSONExtractString(data, 'price', 'product') AS product_id, fromUnixTimestamp(JSONExtractUInt(data, 'period', 'start')) AS period_start, fromUnixTimestamp(JSONExtractUInt(data, 'period', 'end')) AS period_end, greatest(toInt16(round(divide(dateDiff('day', ifNull(period_start, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC')), ifNull(period_end, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC'))), 30.44))), 1) AS period_months, arrayJoin(range(0, period_months)) AS month_index, ifNull(period_start, parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC')) AS timestampFROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.insights_query_runner.stripe_invoices/posthog_test_stripe_invoice/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `tax` Int64, `paid` UInt8, `lines` String, `total` Int64, `charge` String, `issuer` String, `number` String, `object` String, `status` String, `created` DateTime, `currency` String, `customer` String, `discount` String, `due_date` DateTime, `livemode` UInt8, `metadata` String, `subtotal` Int64, `attempted` UInt8, `discounts` String, `rendering` String, `amount_due` Int64, `amount_paid` Int64, `description` String, `invoice_pdf` String, `account_name` String, `auto_advance` UInt8, `effective_at` DateTime, `subscription` String, `attempt_count` UInt8, `automatic_tax` String, `customer_name` String, `period_end_at` DateTime, `billing_reason` String, `customer_email` String, `ending_balance` Int64, `payment_intent` String, `account_country` String, `amount_shipping` Int64, `period_start_at` DateTime, `amount_remaining` Int64, `customer_address` String, `customer_tax_ids` String, `paid_out_of_band` UInt8, `payment_settings` String, `starting_balance` Int64, `collection_method` String, `default_tax_rates` String, `total_tax_amounts` String, `hosted_invoice_url` String, `status_transitions` String, `customer_tax_exempt` String, `total_excluding_tax` Int64, `subscription_details` String, `webhooks_delivered_at` DateTime, `subtotal_excluding_tax` Int64, `total_discount_amounts` String, `pre_payment_credit_notes_amount` Int64, `post_payment_credit_notes_amount` Int64') AS posthog_test_stripe_invoice@@ -1037,7 +1043,7 @@LEFT JOIN (SELECT revenue_analytics_revenue_item.customer_id AS customer_id, sum(revenue_analytics_revenue_item.amount) AS revenueFROM (- SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(events__pdi.person_id) AS customer_id, events.properties.`$group_0` AS group_0_key, events.properties.`$group_1` AS group_1_key, events.properties.`$group_2` AS group_2_key, events.properties.`$group_3` AS group_3_key, events.properties.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.properties.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), if(isNull(nullIf(toString(events.properties.revenue), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.revenue, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.revenue), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.revenue), '[]'), '{}'), toString(events.properties.revenue))))), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(events__pdi.person_id) AS customer_id, events.properties.`$group_0` AS group_0_key, events.properties.`$group_1` AS group_1_key, events.properties.`$group_2` AS group_2_key, events.properties.`$group_3` AS group_3_key, events.properties.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.properties.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), if(isNull(nullIf(toString(events.properties.revenue), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.revenue, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.revenue), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.revenue), '[]'), '{}'), toString(events.properties.revenue))))), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM events_json AS eventsINNER JOIN (SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id@@ -1055,7 +1061,7 @@FROM (SELECT revenue_item.source_label AS source_label, revenue_item.customer_id AS customer_id, revenue_item.subscription_id AS subscription_id, toStartOfMonth(toTimeZone(revenue_item.timestamp, 'UTC')) AS timestamp, sum(revenue_item.amount) AS amountFROM (- SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(events__pdi.person_id) AS customer_id, events.properties.`$group_0` AS group_0_key, events.properties.`$group_1` AS group_1_key, events.properties.`$group_2` AS group_2_key, events.properties.`$group_3` AS group_3_key, events.properties.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.properties.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), if(isNull(nullIf(toString(events.properties.revenue), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.revenue, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.revenue), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.revenue), '[]'), '{}'), toString(events.properties.revenue))))), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(events__pdi.person_id) AS customer_id, events.properties.`$group_0` AS group_0_key, events.properties.`$group_1` AS group_1_key, events.properties.`$group_2` AS group_2_key, events.properties.`$group_3` AS group_3_key, events.properties.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.properties.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), if(isNull(nullIf(toString(events.properties.revenue), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.revenue, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.revenue), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.revenue), '[]'), '{}'), toString(events.properties.revenue))))), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM events_json AS eventsINNER JOIN (SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id@@ -1265,32 +1271,35 @@if(isNull('USD'), accurateCastOrNull(currency_aware_amount,'Decimal64(10)'), if(equals('USD','USD'), toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(0,- 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(1,- 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))))) AS amount+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(0,+ 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(1,+ 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)))))) AS amountFROM events_json AS eventsWHERE and(equals(events.team_id,99999), and(equals(events.event,@@ -1359,32 +1368,35 @@if(isNull('USD'), accurateCastOrNull(currency_aware_amount,'Decimal64(10)'), if(equals('USD','USD'), toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(0,- 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,- 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)) = 0,- toDecimal128(1,- 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,- 'rate',- 'USD',- toDate(toTimeZone(events.timestamp,- 'UTC')), toDecimal64(0,- 10)))))) AS amount+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(0,+ 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount,+ 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)) = 0,+ toDecimal128(1,+ 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)), toDecimal64(0,+ 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`,+ 'rate',+ 'USD',+ toDate(toTimeZone(events.timestamp,+ 'UTC')), toDecimal64(0,+ 10)))))) AS amountFROM events_json AS eventsWHERE and(equals(events.team_id,99999), and(equals(events.event,@@ -1549,7 +1561,7 @@LEFT JOIN (SELECT revenue_analytics_revenue_item.customer_id AS customer_id, sum(revenue_analytics_revenue_item.amount) AS revenueFROM (- SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.properties.`$group_0` AS group_0_key, events.properties.`$group_1` AS group_1_key, events.properties.`$group_2` AS group_2_key, events.properties.`$group_3` AS group_3_key, events.properties.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.properties.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), if(isNull(nullIf(toString(events.properties.revenue), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.revenue, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.revenue), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.revenue), '[]'), '{}'), toString(events.properties.revenue))))), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.properties.`$group_0` AS group_0_key, events.properties.`$group_1` AS group_1_key, events.properties.`$group_2` AS group_2_key, events.properties.`$group_3` AS group_3_key, events.properties.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.properties.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), if(isNull(nullIf(toString(events.properties.revenue), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.revenue, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.revenue), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.revenue), '[]'), '{}'), toString(events.properties.revenue))))), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id@@ -1567,7 +1579,7 @@FROM (SELECT revenue_item.source_label AS source_label, revenue_item.customer_id AS customer_id, revenue_item.subscription_id AS subscription_id, toStartOfMonth(toTimeZone(revenue_item.timestamp, 'UTC')) AS timestamp, sum(revenue_item.amount) AS amountFROM (- SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.properties.`$group_0` AS group_0_key, events.properties.`$group_1` AS group_1_key, events.properties.`$group_2` AS group_2_key, events.properties.`$group_3` AS group_3_key, events.properties.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.properties.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), if(isNull(nullIf(toString(events.properties.revenue), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.revenue, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.revenue), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.revenue), '[]'), '{}'), toString(events.properties.revenue))))), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.properties.`$group_0` AS group_0_key, events.properties.`$group_1` AS group_1_key, events.properties.`$group_2` AS group_2_key, events.properties.`$group_3` AS group_3_key, events.properties.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.properties.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), if(isNull(nullIf(toString(events.properties.revenue), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.revenue, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.revenue), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.revenue), '[]'), '{}'), toString(events.properties.revenue))))), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id@@ -1682,7 +1694,7 @@LEFT JOIN (SELECT revenue_analytics_revenue_item.customer_id AS customer_id, sum(revenue_analytics_revenue_item.amount) AS revenueFROM (- SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.properties.`$group_0` AS group_0_key, events.properties.`$group_1` AS group_1_key, events.properties.`$group_2` AS group_2_key, events.properties.`$group_3` AS group_3_key, events.properties.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.properties.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), if(isNull(nullIf(toString(events.properties.revenue), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.revenue, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.revenue), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.revenue), '[]'), '{}'), toString(events.properties.revenue))))), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.properties.`$group_0` AS group_0_key, events.properties.`$group_1` AS group_1_key, events.properties.`$group_2` AS group_2_key, events.properties.`$group_3` AS group_3_key, events.properties.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.properties.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), if(isNull(nullIf(toString(events.properties.revenue), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.revenue, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.revenue), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.revenue), '[]'), '{}'), toString(events.properties.revenue))))), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id@@ -1700,7 +1712,7 @@FROM (SELECT revenue_item.source_label AS source_label, revenue_item.customer_id AS customer_id, revenue_item.subscription_id AS subscription_id, toStartOfMonth(toTimeZone(revenue_item.timestamp, 'UTC')) AS timestamp, sum(revenue_item.amount) AS amountFROM (- SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.properties.`$group_0` AS group_0_key, events.properties.`$group_1` AS group_1_key, events.properties.`$group_2` AS group_2_key, events.properties.`$group_3` AS group_3_key, events.properties.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.properties.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), if(isNull(nullIf(toString(events.properties.revenue), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.revenue, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.revenue), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.revenue), '[]'), '{}'), toString(events.properties.revenue))))), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ SELECT toString(events.uuid) AS id, toString(events.uuid) AS invoice_item_id, 'revenue_analytics.events.purchase' AS source_label, toTimeZone(events.timestamp, 'UTC') AS timestamp, timestamp AS created_at, 0 AS is_recurring, NULL AS product_id, toString(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS customer_id, events.properties.`$group_0` AS group_0_key, events.properties.`$group_1` AS group_1_key, events.properties.`$group_2` AS group_2_key, events.properties.`$group_3` AS group_3_key, events.properties.`$group_4` AS group_4_key, NULL AS invoice_id, NULL AS subscription_id, toString(events.properties.`$session_id`) AS session_id, events.event AS event_name, NULL AS coupon, coupon AS coupon_id, 'USD' AS original_currency, accurateCastOrNull(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^revenue)), if(isNull(nullIf(toString(events.properties.revenue), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.revenue, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.revenue), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.revenue, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.revenue), '[]'), '{}'), toString(events.properties.revenue))))), 'Decimal64(10)') AS original_amount, in(original_currency, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']) AS enable_currency_aware_divider, if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider, divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount, 'USD' AS currency, if(isNull('USD'), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals('USD', 'USD'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_iddiff --git a/posthog/hogql/printer/clickhouse.py b/posthog/hogql/printer/clickhouse.pyindex 711b15f976ab..1c760536b8ed 100644--- a/posthog/hogql/printer/clickhouse.py+++ b/posthog/hogql/printer/clickhouse.py@@ -364,7 +364,9 @@ class ClickHousePrinter(BasePrinter):db = django_settings.CLICKHOUSE_DATABASEscale = EXCHANGE_RATE_DECIMAL_PRECISION# Build rate lookup expressions- from_rate = f"dictGetOrDefault(`{db}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', {from_currency}, {date}, toDecimal64(0, {scale}))"+ # A NULL currency makes the lookup return NULL, not the default. NULL = 0 is not true, so the guard+ # below would keep a NULL divisor, and divideDecimal fails on the zero under a NULL row.+ from_rate = f"ifNull(dictGetOrDefault(`{db}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', {from_currency}, {date}, toDecimal64(0, {scale})), toDecimal64(0, {scale}))"to_rate = f"dictGetOrDefault(`{db}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', {to_currency}, {date}, toDecimal64(0, {scale}))"# Use if() around divisor to avoid division by zero — with enable_analyzer=0, the old analyzer evaluates all branches regardless of condition.safe_from_rate = f"if({from_rate} = 0, toDecimal128(1, {scale}), {from_rate})"diff --git a/posthog/hogql/printer/test/test_printer.py b/posthog/hogql/printer/test/test_printer.pyindex cfe4ac7fbe4f..4585187beda3 100644--- a/posthog/hogql/printer/test/test_printer.py+++ b/posthog/hogql/printer/test/test_printer.py@@ -4244,7 +4244,7 @@ class TestPrinter(BaseTest):)self.assertEqual((- f"SELECT if(equals(%(hogql_val_0)s, %(hogql_val_1)s), toDecimal128(100, 10), if(dictGetOrDefault(`{CLICKHOUSE_DATABASE}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', %(hogql_val_0)s, toDateOrNull(%(hogql_val_2)s), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(100, 10), if(dictGetOrDefault(`{CLICKHOUSE_DATABASE}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', %(hogql_val_0)s, toDateOrNull(%(hogql_val_2)s), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`{CLICKHOUSE_DATABASE}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', %(hogql_val_0)s, toDateOrNull(%(hogql_val_2)s), toDecimal64(0, 10)))), dictGetOrDefault(`{CLICKHOUSE_DATABASE}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', %(hogql_val_1)s, toDateOrNull(%(hogql_val_2)s), toDecimal64(0, 10))))) AS currency "+ f"SELECT if(equals(%(hogql_val_0)s, %(hogql_val_1)s), toDecimal128(100, 10), if(ifNull(dictGetOrDefault(`{CLICKHOUSE_DATABASE}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', %(hogql_val_0)s, toDateOrNull(%(hogql_val_2)s), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(100, 10), if(ifNull(dictGetOrDefault(`{CLICKHOUSE_DATABASE}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', %(hogql_val_0)s, toDateOrNull(%(hogql_val_2)s), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`{CLICKHOUSE_DATABASE}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', %(hogql_val_0)s, toDateOrNull(%(hogql_val_2)s), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`{CLICKHOUSE_DATABASE}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', %(hogql_val_1)s, toDateOrNull(%(hogql_val_2)s), toDecimal64(0, 10))))) AS currency ""LIMIT 50000 SETTINGS readonly=2, max_execution_time=10, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0"),printed,@@ -4257,7 +4257,7 @@ class TestPrinter(BaseTest):)self.assertEqual((- f"SELECT if(equals(%(hogql_val_0)s, %(hogql_val_1)s), toDecimal128(100, 10), if(dictGetOrDefault(`{CLICKHOUSE_DATABASE}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', %(hogql_val_0)s, today(), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(100, 10), if(dictGetOrDefault(`{CLICKHOUSE_DATABASE}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', %(hogql_val_0)s, today(), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`{CLICKHOUSE_DATABASE}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', %(hogql_val_0)s, today(), toDecimal64(0, 10)))), dictGetOrDefault(`{CLICKHOUSE_DATABASE}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', %(hogql_val_1)s, today(), toDecimal64(0, 10))))) AS currency "+ f"SELECT if(equals(%(hogql_val_0)s, %(hogql_val_1)s), toDecimal128(100, 10), if(ifNull(dictGetOrDefault(`{CLICKHOUSE_DATABASE}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', %(hogql_val_0)s, today(), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(100, 10), if(ifNull(dictGetOrDefault(`{CLICKHOUSE_DATABASE}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', %(hogql_val_0)s, today(), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`{CLICKHOUSE_DATABASE}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', %(hogql_val_0)s, today(), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`{CLICKHOUSE_DATABASE}`.`{EXCHANGE_RATE_DICTIONARY_NAME}`, 'rate', %(hogql_val_1)s, today(), toDecimal64(0, 10))))) AS currency ""LIMIT 50000 SETTINGS readonly=2, max_execution_time=10, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0"),printed,diff --git a/posthog/hogql/property.py b/posthog/hogql/property.pyindex ef2ae8acf88e..10a2191e40e3 100644--- a/posthog/hogql/property.py+++ b/posthog/hogql/property.py@@ -1549,7 +1549,9 @@ def property_to_expr(is_json_field=False,)- if property.key == "text":+ # `$el_text` is the autocapture event property for the same text. The action editor saves it as+ # `text`, but actions saved through other paths can still carry the event-property key.+ if property.key == "text" or property.key == "$el_text":return parse_expr("arrayExists(text -> {compare}, elements_chain_texts)",{diff --git a/posthog/hogql/test/test_property.py b/posthog/hogql/test/test_property.pyindex cce539a7e97c..f99a3ba0fa06 100644--- a/posthog/hogql/test/test_property.py+++ b/posthog/hogql/test/test_property.py@@ -752,19 +752,20 @@ class TestProperty(BaseTest):),self._parse_expr("toString(elements_chain_href) ilike '%href-text.%'"),)- self.assertEqual(- self._property_to_expr(- {- "type": "element",- "key": "text",- "value": "text-text.",- "operator": "regex",- }- ),- self._parse_expr(- "arrayExists(text -> ifNull(match(toString(text), 'text-text.'), 0), elements_chain_texts)"- ),- )+ for text_key in ("text", "$el_text"):+ self.assertEqual(+ self._property_to_expr(+ {+ "type": "element",+ "key": text_key,+ "value": "text-text.",+ "operator": "regex",+ }+ ),+ self._parse_expr(+ "arrayExists(text -> ifNull(match(toString(text), 'text-text.'), 0), elements_chain_texts)"+ ),+ )def test_property_groups(self):self.assertEqual(diff --git a/posthog/hogql/test/test_query.py b/posthog/hogql/test/test_query.pyindex 60c49221db5c..8ec51b06882b 100644--- a/posthog/hogql/test/test_query.py+++ b/posthog/hogql/test/test_query.py@@ -2299,6 +2299,14 @@ class TestQuery(ClickhouseTestMixin, APIBaseTest):response = execute_hogql_query(query, team=self.team)self.assertEqual(response.results, [(Decimal("0"),)])+ def test_currency_conversion_with_null_currency_from(self):+ # A source row with no currency must convert to 0 like an unknown one, not fail the whole query.+ query = (+ "SELECT convertCurrency(c, 'EUR', 100, _toDate('2024-01-01')) FROM (SELECT arrayJoin([NULL, 'USD']) AS c)"+ )+ response = execute_hogql_query(query, team=self.team)+ self.assertEqual(response.results, [(Decimal("0"),), (Decimal("90.49"),)])+def test_currency_conversion_with_bogus_currency_to(self):query = "SELECT convertCurrency('USD', 'BOGUS', 100, _toDate('2024-01-01'))"response = execute_hogql_query(query, team=self.team)diff --git a/products/marketing_analytics/backend/hogql_queries/conversion_goal_processor.py b/products/marketing_analytics/backend/hogql_queries/conversion_goal_processor.pyindex 931e92c07298..5d31b17c1b67 100644--- a/products/marketing_analytics/backend/hogql_queries/conversion_goal_processor.py+++ b/products/marketing_analytics/backend/hogql_queries/conversion_goal_processor.py@@ -442,7 +442,7 @@ class ConversionGoalProcessor:name="nullIf", args=[ast.Call(name="upper", args=[currency_from]), ast.Constant(value="")])# A row can be missing the currency property or carry an empty string; treat those as already- # in the base currency rather than letting convertCurrency null the whole amount out.+ # in the base currency rather than letting convertCurrency convert the whole amount to 0.return ast.Call(name="if",args=[diff --git a/products/product_analytics/backend/hogql_queries/trends/test/__snapshots__/test_math_property_revenue_currency_timestamp.ambr b/products/product_analytics/backend/hogql_queries/trends/test/__snapshots__/test_math_property_revenue_currency_timestamp.ambrindex d6cd50341dd8..8170ed4e55ee 100644--- a/products/product_analytics/backend/hogql_queries/trends/test/__snapshots__/test_math_property_revenue_currency_timestamp.ambr+++ b/products/product_analytics/backend/hogql_queries/trends/test/__snapshots__/test_math_property_revenue_currency_timestamp.ambr@@ -8,7 +8,7 @@(SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT ifNull(sum(if(equals(e.currency_code, 'USD'), toDecimal128(e.revenue_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', e.currency_code, toDate(coalesce(toString(e.timestamp_str), '1970-01-01')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(e.revenue_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', e.currency_code, toDate(coalesce(toString(e.timestamp_str), '1970-01-01')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', e.currency_code, toDate(coalesce(toString(e.timestamp_str), '1970-01-01')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(coalesce(toString(e.timestamp_str), '1970-01-01')), toDecimal64(0, 10)))))), 0) AS total,+ (SELECT ifNull(sum(if(equals(e.currency_code, 'USD'), toDecimal128(e.revenue_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', e.currency_code, toDate(coalesce(toString(e.timestamp_str), '1970-01-01')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(e.revenue_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', e.currency_code, toDate(coalesce(toString(e.timestamp_str), '1970-01-01')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', e.currency_code, toDate(coalesce(toString(e.timestamp_str), '1970-01-01')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(coalesce(toString(e.timestamp_str), '1970-01-01')), toDecimal64(0, 10)))))), 0) AS total,toStartOfDay(parseDateTime64BestEffortOrNull(e.timestamp_str, 6, 'UTC')) AS day_startFROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.trends.datawarehouse.timestamp_handling/posthog_test_string_timestamp_table/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `currency_code` String, `timestamp_str` Nullable(String), `revenue_amount` Float64') AS eWHERE and(ifNull(greaterOrEquals(parseDateTime64BestEffortOrNull(e.timestamp_str, 6, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2023-01-01 00:00:00', 'UTC')), toIntervalDay(1))), 0), ifNull(lessOrEquals(parseDateTime64BestEffortOrNull(e.timestamp_str, 6, 'UTC'), assumeNotNull(toDateTime('2023-01-05 23:59:59', 'UTC'))), 0))@@ -40,7 +40,7 @@(SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT ifNull(sum(if(equals(e.currency_code, 'USD'), toDecimal128(e.revenue_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', e.currency_code, toDate(coalesce(toString(e.timestamp_date32), '1970-01-01')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(e.revenue_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', e.currency_code, toDate(coalesce(toString(e.timestamp_date32), '1970-01-01')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', e.currency_code, toDate(coalesce(toString(e.timestamp_date32), '1970-01-01')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(coalesce(toString(e.timestamp_date32), '1970-01-01')), toDecimal64(0, 10)))))), 0) AS total,+ (SELECT ifNull(sum(if(equals(e.currency_code, 'USD'), toDecimal128(e.revenue_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', e.currency_code, toDate(coalesce(toString(e.timestamp_date32), '1970-01-01')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(e.revenue_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', e.currency_code, toDate(coalesce(toString(e.timestamp_date32), '1970-01-01')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', e.currency_code, toDate(coalesce(toString(e.timestamp_date32), '1970-01-01')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'USD', toDate(coalesce(toString(e.timestamp_date32), '1970-01-01')), toDecimal64(0, 10)))))), 0) AS total,toStartOfDay(toDateTime(e.timestamp_date32, 'UTC')) AS day_startFROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.trends.datawarehouse.timestamp_handling/posthog_test_date32_timestamp_table/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `currency_code` String, `revenue_amount` Float64, `timestamp_date32` Date32') AS eWHERE and(greaterOrEquals(toDateTime(e.timestamp_date32, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2023-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toDateTime(e.timestamp_date32, 'UTC'), assumeNotNull(toDateTime('2023-01-05 23:59:59', 'UTC'))))diff --git a/products/revenue_analytics/backend/views/test/__snapshots__/test_mrr_views.ambr b/products/revenue_analytics/backend/views/test/__snapshots__/test_mrr_views.ambrindex 6d3d830e3113..9d5ab473a524 100644--- a/products/revenue_analytics/backend/views/test/__snapshots__/test_mrr_views.ambr+++ b/products/revenue_analytics/backend/views/test/__snapshots__/test_mrr_views.ambr@@ -39,7 +39,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- if(isNull(upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', ''))), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals(upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', '')), 'GBP'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', '')), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', '')), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', '')), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'GBP', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull(upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', ''))), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals(upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', '')), 'GBP'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', '')), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', '')), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', '')), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'GBP', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -242,7 +242,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amount+ divideDecimal(if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))), accurateCastOrNull(invoice.period_months, 'Decimal64(10)')) AS amountFROM(SELECT posthog_test_stripe_invoice.id AS id,parseDateTime64BestEffortOrNull(toString(posthog_test_stripe_invoice.created), 6, 'UTC') AS created_at,@@ -289,7 +289,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))) AS amount+ if(equals(original_currency, currency), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', original_currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', currency, toDate(ifNull(timestamp, toDateTime(0, 'UTC'))), toDecimal64(0, 10))))) AS amountFROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.revenue_analytics.mrr_views.stripe_charges/posthog_test_stripe_charge/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `paid` Int8, `amount` Int64, `object` String, `source` String, `status` String, `created` DateTime, `invoice` String, `outcome` String, `captured` Int8, `currency` String, `customer` String, `disputed` Int8, `livemode` Int8, `metadata` String, `refunded` Int8, `description` String, `receipt_url` String, `failure_code` String, `fraud_details` String, `radar_options` String, `receipt_email` String, `payment_intent` String, `payment_method` String, `amount_captured` Int64, `amount_refunded` Int64, `billing_details` String, `failure_message` String, `balance_transaction` String, `statement_descriptor` String, `payment_method_details` String, `calculated_statement_descriptor` String') AS posthog_test_stripe_chargeWHERE and(or(isNull(invoice_id), empty(invoice_id)), equals(posthog_test_stripe_charge.status, 'succeeded'))) AS revenue_itemWHERE and(revenue_item.is_recurring, isNotNull(revenue_item.subscription_id), ifNull(greaterOrEquals(timestamp, toStartOfMonth(addDays(toDateTime64('2025-05-31 00:00:00.000000', 6, 'UTC'), -60))), 0), ifNull(lessOrEquals(timestamp, toDateTime64('2025-05-31 00:00:00.000000', 6, 'UTC')), 0))@@ -379,7 +379,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- if(isNull(upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', ''))), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals(upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', '')), 'GBP'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', '')), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', '')), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', '')), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'GBP', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull(upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', ''))), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals(upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', '')), 'GBP'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', '')), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', '')), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'currency'), ''), 'null'), '^"|"$', '')), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'GBP', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,diff --git a/products/revenue_analytics/backend/views/test/__snapshots__/test_mrr_views.new_events_schema.ambr b/products/revenue_analytics/backend/views/test/__snapshots__/test_mrr_views.new_events_schema.ambrindex 8dd546f89d8e..3631637ed05f 100644--- a/products/revenue_analytics/backend/views/test/__snapshots__/test_mrr_views.new_events_schema.ambr+++ b/products/revenue_analytics/backend/views/test/__snapshots__/test_mrr_views.new_events_schema.ambr@@ -39,7 +39,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- if(isNull(upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency))))))), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals(upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency)))))), 'GBP'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency)))))), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency)))))), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency)))))), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'GBP', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull(upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency))))))), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals(upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency)))))), 'GBP'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency)))))), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency)))))), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency)))))), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'GBP', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -155,7 +155,7 @@if(enable_currency_aware_divider, accurateCastOrNull(1, 'Decimal64(10)'), accurateCastOrNull(100, 'Decimal64(10)')) AS currency_aware_divider,divideDecimal(original_amount, currency_aware_divider) AS currency_aware_amount,'GBP' AS currency,- if(isNull(upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency))))))), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals(upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency)))))), 'GBP'), toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency)))))), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency)))))), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency)))))), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'GBP', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amount+ if(isNull(upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency))))))), accurateCastOrNull(currency_aware_amount, 'Decimal64(10)'), if(equals(upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency)))))), 'GBP'), toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency)))))), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(0, 10), multiplyDecimal(divideDecimal(toDecimal128(currency_aware_amount, 10), if(ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency)))))), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)) = 0, toDecimal128(1, 10), ifNull(dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', upper(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^currency)), if(isNull(nullIf(toString(events.properties.currency), '')), NULL, if(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'DateTime'), concat(ifNull(toString(replaceOne(substring(toString(accurateCastOrNull(events.properties.currency, 'DateTime64(9, \'UTC\')')), 1, 19), ' ', 'T')), ''), ifNull(toString(substring(toString(events.properties.currency), 20, 10)), ''), 'Z'), if(or(startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Array'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Map'), startsWith(dynamicType(accurateCast(events.properties.currency, 'Dynamic')), 'Tuple')), nullIf(nullIf(toJSONString(events.properties.currency), '[]'), '{}'), toString(events.properties.currency)))))), toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)), toDecimal64(0, 10)))), dictGetOrDefault(`posthog_test`.`exchange_rate_dict`, 'rate', 'GBP', toDate(toTimeZone(events.timestamp, 'UTC')), toDecimal64(0, 10)))))) AS amountFROM events_json AS eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,