The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Inline parameter in clickhouse honeysql method (#70905)
Riley Thompson0ac98129d956
diff --git a/modules/drivers/clickhouse/src/metabase/driver/clickhouse_qp.clj b/modules/drivers/clickhouse/src/metabase/driver/clickhouse_qp.cljindex e5c083c1b0c..7b0b706f928 100644--- a/modules/drivers/clickhouse/src/metabase/driver/clickhouse_qp.clj+++ b/modules/drivers/clickhouse/src/metabase/driver/clickhouse_qp.clj@@ -183,8 +183,8 @@(let [report-timezone (get-report-timezone-id-safely)inner-expr (h2x// expr 1000)](if report-timezone- [:'toDateTime64 inner-expr 3 report-timezone]- [:'toDateTime64 inner-expr 3])))+ [:'toDateTime64 inner-expr [:inline 3] (h2x/literal report-timezone)]+ [:'toDateTime64 inner-expr [:inline 3]])))(defmethod sql.qp/unix-timestamp->honeysql [:clickhouse :microseconds][_ _ expr]diff --git a/modules/drivers/clickhouse/test/metabase/driver/clickhouse_substitution_test.clj b/modules/drivers/clickhouse/test/metabase/driver/clickhouse_substitution_test.cljindex 413c52d3339..e60c41620dd 100644--- a/modules/drivers/clickhouse/test/metabase/driver/clickhouse_substitution_test.clj+++ b/modules/drivers/clickhouse/test/metabase/driver/clickhouse_substitution_test.clj@@ -336,6 +336,45 @@:target ["variable" ["template-tag" "x"]]:id uuid}]}))))))))+(deftest ^:parallel clickhouse-field-filter-unix-millis-coercion-test+ (mt/test-driver :clickhouse+ (mt/with-clock clock+ (testing "Field filter on a UInt64 column coerced to UNIX milliseconds->DateTime generates valid SQL (#70901)"+ (let [now (local-date-time-now)+ ->epoch-millis (fn [^LocalDateTime ldt]+ (.toEpochMilli (.toInstant (.atZone ldt (java.time.ZoneId/of "UTC")))))]+ (mt/dataset+ (mt/dataset-definition "milliseconds_db"+ [["milliseconds_table"+ [{:field-name "time"+ :base-type {:native "UInt64"}+ :effective-type :type/Instant+ :coercion-strategy :Coercion/UNIXMilliSeconds->DateTime}+ {:field-name "name"+ :base-type :type/Text}]+ [[(->epoch-millis (.minusDays now 2)) "Event A"]+ [(->epoch-millis (.minusHours now 24)) "Event B"]+ [(->epoch-millis (.plusHours now 1)) "Event C"]+ [(->epoch-millis (.plusDays now 2)) "Event D"]]]])+ (let [uuid (str (random-uuid))+ query {:database (mt/id)+ :type "native"+ :native {:collection "milliseconds-table"+ :template-tags {:date_filter {:id uuid+ :name "time"+ :display-name "Time"+ :type "dimension"+ :dimension ["field" (mt/id :milliseconds-table :time) nil]+ :required true}}+ :query "SELECT * FROM `milliseconds_db`.`milliseconds_table` WHERE {{date_filter}}"}+ :parameters [{:type "date/all-options"+ :value "past7days"+ :target ["dimension" ["template-tag" "date_filter"]]+ :id uuid}]}]+ (is (= [[1 1574982000000 "Event A"]+ [2 1575068400000 "Event B"]]+ (mt/rows (qp/process-query query)))))))))))+(deftest clickhouse-native-query-with-uuid-filter-test(mt/test-driver :clickhouse(let [uuid-1 #uuid "3127abff-e634-4114-a015-59893b49ae74"