Error on Query String Length Limit?

Hi,

I'm facing an error after upgrade the version from 0.42 to 0.45.
Before upgrading all native query was fine but some of them get error after upgrading.

Sadly, the error message does not tell me any hint for me like below.
image

After digging the query myself, I found that it is fine when the query length is until 4,220 but 4,221 get error.
(After testing more, found that the length of query string randomly makes error.)

I want to accent that the query was fine before upgrade the version and there was no change except upgrade.

Below is my diagnostic info, please give me how to solve this error.

{
  "browser-info": {
    "language": "ko-KR",
    "platform": "MacIntel",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Whale/3.18.154.8 Safari/537.36",
    "vendor": "NAVER Corp."
  },
  "system-info": {
    "file.encoding": "UTF-8",
    "java.runtime.name": "OpenJDK Runtime Environment",
    "java.runtime.version": "11+28",
    "java.vendor": "Oracle Corporation",
    "java.vendor.url": "http://java.oracle.com/",
    "java.version": "11",
    "java.vm.name": "OpenJDK 64-Bit Server VM",
    "java.vm.version": "11+28",
    "os.name": "Linux",
    "os.version": "4.15.0-163-generic",
    "user.language": "ko",
    "user.timezone": "Asia/Seoul"
  },
  "metabase-info": {
    "databases": [
      "impala",
      "athena",
      "mysql"
    ],
    "hosting-env": "unknown",
    "application-database": "mysql",
    "application-database-details": {
      "database": {
        "name": "MySQL",
        "version": "8.0.30-26.11"
      },
      "jdbc-driver": {
        "name": "MariaDB Connector/J",
        "version": "2.7.6"
      }
    },
    "run-mode": "prod",
    "version": {
      "date": "2023-02-19",
      "tag": "v0.45.3",
      "branch": "release-x.45.x",
      "hash": "070f57b"
    },
    "settings": {
      "report-timezone": null
    }
  }
}

Plus, below is the error log for the query.

