feat(editor): add ClickHouse SQL highlighting
This commit is contained in:
+48
-1
@@ -3,7 +3,7 @@ import { readFileSync } from "node:fs";
|
||||
import { test } from "vitest";
|
||||
import * as langSql from "@codemirror/lang-sql";
|
||||
import { createDbxCodeMirrorSqlDialect } from "../../apps/desktop/src/lib/editor/codemirrorSqlDialect.ts";
|
||||
import { codeMirrorSqlDialect } from "../../apps/desktop/src/lib/database/jdbcDialect.ts";
|
||||
import { codeMirrorSqlDialect, codeMirrorSqlDialectForConnection } from "../../apps/desktop/src/lib/database/jdbcDialect.ts";
|
||||
import type { DatabaseType } from "../../apps/desktop/src/types/database.ts";
|
||||
|
||||
function hasKeyword(keywords: string | undefined, keyword: string): boolean {
|
||||
@@ -47,6 +47,53 @@ test("keeps DBX PostgreSQL procedural dialect extensions", () => {
|
||||
assert.equal(hasKeyword(dialect.spec.builtin, "TG_NAME"), true);
|
||||
});
|
||||
|
||||
test("maps ClickHouse connections to the dedicated editor syntax dialect", () => {
|
||||
assert.equal(codeMirrorSqlDialectForConnection({ db_type: "clickhouse" }), "clickhouse");
|
||||
assert.equal(
|
||||
codeMirrorSqlDialectForConnection({
|
||||
db_type: "jdbc",
|
||||
connection_string: "jdbc:clickhouse://127.0.0.1:8123/default",
|
||||
}),
|
||||
"clickhouse",
|
||||
);
|
||||
});
|
||||
|
||||
test("classifies ClickHouse-specific syntax", () => {
|
||||
const dialect = createDbxCodeMirrorSqlDialect(langSql, "clickhouse", "clickhouse");
|
||||
const sql = `
|
||||
CREATE TABLE events
|
||||
(
|
||||
id UInt64,
|
||||
created_at DateTime64(3),
|
||||
category LowCardinality(String),
|
||||
attributes Map(String, String)
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
PARTITION BY toYYYYMM(created_at)
|
||||
ORDER BY id
|
||||
TTL created_at + INTERVAL 30 DAY
|
||||
SETTINGS index_granularity = 8192;
|
||||
|
||||
SELECT uniqExact(id), argMax(category, created_at)
|
||||
FROM events
|
||||
PREWHERE created_at >= now() - INTERVAL 1 DAY
|
||||
ARRAY JOIN mapKeys(attributes) AS attribute_key
|
||||
LIMIT 10 BY category
|
||||
FORMAT JSONEachRow;
|
||||
`;
|
||||
|
||||
for (const keyword of ["SELECT", "FROM", "ENGINE", "PARTITION", "TTL", "SETTINGS", "PREWHERE", "FORMAT"]) {
|
||||
assert.ok(countParsedNodes(dialect, sql, "Keyword", keyword) >= 1, keyword);
|
||||
}
|
||||
for (const type of ["UInt64", "DateTime64", "LowCardinality", "Map"]) {
|
||||
assert.equal(countParsedNodes(dialect, sql, "Type", type), 1, type);
|
||||
}
|
||||
for (const builtin of ["toYYYYMM", "uniqExact", "argMax", "mapKeys"]) {
|
||||
assert.equal(countParsedNodes(dialect, sql, "Builtin", builtin), 1, builtin);
|
||||
}
|
||||
assert.equal(countParsedNodes(dialect, "--SELECT 1", "LineComment", "--SELECT 1"), 1);
|
||||
});
|
||||
|
||||
test("treats compact double-dash comments as comments in non-MySQL SQL dialects", () => {
|
||||
const databaseTypes: DatabaseType[] = [
|
||||
"oracle",
|
||||
|
||||
+10
@@ -29,6 +29,16 @@ test("infers JDBC dialect from driver profile", () => {
|
||||
);
|
||||
});
|
||||
|
||||
test("uses dedicated ClickHouse editor syntax for inferred JDBC connections", () => {
|
||||
const connection = {
|
||||
db_type: "jdbc" as const,
|
||||
connection_string: "jdbc:clickhouse://127.0.0.1:8123/default",
|
||||
};
|
||||
|
||||
assert.equal(inferJdbcDialect(connection), "clickhouse");
|
||||
assert.equal(codeMirrorSqlDialectForConnection(connection), "clickhouse");
|
||||
});
|
||||
|
||||
test("infers GaussDB-compatible JDBC connections as schema-aware", () => {
|
||||
const gaussdbConnection = {
|
||||
db_type: "jdbc" as const,
|
||||
|
||||
Reference in New Issue
Block a user