fix(sql): preserve ClickHouse lambda arrows
This commit is contained in:
1 parent
c80313eed2
commit
75652b10fe
2 files changed
+22
-1
No files matched your search
@@ -14,6 +14,23 @@ describe("sqlFormatter", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("preserves ClickHouse lambda arrows when formatting issue #3573 SQL", async () => {
|
||||||
|
const sql = `
|
||||||
|
WITH industry_code_donghua_id_RYCzfD AS (SELECT id
|
||||||
|
FROM cd.industry_code_donghua
|
||||||
|
WHERE cd.industry_code_donghua.code IN ('INB0709', 'INB0004'))
|
||||||
|
SELECT id,ent_short,arrayMap(x->dictGet(cd.industry_donghua_dict,'name',x),prefer_industry) as prefer_industry_name,org_type,company_id,arrayCount(\`investment.be_company_id\` -> 1, \`investment.be_company_id\`) as be_company_count
|
||||||
|
FROM search_donghua.investor
|
||||||
|
WHERE arrayExists(x -> x IN industry_code_donghua_id_RYCzfD, prefer_industry)
|
||||||
|
ORDER BY be_company_count DESC,id ASC
|
||||||
|
LIMIT 0,10
|
||||||
|
`;
|
||||||
|
|
||||||
|
const formatted = await formatSqlText(sql, sqlFormatDialectForDbType("clickhouse"));
|
||||||
|
|
||||||
|
expect(formatted).toContain("x -> dictGet");
|
||||||
|
expect(formatted).not.toContain("- >");
|
||||||
|
});
|
||||||
it("preserves DBX brace placeholders in generic and MySQL SQL", async () => {
|
it("preserves DBX brace placeholders in generic and MySQL SQL", async () => {
|
||||||
const sql = "SELECT ${x} AS shell_value, #{x} AS mybatis_value, '${date}' AS quoted_value";
|
const sql = "SELECT ${x} AS shell_value, #{x} AS mybatis_value, '${date}' AS quoted_value";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { DEFAULT_SQL_FORMATTER_SETTINGS, sqlFormatterOptions, type SqlFormatterSettings } from "@/lib/sql/sqlFormatterConfig";
|
import { DEFAULT_SQL_FORMATTER_SETTINGS, sqlFormatterOptions, type SqlFormatterSettings } from "@/lib/sql/sqlFormatterConfig";
|
||||||
|
|
||||||
export type SqlFormatDialect = "mysql" | "postgres" | "sqlite" | "sqlserver" | "generic";
|
export type SqlFormatDialect = "mysql" | "postgres" | "sqlite" | "sqlserver" | "clickhouse" | "generic";
|
||||||
|
|
||||||
export const MAX_SQL_FORMAT_CHARS = 1_000_000;
|
export const MAX_SQL_FORMAT_CHARS = 1_000_000;
|
||||||
|
|
||||||
@@ -34,6 +34,8 @@ export function sqlFormatDialectForDbType(dbType: string | null | undefined): Sq
|
|||||||
return "sqlite";
|
return "sqlite";
|
||||||
case "sqlserver":
|
case "sqlserver":
|
||||||
return "sqlserver";
|
return "sqlserver";
|
||||||
|
case "clickhouse":
|
||||||
|
return "clickhouse";
|
||||||
default:
|
default:
|
||||||
return "generic";
|
return "generic";
|
||||||
}
|
}
|
||||||
@@ -49,6 +51,8 @@ function formatterLanguage(dialect: SqlFormatDialect) {
|
|||||||
return "sqlite";
|
return "sqlite";
|
||||||
case "sqlserver":
|
case "sqlserver":
|
||||||
return "transactsql";
|
return "transactsql";
|
||||||
|
case "clickhouse":
|
||||||
|
return "clickhouse";
|
||||||
default:
|
default:
|
||||||
return "sql";
|
return "sql";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user