Skip to content

Commit b46ae2f

Browse files
authored
fix: Fix sidebar when selecting JSON property (#1231)
Closes HDX-2042 Closes HDX-2524 Closes HDX-2307 Closes #1010 # Summary This PR fixes errors that occurred when attempting to open the sidebar by clicking a log table row using a JSON logs table schema. The error was caused by `node-sql-parser` throwing exceptions when parsing SQL with JSON Expressions, resulting in HyperDX being unable to extract aliases from the SQL. In the long term, we'll want to have a true ClickHouse SQL parser. In the short term, this is fixed by: 1. Finding and replacing all JSON expressions in the sql with placeholder tokens, prior to parsing with node-sql-parser 2. Parsing with node-sql-parser to find aliases correctly 3. Replacing the placeholder tokens with the original JSON expressions ## Testing (All of the following use a JSON schema) ### Before <details> <summary>When selecting a JSON column with an alias</summary> <img width="1126" height="96" alt="Screenshot 2025-10-01 at 2 28 19 PM" src="https://github.com/user-attachments/assets/c35ed870-9986-4b30-9890-e1ca8ff6c92c" /> <img width="372" height="142" alt="Screenshot 2025-10-01 at 2 28 06 PM" src="https://github.com/user-attachments/assets/d65fdce4-6625-4308-b5d0-6f845a0f2f05" /> </details> <details> <summary>When filtering by a JSON column and using an alias on a non-JSON property</summary> <img width="800" height="103" alt="Screenshot 2025-10-01 at 2 29 44 PM" src="https://github.com/user-attachments/assets/aa7faabb-316b-4103-8840-74ac08519efb" /> <img width="372" height="142" alt="Screenshot 2025-10-01 at 2 28 06 PM" src="https://github.com/user-attachments/assets/eb86cce5-eee4-40f9-af93-2451bff32444" /> </details> ### After <details> <summary>When selecting a JSON column with an alias</summary> <img width="1126" height="96" alt="Screenshot 2025-10-01 at 2 28 19 PM" src="https://github.com/user-attachments/assets/678ba290-5215-4cc5-8fee-1bf67955aaa2" /> <img width="725" height="696" alt="Screenshot 2025-10-01 at 2 30 42 PM" src="https://github.com/user-attachments/assets/5da48109-a0cd-4b5f-a5e3-bd700116d81b" /> </details> <details> <summary>When filtering by a JSON column and using an alias on a non-JSON property</summary> <img width="800" height="103" alt="Screenshot 2025-10-01 at 2 29 44 PM" src="https://github.com/user-attachments/assets/715de816-639e-4ffd-9e09-341bd0b2ee4a" /> <img width="1271" height="888" alt="Screenshot 2025-10-01 at 2 30 24 PM" src="https://github.com/user-attachments/assets/b3b766de-be70-4161-b9ca-8aae9330b5f2" /> </details>
1 parent f4c3523 commit b46ae2f

File tree

6 files changed

+627
-8
lines changed

6 files changed

+627
-8
lines changed

.changeset/sharp-phones-travel.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@hyperdx/common-utils": patch
3+
"@hyperdx/app": patch
4+
---
5+
6+
fix: Fix sidebar when selecting JSON property

packages/app/src/hooks/useRowWhere.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function processRowToWhereClause(
6666

6767
// Currently we can't distinguish null or 'null'
6868
if (value === 'null') {
69-
return SqlString.format(`isNull(??)`, [column]);
69+
return SqlString.format(`isNull(??)`, [valueExpr]);
7070
}
7171
if (value.length > 1000 || column.length > 1000) {
7272
console.warn('Search value/object key too large.');

packages/common-utils/src/__tests__/clickhouse.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,27 @@ describe('chSqlToAliasMap - alias unit test', () => {
200200
};
201201
expect(res).toEqual(aliasMap);
202202
});
203+
204+
it('Alias, with JSON expressions', () => {
205+
const chSqlInput: ChSql = {
206+
sql: "SELECT Timestamp as ts,ResourceAttributes.service.name as service,toStartOfDay(LogAttributes.start.`time`) as start_time,Body,TimestampTime,ServiceName,TimestampTime FROM {HYPERDX_PARAM_1544803905:Identifier}.{HYPERDX_PARAM_129845054:Identifier} WHERE (TimestampTime >= fromUnixTimestamp64Milli({HYPERDX_PARAM_1456399765:Int64}) AND TimestampTime <= fromUnixTimestamp64Milli({HYPERDX_PARAM_1719057412:Int64})) AND (`ResourceAttributes`.`service`.`name` = 'serviceName') ORDER BY TimestampTime DESC LIMIT {HYPERDX_PARAM_49586:Int32} OFFSET {HYPERDX_PARAM_48:Int32}",
207+
params: {
208+
HYPERDX_PARAM_1544803905: 'default',
209+
HYPERDX_PARAM_129845054: 'otel_logs',
210+
HYPERDX_PARAM_1456399765: 1743038742000,
211+
HYPERDX_PARAM_1719057412: 1743040542000,
212+
HYPERDX_PARAM_49586: 200,
213+
HYPERDX_PARAM_48: 0,
214+
},
215+
};
216+
const res = chSqlToAliasMap(chSqlInput);
217+
const aliasMap = {
218+
ts: 'Timestamp',
219+
service: 'ResourceAttributes.service.name',
220+
start_time: 'toStartOfDay(LogAttributes.start.`time`)',
221+
};
222+
expect(res).toEqual(aliasMap);
223+
});
203224
});
204225

205226
describe('computeRatio', () => {

0 commit comments

Comments
 (0)