Skip to content

Instantly share code, notes, and snippets.

View escherize's full-sized avatar

bryan escherize

View GitHub Profile
Unstaged
modified src/metabase/lib/metadata/calculation.cljc
@@ -22,7 +22,8 @@
[metabase.util.i18n :as i18n]
[metabase.util.log :as log]
[metabase.util.malli :as mu]
- [metabase.util.malli.registry :as mr]))
+ [metabase.util.malli.registry :as mr]
+ [malli.error :as me]))
{
"database_id": 13371337,
"parameterized": false,
"started_at": "2025-08-19T22:24:07.03818Z",
"via": [
{
"status": "failed",
"class": "class org.mariadb.jdbc.internal.util.exceptions.MariaDbSqlException",
"error": "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(order by `source`.`running_time_seconds`) AS `Percentile 90 of query running ti' at line 2",
"stacktrace": [
{
"database_id": 13371337,
"parameterized": false,
"started_at": "2025-08-19T22:22:59.101199Z",
"via": [
{
"status": "failed",
"class": "class org.mariadb.jdbc.internal.util.exceptions.MariaDbSqlException",
"error": "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(order by `source`.`running_time_seconds`) AS `Percentile 90`, PERCENTILE_CONT(0' at line 2",
"stacktrace": [
https://gist.github.com/escherize/e5a0266b8efc7b4ae311762f775a3bfb
{
"database_id": 13371337,
"parameterized": true,
"started_at": "2025-08-19T18:23:49.389733Z",
"via": [
{
"status": "failed",
"class": "class org.mariadb.jdbc.internal.util.exceptions.MariaDbSqlException",
"error": "Unknown column 'source.max' in 'order clause'",
"stacktrace": [
2025-08-19 18:13:31,761 ERROR middleware.catch-exceptions :: Error processing query: Unknown column 'source.max' in 'order clause'
{:database_id 13371337,
:parameterized true,
:started_at #t "2025-08-19T18:13:20.097556Z[UTC]",
:via
[{:status :failed,
:class org.mariadb.jdbc.internal.util.exceptions.MariaDbSqlException,
:error "Unknown column 'source.max' in 'order clause'",
:stacktrace
["org.mariadb.jdbc.internal.util.exceptions.MariaDbSqlException.of(MariaDbSqlException.java:34)"

Toucan2 Hooks: How They Work and Why They're Powerful

The Hook System

Toucan2 uses a derive-based hook system rather than explicit method implementations. You declare behavior by deriving your model from special hook keywords.

Common Hook Patterns in Metabase

1. Timestamps - Automatic created_at/updated_at

Problem Statement

Investigated suspected memory leak in metabase.util.malli.registry/cache atom. Initial reports suggested unbounded memory growth during test runs.

Root Cause Analysis

The real issue wasn't a memory leak, but fundamentally broken caching for function schemas. With the original schema-cache-key implementation, schemas containing function objects generated unstable cache keys because:

(fn [x] ...) creates new function objects each time Function objects have different identity even with identical code This caused cache misses for functionally identical schemas

(ns mage.escherize.analyze-cache-misses
(:require
[clojure.edn :as edn]
[clojure.java.io :as io]
[clojure.string :as str]
[mage.util :as util]))
(defn read-log [log-file]
(map second (edn/read-string (str "[" (slurp log-file) "]"))))
https://gist.github.com/escherize/24e99c1ad6bd6bab2971d520093c2470