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/fuzzy-knives-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hyperdx/common-utils": patch
---

fix: Skip rendering empty aggConditions
Comment thread
greptile-apps[bot] marked this conversation as resolved.
60 changes: 60 additions & 0 deletions packages/common-utils/src/__tests__/queryParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2121,6 +2121,66 @@ describe('CustomSchemaSQLSerializerV2 - Array and Nested Fields', () => {
);
});

describe('genEnglishExplanation', () => {
const metadata = getMetadata(
new ClickhouseClient({ host: 'http://localhost:8123' }),
);
metadata.getColumn = jest.fn().mockImplementation(async () => undefined);
metadata.getMaterializedColumnsLookupTable = jest
.fn()
.mockImplementation(async () => new Map());

const databaseName = 'testName';
const tableName = 'testTable';
const connectionId = 'testId';
const query = 'bar';

it('serializes to english when table, database, and connection are present', async () => {
const actual = await genEnglishExplanation({
query,
tableConnection: { tableName, databaseName, connectionId },
metadata,
});
expect(actual).toBe('event has whole word bar');
});

it('falls back to the raw message when tableName is missing', async () => {
const actual = await genEnglishExplanation({
query,
tableConnection: { tableName: '', databaseName, connectionId },
metadata,
});
expect(actual).toBe(`Message containing ${query}`);
});

it('falls back to the raw message when databaseName is missing', async () => {
const actual = await genEnglishExplanation({
query,
tableConnection: { tableName, databaseName: '', connectionId },
metadata,
});
expect(actual).toBe(`Message containing ${query}`);
});

it('falls back to the raw message when connectionId is missing', async () => {
const actual = await genEnglishExplanation({
query,
tableConnection: { tableName, databaseName, connectionId: '' },
metadata,
});
expect(actual).toBe(`Message containing ${query}`);
});

it('falls back to the raw message when all table connection fields are missing', async () => {
const actual = await genEnglishExplanation({
query,
tableConnection: { tableName: '', databaseName: '', connectionId: '' },
metadata,
});
expect(actual).toBe(`Message containing ${query}`);
});
});

describe('parseKvItemsExpression', () => {
it('parses standard KV items expression', () => {
expect(
Expand Down
26 changes: 14 additions & 12 deletions packages/common-utils/src/core/renderChartConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,18 +691,20 @@ async function renderSelectList(

const selectsSQL = await Promise.all(
selectList.map(async select => {
const whereClause = await renderWhereExpression({
condition: select.aggCondition ?? '',
from: chartConfig.from,
language: select.aggConditionLanguage ?? 'lucene',
implicitColumnExpression: chartConfig.implicitColumnExpression,
bodyExpression: chartConfig.bodyExpression,
useTextIndexForImplicitColumn:
chartConfig.useTextIndexForImplicitColumn,
metadata,
connectionId: chartConfig.connection,
with: chartConfig.with,
});
const whereClause = isNonEmptyWhereExpr(select.aggCondition)
? await renderWhereExpression({
condition: select.aggCondition ?? '',
Comment thread
greptile-apps[bot] marked this conversation as resolved.
from: chartConfig.from,
language: select.aggConditionLanguage ?? 'lucene',
implicitColumnExpression: chartConfig.implicitColumnExpression,
bodyExpression: chartConfig.bodyExpression,
useTextIndexForImplicitColumn:
chartConfig.useTextIndexForImplicitColumn,
metadata,
connectionId: chartConfig.connection,
with: chartConfig.with,
})
: chSql``;

let expr: ChSql;
if (select.aggFn == null) {
Expand Down
2 changes: 1 addition & 1 deletion packages/common-utils/src/queryParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2022,7 +2022,7 @@ export async function genEnglishExplanation({
const { tableName, databaseName, connectionId } = tableConnection;
const parsedQ = parse(query);

if (parsedQ) {
if (parsedQ && tableName && databaseName && connectionId) {
const serializer = new EnglishSerializer({
metadata,
tableName,
Expand Down
Loading