:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(clickhouse): return an empty string from JSONDropKeys for empty input (#114775)
Phil Haackaa092e5294c4
diff --git a/clickhouse-udfs/util/cmd/json_drop_keys_udf/main.go b/clickhouse-udfs/util/cmd/json_drop_keys_udf/main.goindex 7a74e9792345..ab18e7b1e502 100644--- a/clickhouse-udfs/util/cmd/json_drop_keys_udf/main.go+++ b/clickhouse-udfs/util/cmd/json_drop_keys_udf/main.go@@ -96,6 +96,11 @@ var parserPool = sync.Pool{}func processLine(keys jsonKey, rawLine []byte, buf *bytes.Buffer) error {+ // A legacy events JSON column stores '' when its producer omits the value. An empty value has no key to drop.+ if len(rawLine) == 0 {+ buf.Reset()+ return nil+ }parser := parserPool.Get().(*cachedParser)defer parserPool.Put(parser)if parser.maxInput > max(64*1024, 2*len(rawLine)) {diff --git a/clickhouse-udfs/util/cmd/json_drop_keys_udf/main_test.go b/clickhouse-udfs/util/cmd/json_drop_keys_udf/main_test.goindex 0fbb32e75d49..cf5d22ff7ca9 100644--- a/clickhouse-udfs/util/cmd/json_drop_keys_udf/main_test.go+++ b/clickhouse-udfs/util/cmd/json_drop_keys_udf/main_test.go@@ -242,6 +242,7 @@ func TestRunRowBinary(t *testing.T) {input := encodeRowBinaryChunks([]rowBinaryRow{{json: `{"a":1,"b":2}`, keys: []string{"a"}},+ {json: "", keys: []string{"a"}},{json: `{"a":1,"b":2}`, keys: []string{"a"}},{json: `{"a":1,"b":2}`, keys: []string{"b"}},{json: "{\n\"a\":1,\t\"b\":\"x\\ny\"}", keys: []string{"a"}},@@ -258,6 +259,7 @@ func TestRunRowBinary(t *testing.T) {}assert.Equal(t, []string{`{"b":2}`,+ "",`{"b":2}`,`{"a":1}`,`{"b":"x\ny"}`,diff --git a/clickhouse-udfs/util/testdata/json_drop_keys/stateless/README.md b/clickhouse-udfs/util/testdata/json_drop_keys/stateless/README.mdindex e80e3ba39abe..519e772fdc25 100644--- a/clickhouse-udfs/util/testdata/json_drop_keys/stateless/README.md+++ b/clickhouse-udfs/util/testdata/json_drop_keys/stateless/README.md@@ -8,4 +8,5 @@ Each test has a `<name>.tsv` input and a matching `<name>.reference` expected ou| `drop_nested_a_and_keep_dotted_keys` | Drops top-level `a` values and verifies dotted keys that are not dropped keep their flat form. || `large_integer` | Preserves large integer values while dropping only requested keys. || `root_array` | Drops keys from objects when the root JSON value is an array. |+| `empty_input` | Returns an empty string for an empty input value. || `malformed_json.fail` | Verifies malformed JSON fails instead of being hidden. |diff --git a/clickhouse-udfs/util/testdata/json_drop_keys/stateless/empty_input.reference b/clickhouse-udfs/util/testdata/json_drop_keys/stateless/empty_input.referencenew file mode 100644index 000000000000..c18760def38e--- /dev/null+++ b/clickhouse-udfs/util/testdata/json_drop_keys/stateless/empty_input.reference@@ -0,0 +1,3 @@+{"b":2}++{}diff --git a/clickhouse-udfs/util/testdata/json_drop_keys/stateless/empty_input.tsv b/clickhouse-udfs/util/testdata/json_drop_keys/stateless/empty_input.tsvnew file mode 100644index 000000000000..eccda3d98f05--- /dev/null+++ b/clickhouse-udfs/util/testdata/json_drop_keys/stateless/empty_input.tsv@@ -0,0 +1,3 @@+{"a":1,"b":2}++{"a":3}diff --git a/docs/internal/clickhouse-utility-udfs.md b/docs/internal/clickhouse-utility-udfs.mdindex cb9b432254f4..fb8746bd3c70 100644--- a/docs/internal/clickhouse-utility-udfs.md+++ b/docs/internal/clickhouse-utility-udfs.md@@ -231,6 +231,7 @@ The worker keeps the parsed filter for the most recent key array and parses it aBoth functions use the `json_drop_keys_udf` executable. The pool entry point uses `--row-binary` with chunk headers.RowBinary transport lets the JSON contain raw newlines and tabs.Malformed JSON, truncated chunks, a JSON value above 1 GiB, more than 65,536 keys, and a key above 64 KiB fail the query.+Both functions return an empty string for an empty input value, which legacy events JSON columns can hold.With 1,000,000 small synthetic rows, `max_threads = 1`, and ClickHouse 26.6.2.158 on an Apple M4 Pro, best of three runs, recorded September 24, 2026:diff --git a/posthog/user_scripts/json_drop_keys_udf_aarch64 b/posthog/user_scripts/json_drop_keys_udf_aarch64index ebbd19c6443a..64bef7398d79 100755Binary files a/posthog/user_scripts/json_drop_keys_udf_aarch64 and b/posthog/user_scripts/json_drop_keys_udf_aarch64 differdiff --git a/posthog/user_scripts/json_drop_keys_udf_x86_64 b/posthog/user_scripts/json_drop_keys_udf_x86_64index 517d9085078b..995351ae7e18 100755Binary files a/posthog/user_scripts/json_drop_keys_udf_x86_64 and b/posthog/user_scripts/json_drop_keys_udf_x86_64 differ