[21e39208-b45a-49ce-836b-6172bb2f0a3e] 2023-03-27T11:16:49+09:00 ERROR metabase.query-processor.middleware.catch-exceptions Error processing query: Error running query
{:database_id 8,
 :started_at #t "2023-03-27T11:16:46.346673+09:00[Asia/Seoul]",
 :via
 [{:status :failed,
   :class clojure.lang.ExceptionInfo,
   :error "Error executing query: null",
   :stacktrace
   ["--> driver.sql_jdbc.execute$execute_reducible_query$fn__56094.invoke(execute.clj:501)"
    "driver.sql_jdbc.execute$execute_reducible_query.invokeStatic(execute.clj:498)"
    "driver.sql_jdbc.execute$execute_reducible_query.invoke(execute.clj:485)"
    "driver.sql_jdbc.execute$execute_reducible_query.invokeStatic(execute.clj:493)"
    "driver.sql_jdbc.execute$execute_reducible_query.invoke(execute.clj:485)"
    "driver.sql_jdbc$fn__88601.invokeStatic(sql_jdbc.clj:58)"
    "driver.sql_jdbc$fn__88601.invoke(sql_jdbc.clj:56)"
    "driver.athena$fn__99815.invokeStatic(athena.clj:424)"
    "driver.athena$fn__99815.invoke(athena.clj:422)"
    "query_processor.context$executef.invokeStatic(context.clj:59)"
    "query_processor.context$executef.invoke(context.clj:48)"
    "query_processor.context.default$default_runf.invokeStatic(default.clj:67)"
    "query_processor.context.default$default_runf.invoke(default.clj:65)"
    "query_processor.context$runf.invokeStatic(context.clj:45)"
    "query_processor.context$runf.invoke(context.clj:39)"
    "query_processor.reducible$identity_qp.invokeStatic(reducible.clj:12)"
    "query_processor.reducible$identity_qp.invoke(reducible.clj:9)"
    "query_processor.middleware.cache$maybe_return_cached_results$maybe_return_cached_results_STAR___53600.invoke(cache.clj:220)"
    "query_processor.middleware.permissions$check_query_permissions$fn__49259.invoke(permissions.clj:109)"
    "query_processor.middleware.mbql_to_native$mbql__GT_native$fn__52545.invoke(mbql_to_native.clj:23)"
    "query_processor$fn__55076$combined_post_process__55081$combined_post_process_STAR___55082.invoke(query_processor.clj:212)"
    "query_processor$fn__55076$combined_pre_process__55077$combined_pre_process_STAR___55078.invoke(query_processor.clj:209)"
    "query_processor.middleware.resolve_database_and_driver$resolve_database_and_driver$fn__53521$fn__53526.invoke(resolve_database_and_driver.clj:35)"
    "driver$do_with_driver.invokeStatic(driver.clj:76)"
    "driver$do_with_driver.invoke(driver.clj:72)"
    "query_processor.middleware.resolve_database_and_driver$resolve_database_and_driver$fn__53521.invoke(resolve_database_and_driver.clj:34)"
    "query_processor.middleware.fetch_source_query$resolve_card_id_source_tables$fn__49525.invoke(fetch_source_query.clj:314)"
    "query_processor.middleware.store$initialize_store$fn__49715$fn__49716.invoke(store.clj:11)"
    "query_processor.store$do_with_store.invokeStatic(store.clj:45)"
    "query_processor.store$do_with_store.invoke(store.clj:39)"
    "query_processor.middleware.store$initialize_store$fn__49715.invoke(store.clj:10)"
    "query_processor.middleware.normalize_query$normalize$fn__53793.invoke(normalize_query.clj:22)"
    "query_processor.middleware.constraints$add_default_userland_constraints$fn__50803.invoke(constraints.clj:53)"
    "query_processor.middleware.process_userland_query$process_userland_query$fn__53732.invoke(process_userland_query.clj:145)"
    "query_processor.middleware.catch_exceptions$catch_exceptions$fn__54104.invoke(catch_exceptions.clj:167)"
    "query_processor.reducible$async_qp$qp_STAR___45514$thunk__45516.invoke(reducible.clj:100)"
    "query_processor.reducible$async_qp$qp_STAR___45514.invoke(reducible.clj:106)"
    "query_processor.reducible$async_qp$qp_STAR___45514.invoke(reducible.clj:91)"
    "query_processor.reducible$sync_qp$qp_STAR___45525.doInvoke(reducible.clj:126)"
    "query_processor$process_userland_query.invokeStatic(query_processor.clj:331)"
    "query_processor$process_userland_query.doInvoke(query_processor.clj:327)"
    "query_processor$fn__55123$process_query_and_save_execution_BANG___55132$fn__55135.invoke(query_processor.clj:342)"
    "query_processor$fn__55123$process_query_and_save_execution_BANG___55132.invoke(query_processor.clj:335)"
    "query_processor$fn__55167$process_query_and_save_with_max_results_constraints_BANG___55176$fn__55179.invoke(query_processor.clj:354)"
    "query_processor$fn__55167$process_query_and_save_with_max_results_constraints_BANG___55176.invoke(query_processor.clj:347)"
    "api.dataset$run_query_async$fn__70529.invoke(dataset.clj:69)"
    "query_processor.streaming$streaming_response_STAR_$fn__40610$fn__40611.invoke(streaming.clj:162)"
    "query_processor.streaming$streaming_response_STAR_$fn__40610.invoke(streaming.clj:161)"
    "async.streaming_response$do_f_STAR_.invokeStatic(streaming_response.clj:65)"
    "async.streaming_response$do_f_STAR_.invoke(streaming_response.clj:63)"
    "async.streaming_response$do_f_async$task__20021.invoke(streaming_response.clj:84)"],
   :error_type :invalid-query,
   :ex-data
   {:sql
    "-- Metabase:: userID: 1 queryType: native queryHash: 734aa727f63cbb3ef20d3fb662c14a21a92c794b46dba85f0d7332cd0d5241cb\nselect case when segment = 'seg_cookie_list_first_buyer_new' then 1\r\n            when segment = 'seg_cookie_list_first_buyer_buy_term' then 2\r\n            when segment = 'seg_cookie_list_first_buyer_wakeup' then 3\r\n            when segment = 'seg_cookie_list_first_buyer_rebuy' then 4\r\n            when segment = 'seg_cookie_list_first_buyer_high_value' then 5\r\n            when segment = 'seg_cookie_list_first_buyer_growth' then 6\r\n            when segment = 'seg_cookie_list_first_buyer_attention' then 7\r\n            when segment = 'seg_cookie_list_regular_buyer_high_churn' then 9\r\n            when segment = 'seg_cookie_list_regular_buyer_lull' then 10\r\n            when segment = 'seg_cookie_list_regular_buyer_buy_term' then 11\r\n            when segment = 'seg_cookie_list_regular_buyer_wakeup' then 12\r\n            when segment = 'seg_cookie_list_regular_buyer_must_catch' then 13\r\n            when segment = 'seg_cookie_list_regular_buyer_low_value' then 14\r\n            when segment = 'seg_cookie_list_regular_buyer_lull_rich' then 15\r\n            when segment = 'seg_cookie_list_regular_buyer_recent_buy' then 16\r\n            when segment = 'seg_cookie_list_regular_buyer_short_buy_term' then 17\r\n            when segment = 'seg_cookie_list_regular_buyer_high_pred_buy' then 18\r\n            when segment = 'seg_cookie_list_regular_buyer_recent_buy_frequent' then 19\r\n            when segment = 'seg_cookie_list_regular_buyer_high_value' then 20\r\n            when segment = 'seg_cookie_list_regular_buyer_loyal_pred' then 21\r\n            when segment = 'seg_cookie_list_regular_buyer_high_cont_pred' then 22\r\n            when segment = 'seg_cookie_list_regular_buyer_high_cont_recent' then 23\r\n            when segment = 'seg_cookie_list_regular_buyer_high_value_recent' then 24\r\n\t\t\twhen segment = 'seg_cookie_list_regular_buyer_low_value_frequent' then 25\r\n            when segment = 'seg_cookie_list_regular_buyer_low_value_pred' then 26\r\n            when segment = 'seg_cookie_list_regular_buyer_frequent' then 27\r\n\t\t\twhen segment = 'seg_cookie_list_loyal_buyer_must_catch' then 29\r\n            when segment = 'seg_cookie_list_loyal_buyer_lull' then 30\r\n            when segment = 'seg_cookie_list_loyal_buyer_buy_term' then 31\r\n\t\t\twhen segment = 'seg_cookie_list_loyal_buyer_wakeup' then 32\r\n            when segment = 'seg_cookie_list_loyal_buyer_must_catch_loyal' then 33\r\n            when segment = 'seg_cookie_list_loyal_buyer_low_value_recent' then 34\r\n\t\t\twhen segment = 'seg_cookie_list_loyal_buyer_recent' then 35\r\n            when segment = 'seg_cookie_list_loyal_buyer_short_buy_term' then 36\r\n            when segment = 'seg_cookie_list_loyal_buyer_high_pred_buy' then 37\r\n\t\t\twhen segment = 'seg_cookie_list_loyal_buyer_buy_frequent' then 38\r\n            when segment = 'seg_cookie_list_loyal_buyer_loyal' then 39\r\n            when segment = 'seg_cookie_list_loyal_buyer_high_loyalty' then 40\r\n\t\t\twhen segment = 'seg_cookie_list_loyal_buyer_high_cont_recent' then 41\r\n            when segment = 'seg_cookie_list_loyal_buyer_high_value_recent' then 42\r\n            when segment = 'seg_cookie_ongoing_join_not_first_buy_1d' then 43\r\n            when segment = 'seg_cookie_ongoing_join_not_first_buy_1w' then 44\r\n            when segment = 'seg_cookie_ongoing_join_not_first_buy_1d_1w' then 45\r\n            when segment = 'seg_cookie_ongoing_join_not_visit_not_first_buy_1w' then 46\r\n            when segment = 'seg_cookie_ongoing_join_visit_not_first_buy_1d' then 47\r\n            when segment = 'seg_cookie_ongoing_join_visit_not_first_buy_1w' then 48\r\n            when segment = 'seg_cookie_ongoing_visit_not_first_buy_1d' then 49\r\n            when segment = 'seg_cookie_ongoing_visit_not_first_buy_1w' then 50\r\n            when segment = 'seg_cookie_ongoing_visit_not_first_buy_1d_1w' then 51\r\n            when segment = 'seg_cookie_ongoing_cart_not_first_buy_1d' then 52\r\n            when segment = 'seg_cookie_ongoing_cart_not_first_buy_1w' then 53 when segment = '' then 54\r\n\t\t\telse 0 end segment_no\r\n    , buy_ucnt\r\n    , hist_ltv\r\n    , hist_ltv_unit_avg\r\n    , buy_num_unit_avg\r\n    , pred_ltv_1m\r\n    , pred_ltv_3m\r\n    , pred_ltv_6m\r\n    , buy_term\r\nfrom ai_box.segment_kpi a\r\nwhere dt = '20230326'\r\nand company_id in ('96159')\r\norder by segment_no",
    :params nil,
    :type :invalid-query}}],
 :error_type :invalid-query,
 :json_query
 {:type "native",
  :native
  {:query
   "select case when segment = 'seg_cookie_list_first_buyer_new' then 1\r\n            when segment = 'seg_cookie_list_first_buyer_buy_term' then 2\r\n            when segment = 'seg_cookie_list_first_buyer_wakeup' then 3\r\n            when segment = 'seg_cookie_list_first_buyer_rebuy' then 4\r\n            when segment = 'seg_cookie_list_first_buyer_high_value' then 5\r\n            when segment = 'seg_cookie_list_first_buyer_growth' then 6\r\n            when segment = 'seg_cookie_list_first_buyer_attention' then 7\r\n            when segment = 'seg_cookie_list_regular_buyer_high_churn' then 9\r\n            when segment = 'seg_cookie_list_regular_buyer_lull' then 10\r\n            when segment = 'seg_cookie_list_regular_buyer_buy_term' then 11\r\n            when segment = 'seg_cookie_list_regular_buyer_wakeup' then 12\r\n            when segment = 'seg_cookie_list_regular_buyer_must_catch' then 13\r\n            when segment = 'seg_cookie_list_regular_buyer_low_value' then 14\r\n            when segment = 'seg_cookie_list_regular_buyer_lull_rich' then 15\r\n            when segment = 'seg_cookie_list_regular_buyer_recent_buy' then 16\r\n            when segment = 'seg_cookie_list_regular_buyer_short_buy_term' then 17\r\n            when segment = 'seg_cookie_list_regular_buyer_high_pred_buy' then 18\r\n            when segment = 'seg_cookie_list_regular_buyer_recent_buy_frequent' then 19\r\n            when segment = 'seg_cookie_list_regular_buyer_high_value' then 20\r\n            when segment = 'seg_cookie_list_regular_buyer_loyal_pred' then 21\r\n            when segment = 'seg_cookie_list_regular_buyer_high_cont_pred' then 22\r\n            when segment = 'seg_cookie_list_regular_buyer_high_cont_recent' then 23\r\n            when segment = 'seg_cookie_list_regular_buyer_high_value_recent' then 24\r\n\t\t\twhen segment = 'seg_cookie_list_regular_buyer_low_value_frequent' then 25\r\n            when segment = 'seg_cookie_list_regular_buyer_low_value_pred' then 26\r\n            when segment = 'seg_cookie_list_regular_buyer_frequent' then 27\r\n\t\t\twhen segment = 'seg_cookie_list_loyal_buyer_must_catch' then 29\r\n            when segment = 'seg_cookie_list_loyal_buyer_lull' then 30\r\n            when segment = 'seg_cookie_list_loyal_buyer_buy_term' then 31\r\n\t\t\twhen segment = 'seg_cookie_list_loyal_buyer_wakeup' then 32\r\n            when segment = 'seg_cookie_list_loyal_buyer_must_catch_loyal' then 33\r\n            when segment = 'seg_cookie_list_loyal_buyer_low_value_recent' then 34\r\n\t\t\twhen segment = 'seg_cookie_list_loyal_buyer_recent' then 35\r\n            when segment = 'seg_cookie_list_loyal_buyer_short_buy_term' then 36\r\n            when segment = 'seg_cookie_list_loyal_buyer_high_pred_buy' then 37\r\n\t\t\twhen segment = 'seg_cookie_list_loyal_buyer_buy_frequent' then 38\r\n            when segment = 'seg_cookie_list_loyal_buyer_loyal' then 39\r\n            when segment = 'seg_cookie_list_loyal_buyer_high_loyalty' then 40\r\n\t\t\twhen segment = 'seg_cookie_list_loyal_buyer_high_cont_recent' then 41\r\n            when segment = 'seg_cookie_list_loyal_buyer_high_value_recent' then 42\r\n            when segment = 'seg_cookie_ongoing_join_not_first_buy_1d' then 43\r\n            when segment = 'seg_cookie_ongoing_join_not_first_buy_1w' then 44\r\n            when segment = 'seg_cookie_ongoing_join_not_first_buy_1d_1w' then 45\r\n            when segment = 'seg_cookie_ongoing_join_not_visit_not_first_buy_1w' then 46\r\n            when segment = 'seg_cookie_ongoing_join_visit_not_first_buy_1d' then 47\r\n            when segment = 'seg_cookie_ongoing_join_visit_not_first_buy_1w' then 48\r\n            when segment = 'seg_cookie_ongoing_visit_not_first_buy_1d' then 49\r\n            when segment = 'seg_cookie_ongoing_visit_not_first_buy_1w' then 50\r\n            when segment = 'seg_cookie_ongoing_visit_not_first_buy_1d_1w' then 51\r\n            when segment = 'seg_cookie_ongoing_cart_not_first_buy_1d' then 52\r\n            when segment = 'seg_cookie_ongoing_cart_not_first_buy_1w' then 53 when segment = '' then 54\r\n\t\t\telse 0 end segment_no\r\n    , buy_ucnt\r\n    , hist_ltv\r\n    , hist_ltv_unit_avg\r\n    , buy_num_unit_avg\r\n    , pred_ltv_1m\r\n    , pred_ltv_3m\r\n    , pred_ltv_6m\r\n    , buy_term\r\nfrom ai_box.segment_kpi a\r\nwhere dt = '20230326'\r\nand company_id in ('96159')\r\norder by segment_no",
   :template-tags {}},
  :database 8,
  :parameters [],
  :middleware {:js-int-to-string? true, :add-default-userland-constraints? true}},
 :status :failed,
 :class java.lang.StackOverflowError,
 :stacktrace
 ["java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4791)"
  "java.base/java.util.regex.Pattern$Loop.match(Pattern.java:4928)"
  "java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:4850)"
  "java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4700)"
  "java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4700)"
  "java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:3927)"
  "java.base/java.util.regex.Pattern$Neg.match(Pattern.java:5246)"
  "java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4736)"
  "java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4791)"
  "java.base/java.util.regex.Pattern$Loop.match(Pattern.java:4928)"
  "java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:4850)"
  "java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4700)"
  "java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:3927)"
  "java.base/java.util.regex.Pattern$Neg.match(Pattern.java:5246)"
  "java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4736)"
  "java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4791)"
  "java.base/java.util.regex.Pattern$Loop.match(Pattern.java:4928)"
  "java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:4850)"
  "java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4700)"
  "java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:3927)"
  "java.base/java.util.regex.Pattern$Neg.match(Pattern.java:5246)"
  "java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4736)"
  "java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4791)"
  "java.base/java.util.regex.Pattern$Loop.match(Pattern.java:4928)"
  "java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:4850)"
  "java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4700)"
  "java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:3927)"
  nil],
 :card_id nil,
 :context :ad-hoc,
 :error nil,
 :row_count 0,
 :running_time 0,
 :data {:rows [], :cols []}}

