@@ -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