Skip to content
Snippets Groups Projects
Unverified Commit 96bb2ee6 authored by Cam Saul's avatar Cam Saul Committed by GitHub
Browse files

Merge pull request #9254 from metabase/paychex-binning_ratio_fix

Paychex binning ratio fix
parents 8ddbee2a 7d6c0383
Branches
Tags
No related merge requests found
......@@ -45,6 +45,12 @@
java.lang.Number
(to-sql [x] (str x)))
;; Ratios are represented as the division of two numbers which may cause order-of-operation issues when dealing with
;; queries. The easiest way around this is to convert them to their decimal representations.
(extend-protocol honeysql.format/ToSql
clojure.lang.Ratio
(to-sql [x] (hformat/to-sql (double x))))
;; HoneySQL automatically assumes that dots within keywords are used to separate schema / table / field / etc. To
;; handle weird situations where people actually put dots *within* a single identifier we'll replace those dots with
;; lozenges, let HoneySQL do its thing, then switch them back at the last second
......
(ns metabase.util.honeysql-extensions-test
(:require [expectations :refer :all]
[honeysql.format :as hformat]
[metabase.util.honeysql-extensions :as hsql-ext])
[honeysql
[core :as hsql]
[format :as hformat]])
(:import java.util.Locale))
;; Basic format test not including a specific quoting option
......@@ -35,3 +36,9 @@
["\"SETTING\""]
(with-locale "tr"
(hformat/format :setting :quoting :h2)))
;; test ToSql behavior for Ratios (#9246). Should convert to a double rather than leaving it as a division operation.
;; The double itself should get converted to a numeric literal
(expect
["SELECT 0.1 AS one_tenth"]
(hsql/format {:select [[(/ 1 10) :one_tenth]]}))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment