{"id":3241,"date":"2021-08-21T09:09:47","date_gmt":"2021-08-21T08:09:47","guid":{"rendered":"https:\/\/kudzia.eu\/b\/?p=3241"},"modified":"2021-08-22T21:10:30","modified_gmt":"2021-08-22T20:10:30","slug":"clickhouse-getting-n-most-significant-digits-of-a-number","status":"publish","type":"post","link":"https:\/\/kudzia.eu\/b\/2021\/08\/clickhouse-getting-n-most-significant-digits-of-a-number\/","title":{"rendered":"clickhouse &#8211; getting n most significant digits of a number"},"content":{"rendered":"<p>i&#8217;m testing some wild idea of finding matches in quite a large dataset. part of the problem is that scaling of input is unknown, 123 might be correct match for 1.23 or for 12.3.<\/p>\n<p>here&#8217;s an expression that returns me n=4 most significant digits of each float from the input array:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nSELECT arrayMap(x -&gt; if(x = 0, 0, floor(pow(10, 3 - floor(log10(abs(x)))) * abs(x)) * sign(x)), &#x5B;10, 23, 11.1, 3783.3, -0.3213, 0, 9831982732196.318]) AS res\r\n\r\n\u250c\u2500res\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\r\n\u2502 &#x5B;1000,2300,1110,3783,-3212,0,9831] \u2502\r\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>i&#8217;m testing some wild idea of finding matches in quite a large dataset. part of the problem is that scaling of input is unknown, 123 might be correct match for 1.23 or for 12.3. here&#8217;s an expression that returns me n=4 most significant digits of each float from the input array: SELECT arrayMap(x -&gt; if(x [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[112],"class_list":["post-3241","post","type-post","status-publish","format-standard","hentry","category-unimportant","tag-clickhouse"],"_links":{"self":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/3241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/comments?post=3241"}],"version-history":[{"count":1,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/3241\/revisions"}],"predecessor-version":[{"id":3242,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/3241\/revisions\/3242"}],"wp:attachment":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/media?parent=3241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/categories?post=3241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/tags?post=3241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}