Skip to content

Commit 8ad9a2f

Browse files
authored
Merge pull request #1917 from Dragonliu2018/lzl/feat/support_doris_server_species
feat: support doris server specie
2 parents a467d0a + 9d32067 commit 8ad9a2f

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Documentation: [https://mycli.net/docs](https://mycli.net/docs)
1010
![Completion](doc/screenshots/tables.png)
1111
![CompletionGif](doc/screenshots/main.gif)
1212

13-
Mycli is compatible with MySQL, MariaDB, Percona, and TiDB.
13+
Mycli is compatible with MySQL, MariaDB, Percona, TiDB, and Doris.
1414

1515
Postgres Equivalent: [https://pgcli.com](https://pgcli.com)
1616

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Upcoming (TBD)
22
==============
33

4+
Features
5+
--------
6+
* Detect Apache Doris and display its real version instead of the MySQL-compat placeholder.
7+
48
Bug Fixes
59
---------
610
* Keep completion-menu Escape cancellation eager only in Vi mode so Emacs Alt-key bindings keep working while completions are open.

mycli/sqlexecute.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class ServerSpecies(enum.Enum):
3939
MariaDB = "MariaDB"
4040
Percona = "Percona"
4141
TiDB = "TiDB"
42+
Doris = "Doris"
4243
Unknown = "Unknown"
4344

4445

@@ -365,7 +366,38 @@ def connect(
365366
# retrieve connection id (skip in sandbox mode as queries will fail)
366367
if not self.sandbox_mode:
367368
self.reset_connection_id()
368-
self.server_info = ServerInfo.from_version_string(conn.server_version) # type: ignore[attr-defined]
369+
server_info = ServerInfo.from_version_string(conn.server_version) # type: ignore[attr-defined]
370+
if server_info.species == ServerSpecies.MySQL:
371+
if (doris_version := self._probe_doris_version()) is not None:
372+
server_info = ServerInfo(ServerSpecies.Doris, doris_version)
373+
self.server_info = server_info
374+
375+
def _probe_doris_version(self) -> str | None:
376+
"""Query the server to check if it is Doris. Returns the Doris version string
377+
(e.g. '2.1.7') if confirmed, or None if the server is not Doris."""
378+
if self.sandbox_mode or self.conn is None:
379+
return None
380+
try:
381+
with self.conn.cursor() as cur:
382+
cur.execute("SELECT @@version_comment, @@version")
383+
row = cur.fetchone()
384+
if not row:
385+
return None
386+
version_comment = str(row[0] or "")
387+
version = str(row[1] or "")
388+
if "doris" not in version_comment.lower() and "doris" not in version.lower():
389+
return None
390+
# Prefer @@version_comment which usually carries the real Doris version string
391+
# (e.g. "doris-2.1.7-rc01"), then fall back to @@version.
392+
for candidate in (version_comment, version):
393+
ver_match = re.search(r"([0-9]+\.[0-9]+\.[0-9]+)", candidate)
394+
if ver_match:
395+
return ver_match.group(1)
396+
# Doris confirmed but couldn't parse a version number
397+
return ""
398+
except Exception as e:
399+
_logger.debug("Doris detection failed: %s", e)
400+
return None
369401

370402
def run(self, statement: str) -> Generator[SQLResult, None, None]:
371403
"""Execute the sql in the database and return the results."""

0 commit comments

Comments
 (0)