25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(kyuubi): use engine identifier quote for connect database
lxk95526a579ba7c5e
diff --git a/agents/drivers/hive-go/config.go b/agents/drivers/hive-go/config.goindex debc0d2e08..f4df274adf 100644--- a/agents/drivers/hive-go/config.go+++ b/agents/drivers/hive-go/config.go@@ -436,6 +436,7 @@ func parseHiveAssignments(raw string, lowercaseKeys bool) map[string]string {if decoded, err := url.QueryUnescape(key); err == nil {key = decoded}+ key = strings.TrimLeft(strings.TrimSpace(key), "?#")if lowercaseKeys {key = strings.ToLower(key)}@@ -691,22 +692,27 @@ func applyHiveParameters(config *connectionConfig, values, hiveConfs map[string]func applyOpenSessionVariables(config *connectionConfig, values, hiveConfs, hiveVars map[string]string) {config.HiveConfiguration["set:hiveconf:"+resultSetUniqueColumnNames] = "false"for key, value := range values {- lowerKey := strings.ToLower(key)+ cleanKey := strings.TrimPrefix(key, "#")+ lowerKey := strings.ToLower(cleanKey)switch {case strings.HasPrefix(lowerKey, "hiveconf:"):- config.HiveConfiguration["set:hiveconf:"+canonicalHiveConfKey(key[len("hiveconf:"):])] = value+ config.HiveConfiguration["set:hiveconf:"+canonicalHiveConfKey(cleanKey[len("hiveconf:"):])] = valuecase strings.HasPrefix(lowerKey, "hivevar:"):- config.HiveConfiguration["set:hivevar:"+key[len("hivevar:"):]] = value+ config.HiveConfiguration["set:hivevar:"+cleanKey[len("hivevar:"):]] = value+ case strings.HasPrefix(lowerKey, "kyuubi."):+ config.HiveConfiguration["set:hivevar:"+cleanKey] = value}}for key, value := range hiveConfs {- if strings.EqualFold(key, "hive.server2.transport.mode") || strings.EqualFold(key, "hive.server2.thrift.http.path") {+ cleanKey := strings.TrimPrefix(key, "#")+ if strings.EqualFold(cleanKey, "hive.server2.transport.mode") || strings.EqualFold(cleanKey, "hive.server2.thrift.http.path") {continue}- config.HiveConfiguration["set:hiveconf:"+canonicalHiveConfKey(key)] = value+ config.HiveConfiguration["set:hiveconf:"+canonicalHiveConfKey(cleanKey)] = value}for key, value := range hiveVars {- config.HiveConfiguration["set:hivevar:"+key] = value+ cleanKey := strings.TrimPrefix(key, "#")+ config.HiveConfiguration["set:hivevar:"+cleanKey] = value}if proxyUser := firstNonEmpty(parameter(values, "proxyuser"), parameter(values, "hive.server2.proxy.user")); proxyUser != "" {config.HiveConfiguration["hive.server2.proxy.user"] = proxyUser@@ -753,11 +759,14 @@ func openSessionConfigurationValue(values map[string]string, key string) string// Hive JDBC-style URL fragments are sent as hive variables, while values// after '?' are sent as hive confs. Kyuubi strips either prefix before it// resolves session-scoped settings such as kyuubi.engine.type.- for _, wanted := range []string{"set:hivevar:" + key, "set:hiveconf:" + key, key} {- for candidate, value := range values {- if strings.EqualFold(strings.TrimSpace(candidate), wanted) {- return value- }+ normalizedKey := strings.ToLower(strings.TrimPrefix(strings.TrimSpace(key), "#"))+ for candidate, value := range values {+ candidateKey := strings.ToLower(strings.TrimSpace(candidate))+ candidateKey = strings.TrimPrefix(candidateKey, "set:hivevar:")+ candidateKey = strings.TrimPrefix(candidateKey, "set:hiveconf:")+ candidateKey = strings.TrimPrefix(candidateKey, "#")+ if candidateKey == normalizedKey {+ return value}}return ""diff --git a/agents/drivers/hive-go/config_test.go b/agents/drivers/hive-go/config_test.goindex 868600ffc5..416138731b 100644--- a/agents/drivers/hive-go/config_test.go+++ b/agents/drivers/hive-go/config_test.go@@ -432,6 +432,36 @@ func TestKyuubiIdentifierQuoteFollowsPreservedEngineType(t *testing.T) {configuration: "set:hiveconf:kyuubi.engine.type",identifierQuote: trinoIdentifierQuote,},+ {+ name: "URL param without hash selects Trino",+ params: connectParams{+ Host: "kyuubi.example.com",+ DatabaseType: "kyuubi",+ URLParams: "kyuubi.engine.type=TRINO",+ },+ configuration: "set:hivevar:kyuubi.engine.type",+ identifierQuote: trinoIdentifierQuote,+ },+ {+ name: "Semicolon with hash selects Trino",+ params: connectParams{+ Host: "kyuubi.example.com",+ DatabaseType: "kyuubi",+ URLParams: ";#kyuubi.engine.type=trino",+ },+ configuration: "set:hivevar:kyuubi.engine.type",+ identifierQuote: trinoIdentifierQuote,+ },+ {+ name: "Session params with auth selects Trino",+ params: connectParams{+ Host: "kyuubi.example.com",+ DatabaseType: "kyuubi",+ URLParams: "auth=NOSASL;kyuubi.engine.type=TRINO",+ },+ configuration: "set:hivevar:kyuubi.engine.type",+ identifierQuote: trinoIdentifierQuote,+ },{name: "Kyuubi Spark keeps Hive quote",params: connectParams{diff --git a/agents/drivers/hive-go/connector.go b/agents/drivers/hive-go/connector.goindex ce745c1827..8c4529713c 100644--- a/agents/drivers/hive-go/connector.go+++ b/agents/drivers/hive-go/connector.go@@ -90,6 +90,7 @@ func newDiscoveryConnector(config connectionConfig) *discoveryConnector {BrowserResponseTimeout: config.BrowserResponseTimeout,BrowserDisableSSLCheck: config.BrowserDisableSSLCheck,WaitForNonQueryCompletion: waitsForNonQueryCompletion(config.DatabaseType),+ IdentifierQuote: config.identifierQuote(),})},driver: &gohive.Driver{},diff --git a/agents/go-common/gohive/connector.go b/agents/go-common/gohive/connector.goindex 03d61d9734..cc6c758d7d 100644--- a/agents/go-common/gohive/connector.go+++ b/agents/go-common/gohive/connector.go@@ -50,6 +50,7 @@ type Config struct {BrowserResponseTimeout time.DurationBrowserDisableSSLCheck boolWaitForNonQueryCompletion bool+ IdentifierQuote string}var _ driver.Connector = (*HiveConnector)(nil)@@ -112,6 +113,7 @@ func (c *HiveConnector) Connect(ctx context.Context) (driver.Conn, error) {connCfg.BrowserResponseTimeout = c.cfg.BrowserResponseTimeoutconnCfg.BrowserDisableSSLCheck = c.cfg.BrowserDisableSSLCheckconnCfg.WaitForNonQueryCompletion = c.cfg.WaitForNonQueryCompletion+ connCfg.IdentifierQuote = c.cfg.IdentifierQuote// Fallback: build TLS config from cert/key files if TLSConfig not provided directlyif connCfg.TLSConfig == nil {diff --git a/agents/go-common/gohive/hive.go b/agents/go-common/gohive/hive.goindex ca82c53e9c..b128b7f031 100644--- a/agents/go-common/gohive/hive.go+++ b/agents/go-common/gohive/hive.go@@ -272,11 +272,28 @@ type connectConfiguration struct {BrowserResponseTimeout time.DurationBrowserDisableSSLCheck boolWaitForNonQueryCompletion bool+ IdentifierQuote string// Maximum length of the data in bytes. Used for SASL.MaxSize uint32MaxMessageSize int32}+func (c *connectConfiguration) identifierQuote() string {+ if c != nil && c.IdentifierQuote != "" {+ return c.IdentifierQuote+ }+ if c != nil && c.HiveConfiguration != nil {+ for k, v := range c.HiveConfiguration {+ cleanKey := strings.TrimPrefix(strings.TrimPrefix(strings.TrimSpace(k), "set:hivevar:"), "set:hiveconf:")+ cleanKey = strings.TrimPrefix(cleanKey, "#")+ if strings.EqualFold(cleanKey, "kyuubi.engine.type") && strings.EqualFold(strings.TrimSpace(v), "TRINO") {+ return "\""+ }+ }+ }+ return "`"+}+// newConnectConfiguration returns a connect configuration, all with empty fieldsfunc newConnectConfiguration() *connectConfiguration {return &connectConfiguration{@@ -652,7 +669,7 @@ func innerConnect(ctx context.Context, host string, port int, auth string,if configuration.Database != "" {cursor := conn.cursor()defer cursor.close(ctx)- cursor.exec(ctx, "USE "+quoteHiveIdentifier(configuration.Database))+ cursor.exec(ctx, "USE "+quoteIdentifier(configuration.Database, configuration.identifierQuote()))if cursor.Err != nil {return nil, cursor.Err}@@ -1693,7 +1710,14 @@ func usesHTTPBasicAuth(auth string) bool {}func quoteHiveIdentifier(value string) string {- return "`" + strings.ReplaceAll(value, "`", "``") + "`"+ return quoteIdentifier(value, "`")+}++func quoteIdentifier(value, quote string) string {+ if quote == "" {+ quote = "`"+ }+ return quote + strings.ReplaceAll(value, quote, quote+quote) + quote}var DEFAULT_SQL_STATE = ""diff --git a/agents/go-common/gohive/http_auth_test.go b/agents/go-common/gohive/http_auth_test.goindex c57f5a90e0..9d35083772 100644--- a/agents/go-common/gohive/http_auth_test.go+++ b/agents/go-common/gohive/http_auth_test.go@@ -386,3 +386,32 @@ func TestQuoteHiveIdentifierEscapesBackticks(t *testing.T) {t.Fatalf("unexpected quoted identifier: %q", value)}}++func TestQuoteIdentifierWithCustomQuote(t *testing.T) {+ if value := quoteIdentifier(`analytics"prod`, `"`); value != `"analytics""prod"` {+ t.Fatalf("unexpected quoted identifier: %q", value)+ }+ if value := quoteIdentifier("analytics`prod", ""); value != "`analytics``prod`" {+ t.Fatalf("unexpected default quoted identifier: %q", value)+ }+}++func TestConnectConfigurationIdentifierQuote(t *testing.T) {+ cfg := &connectConfiguration{IdentifierQuote: `"`}+ if q := cfg.identifierQuote(); q != `"` {+ t.Fatalf("expected quote %q, got %q", `"`, q)+ }+ cfg = &connectConfiguration{+ HiveConfiguration: map[string]string{"set:hivevar:kyuubi.engine.type": "TRINO"},+ }+ if q := cfg.identifierQuote(); q != `"` {+ t.Fatalf("expected auto-detected Trino quote %q, got %q", `"`, q)+ }+ cfg = &connectConfiguration{+ HiveConfiguration: map[string]string{"set:hivevar:kyuubi.engine.type": "SPARK_SQL"},+ }+ if q := cfg.identifierQuote(); q != "`" {+ t.Fatalf("expected default quote %q, got %q", "`", q)+ }+}+