Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clean-waves-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hyperdx/app": patch
---

fix delimited column identifier for dynamic fields
26 changes: 23 additions & 3 deletions packages/app/src/hooks/__tests__/useRowWhere.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ describe('processRowToWhereClause', () => {
const row = { dynamic_field: '"quoted_value"' };
const result = processRowToWhereClause(row, columnMap);

expect(result).toBe("toString(dynamic_field)='quoted_value'");
expect(result).toBe("toString(`dynamic_field`)='quoted_value'");
});

it('should handle Dynamic columns with escaped values', () => {
Expand All @@ -189,10 +189,30 @@ describe('processRowToWhereClause', () => {
],
]);

const row = { dynamic_field: '{\\"took\\":7, not a valid json' };
const row = { dynamic_field: '{\\"took\\":7, this ins\'t a valid json' };
const result = processRowToWhereClause(row, columnMap);
expect(result).toBe(
'toString(dynamic_field)=\'{\\"took\\":7, not a valid json\'',
"toString(`dynamic_field`)='{\\\"took\\\":7, this ins't a valid json'",
);
});

it('should handle Dynamic columns with delimited identifier', () => {
const columnMap = new Map([
[
'dynamic_field.nested.needs\\toBeEscaped',
{
name: 'dynamic_field.nested\\ToBeEscaped',
type: 'Dynamic',
valueExpr: 'dynamic_field.nested.needs\\ToBeEscaped',
jsType: JSDataType.Dynamic,
},
],
]);

const row = { 'dynamic_field.nested.needs\\toBeEscaped': 'some string' };
const result = processRowToWhereClause(row, columnMap);
expect(result).toBe(
`toString(\`dynamic_field\`.\`nested\`.\`needs\\ToBeEscaped\`)='some string'`,
);
});

Expand Down
14 changes: 6 additions & 8 deletions packages/app/src/hooks/useRowWhere.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,19 @@ export function processRowToWhereClause(
if (value === 'null') {
return SqlString.format(`isNull(??)`, [column]);
}
if (value.length > 1000 || column.length > 1000) {
console.warn('Search value/object key too large.');
}
// TODO: update when JSON type have new version
// will not work for array/object dyanmic data

// escaped strings needs raw, becuase sqlString will add another layer of escaping
// data other than array/object will alwayas return with dobule quote(because of CH)
// remove dobule qoute to search correctly
return SqlString.format(`toString(?)='?'`, [
SqlString.raw(valueExpr),
// remove double quotes if present and escape single quotes
return SqlString.format(`toString(??)='?'`, [
valueExpr,
SqlString.raw(
value[0] === '"' && value[value.length - 1] === '"'
(value[0] === '"' && value[value.length - 1] === '"'
? value.slice(1, -1)
: value,
: value
).replace(/'/g, "\\'"),
),
]);
default:
Expand Down