Which dw is this? Can you post the query?

Hi Luiggi,

It is connecting Athena and the query is on just one table and super simple excepts using lots of case when clauses as below.

select case when segment = 'seg_cookie_list_first_buyer_new' then 1
            when segment = 'seg_cookie_list_first_buyer_buy_term' then 2
            when segment = 'seg_cookie_list_first_buyer_wakeup' then 3
            when segment = 'seg_cookie_list_first_buyer_rebuy' then 4
            when segment = 'seg_cookie_list_first_buyer_high_value' then 5
            when segment = 'seg_cookie_list_first_buyer_growth' then 6
            when segment = 'seg_cookie_list_first_buyer_attention' then 7
            when segment = 'seg_cookie_list_regular_buyer_high_churn' then 9
            when segment = 'seg_cookie_list_regular_buyer_lull' then 10
            when segment = 'seg_cookie_list_regular_buyer_buy_term' then 11
            when segment = 'seg_cookie_list_regular_buyer_wakeup' then 12
            when segment = 'seg_cookie_list_regular_buyer_must_catch' then 13
            when segment = 'seg_cookie_list_regular_buyer_low_value' then 14
            when segment = 'seg_cookie_list_regular_buyer_lull_rich' then 15
            when segment = 'seg_cookie_list_regular_buyer_recent_buy' then 16
            when segment = 'seg_cookie_list_regular_buyer_short_buy_term' then 17
            when segment = 'seg_cookie_list_regular_buyer_high_pred_buy' then 18
            when segment = 'seg_cookie_list_regular_buyer_recent_buy_frequent' then 19
            when segment = 'seg_cookie_list_regular_buyer_high_value' then 20
            when segment = 'seg_cookie_list_regular_buyer_loyal_pred' then 21
            when segment = 'seg_cookie_list_regular_buyer_high_cont_pred' then 22
            when segment = 'seg_cookie_list_regular_buyer_high_cont_recent' then 23
            when segment = 'seg_cookie_list_regular_buyer_high_value_recent' then 24
			when segment = 'seg_cookie_list_regular_buyer_low_value_frequent' then 25
            when segment = 'seg_cookie_list_regular_buyer_low_value_pred' then 26
            when segment = 'seg_cookie_list_regular_buyer_frequent' then 27
			when segment = 'seg_cookie_list_loyal_buyer_must_catch' then 29
            when segment = 'seg_cookie_list_loyal_buyer_lull' then 30
            when segment = 'seg_cookie_list_loyal_buyer_buy_term' then 31
			when segment = 'seg_cookie_list_loyal_buyer_wakeup' then 32
            when segment = 'seg_cookie_list_loyal_buyer_must_catch_loyal' then 33
            when segment = 'seg_cookie_list_loyal_buyer_low_value_recent' then 34
			when segment = 'seg_cookie_list_loyal_buyer_recent' then 35
            when segment = 'seg_cookie_list_loyal_buyer_short_buy_term' then 36
            when segment = 'seg_cookie_list_loyal_buyer_high_pred_buy' then 37
			when segment = 'seg_cookie_list_loyal_buyer_buy_frequent' then 38
            when segment = 'seg_cookie_list_loyal_buyer_loyal' then 39
            when segment = 'seg_cookie_list_loyal_buyer_high_loyalty' then 40
			when segment = 'seg_cookie_list_loyal_buyer_high_cont_recent' then 41
            when segment = 'seg_cookie_list_loyal_buyer_high_value_recent' then 42
            when segment = 'seg_cookie_ongoing_join_not_first_buy_1d' then 43
            when segment = 'seg_cookie_ongoing_join_not_first_buy_1w' then 44
            when segment = 'seg_cookie_ongoing_join_not_first_buy_1d_1w' then 45
            when segment = 'seg_cookie_ongoing_join_not_visit_not_first_buy_1w' then 46
            when segment = 'seg_cookie_ongoing_join_visit_not_first_buy_1d' then 47
            when segment = 'seg_cookie_ongoing_join_visit_not_first_buy_1w' then 48
            when segment = 'seg_cookie_ongoing_visit_not_first_buy_1d' then 49
            when segment = 'seg_cookie_ongoing_visit_not_first_buy_1w' then 50
            when segment = 'seg_cookie_ongoing_visit_not_first_buy_1d_1w' then 51
            when segment = 'seg_cookie_ongoing_cart_not_first_buy_1d' then 52
            when segment = 'seg_cookie_ongoing_cart_not_first_buy_1w' then 53
and lots of case when clauses more...
...
...
...
...

			else 0 end segment_no
    , buy_ucnt
    , hist_ltv
    , hist_ltv_unit_avg
    , buy_num_unit_avg
    , pred_ltv_1m
    , pred_ltv_3m
    , pred_ltv_6m
    , buy_term
from ai_box.segment_kpi a
where dt = 'yyyymmdd'
and company_id in ('abc')
order by segment_no

Hi Daniel,

Did you try running the query directly on Athena using an IDE and not metabase.

You mentioned after digging the query myself, I found that it is fine when the query length is until 4,220 but 4,221 get error. Am I correct in assuming that if you remove some of the case when conditions on the above query then it runs fine?

Hi, @TonyC
Sure. I have tried running the whole query directly and it was fine.
And It was okay when I removed some of case when condition from query on metabase.
That's why I suspect there is a sort of limitation about query string length in recently metabase version.

is there a way you could make a join to a table that has the case statements so you don't need to write that in case statements?

@Luiggi
I've already tried the way and it worked.
However it is just temporarily way to run query somehow, I need to know why the query makes error on recent version and how to use the query as it is.

the error seems to indicate a stack overflow, so something went out of parameters clearly :frowning: