fix: dashboard drilldown support to logs page, getting ` and query of unions not getting passed properly (#5525)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
	- Improved SQL query generation logic for drilldown functionality
	- Enhanced query construction to handle table aliases more effectively
	- Sanitized query strings by replacing backticks with double quotes

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
ktx-vaidehi
2025-01-01 18:34:07 +05:30
committed by GitHub
parent e75471562e
commit 3f2d63b79e
@@ -837,10 +837,18 @@ export default defineComponent({
if (!parser) {
await importSqlParser();
}
const ast = await parseQuery(originalQuery, parser);
if (!ast) return;
const tableAliases = ast.from
?.filter((fromEntry: any) => fromEntry.as)
.map((fromEntry: any) => fromEntry.as);
const aliasClause = tableAliases?.length
? ` AS ${tableAliases.join(", ")}`
: "";
const breakdownColumn = breakdown[0]?.column;
const breakdownValue = drilldownParams[0]?.seriesName;
const whereClause = buildWhereClause(
@@ -849,11 +857,13 @@ export default defineComponent({
breakdownValue,
);
const modifiedQuery =
let modifiedQuery =
drilldownData.data.logsMode === "auto"
? `SELECT * FROM "${streamName}" ${whereClause}`
? `SELECT * FROM "${streamName}"${aliasClause} ${whereClause}`
: drilldownData.data.logsQuery;
modifiedQuery = modifiedQuery.replace(/`/g, '"');
const encodedQuery: any = b64EncodeUnicode(modifiedQuery);
const pos = window.location.pathname.indexOf("/web/");