From b3c4c9a9127465117960dcb3115b378b248aa776 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Fri, 31 Jul 2026 22:50:46 +0800 Subject: [PATCH] fix(jdbc): detect Inceptor as Hive --- .../__tests__/database/jdbcDialect.spec.ts | 36 +++++++++++++++++++ apps/desktop/src/lib/database/jdbcDialect.ts | 5 +-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/lib/__tests__/database/jdbcDialect.spec.ts b/apps/desktop/src/lib/__tests__/database/jdbcDialect.spec.ts index 439ae34e50..018e16e189 100644 --- a/apps/desktop/src/lib/__tests__/database/jdbcDialect.spec.ts +++ b/apps/desktop/src/lib/__tests__/database/jdbcDialect.spec.ts @@ -139,6 +139,42 @@ describe("jdbc dialect inference", () => { expect(inferJdbcDialect(damengConnection)).toBe("dameng"); }); + + it("uses Hive tree and execution semantics for Inceptor JDBC metadata", () => { + const connection = { + db_type: "jdbc" as const, + connection_string: "jdbc:hive2://inceptor.example.com:10000/default", + database_info: { productName: "Apache Hive", driverName: "Inceptor JDBC 8.37.3" }, + }; + + expect(inferJdbcDialect(connection)).toBe("hive"); + expect(effectiveDatabaseTypeForConnection(connection)).toBe("hive"); + expect(connectionUsesDatabaseObjectTreeMode(connection)).toBe(false); + expect(connectionObjectTreeNodeSchema(connection, "CS")).toBe("CS"); + expect(connectionQueryExecutionSchema(connection, "CS", undefined, false)).toBe("CS"); + }); + + it.each([ + { driver_profile: "inceptor" }, + { driver_label: "Inceptor JDBC 8.37.3" }, + { jdbc_driver_class: "io.transwarp.inceptor.jdbc.InceptorDriver" }, + { jdbc_driver_paths: ["C:\\drivers\\InceptorJDBC.jar"] }, + { database_info: { driverName: "Inceptor JDBC 8.37.3" } }, + { database_info: { serverComment: "Transwarp Inceptor Server" } }, + ])("detects Inceptor from explicit JDBC identity %#", (identity) => { + expect(inferJdbcDialect({ db_type: "jdbc", ...identity })).toBe("hive"); + }); + + it("recognizes Apache Hive metadata without changing generic hive2 or MySQL inference", () => { + expect(inferJdbcDialect({ db_type: "jdbc", database_info: { productName: "Apache Hive" } })).toBe("hive"); + expect(inferJdbcDialect({ db_type: "jdbc", driver_label: "Kyuubi JDBC", connection_string: "jdbc:hive2://kyuubi.example.com/default" })).toBe("mysql"); + expect(inferJdbcDialect({ db_type: "jdbc", connection_string: "jdbc:hive2://hiveserver.example.com/default" })).toBe("mysql"); + expect(inferJdbcDialect({ db_type: "jdbc", connection_string: "jdbc:mysql://mysql.example.com/app" })).toBe("mysql"); + }); + + it("prefers explicit Kyuubi identity over Apache Hive product metadata", () => { + expect(inferJdbcDialect({ db_type: "jdbc", driver_label: "Kyuubi JDBC", database_info: { productName: "Apache Hive" } })).toBe("mysql"); + }); }); describe("GaussDB connection mode", () => { diff --git a/apps/desktop/src/lib/database/jdbcDialect.ts b/apps/desktop/src/lib/database/jdbcDialect.ts index d471843440..801e0e6563 100644 --- a/apps/desktop/src/lib/database/jdbcDialect.ts +++ b/apps/desktop/src/lib/database/jdbcDialect.ts @@ -18,8 +18,9 @@ const JDBC_DIALECT_MATCHERS: Array<{ type: DatabaseType; patterns: RegExp[] }> = { type: "starrocks", patterns: [/starrocks/i] }, { type: "doris", patterns: [/doris/i] }, { type: "goldendb", patterns: [/jdbc:goldendb:/i, /goldendb/i] }, - { type: "hive", patterns: [/org\.apache\.hive\.jdbc\.HiveDriver/i, /hive-jdbc/i] }, - { type: "mysql", patterns: [/jdbc:mysql:/i, /mysql/i, /mariadb/i, /kyuubi/i, /hive2/i] }, + { type: "mysql", patterns: [/kyuubi/i] }, + { type: "hive", patterns: [/inceptor/i, /\bapache\s+hive\b/i, /org\.apache\.hive\.jdbc\.HiveDriver/i, /hive-jdbc/i] }, + { type: "mysql", patterns: [/jdbc:mysql:/i, /mysql/i, /mariadb/i, /hive2/i] }, { type: "gaussdb", patterns: [/jdbc:gaussdb:/i, /com\.huawei\.gaussdb/i, /gaussdb/i] }, { type: "dameng", patterns: [/jdbc:dm:/i, /dm\.jdbc\.driver/i, /dameng/i] }, { type: "opengauss", patterns: [/jdbc:opengauss:/i, /org\.opengauss/i, /opengauss/i] },