Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
public class JdbcMySQLConnectorClient extends JdbcConnectorClient {

private static final Logger LOG = LogManager.getLogger(JdbcMySQLConnectorClient.class);
private static final String APACHE_DORIS_SERVER_IDENTITY = "apache_doris";

private final boolean convertDateToNull;
private boolean isDoris = false;
Expand Down Expand Up @@ -76,10 +77,15 @@ private void detectDoris() {
try {
conn = getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery("SHOW VARIABLES LIKE 'version_comment'");
rs = stmt.executeQuery("SHOW VARIABLES LIKE 'server_identity'");
if (rs.next()) {
String versionComment = rs.getString("Value");
isDoris = isDorisCompatibleVersionComment(versionComment);
isDoris = isDorisServerIdentity(rs.getString("Value"));
} else {
closeResources(rs);
rs = stmt.executeQuery("SHOW VARIABLES LIKE 'version_comment'");
if (rs.next()) {
isDoris = isDorisCompatibleVersionComment(rs.getString("Value"));
}
}
} catch (Exception e) {
LOG.warn("Failed to detect if remote MySQL is Doris: {}", e.getMessage());
Expand All @@ -88,14 +94,20 @@ private void detectDoris() {
}
}

static boolean isDorisServerIdentity(String serverIdentity) {
return APACHE_DORIS_SERVER_IDENTITY.equalsIgnoreCase(serverIdentity);
}

static boolean isDorisCompatibleVersionComment(String versionComment) {
if (versionComment == null || versionComment.isEmpty()) {
return false;
}
String lowerVersionComment = versionComment.toLowerCase(Locale.ROOT);
// Enterprise releases can omit the optional "(Cloud Mode)" suffix.
return lowerVersionComment.contains("doris")
|| lowerVersionComment.contains("selectdb")
|| lowerVersionComment.contains("velodb")
|| lowerVersionComment.contains("enterprise version enterprise-")
|| (lowerVersionComment.contains("enterprise version")
&& lowerVersionComment.contains("cloud mode"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@

public class JdbcMySQLConnectorClientTest {

@Test
void testIsDorisServerIdentity() {
Assertions.assertTrue(JdbcMySQLConnectorClient.isDorisServerIdentity("apache_doris"));
Assertions.assertTrue(JdbcMySQLConnectorClient.isDorisServerIdentity("APACHE_DORIS"));
Assertions.assertFalse(JdbcMySQLConnectorClient.isDorisServerIdentity("mysql"));
Assertions.assertFalse(JdbcMySQLConnectorClient.isDorisServerIdentity(null));
}

@Test
void testIsDorisCompatibleVersionComment() {
Assertions.assertTrue(JdbcMySQLConnectorClient.isDorisCompatibleVersionComment(
Expand All @@ -32,6 +40,8 @@ void testIsDorisCompatibleVersionComment() {
"VeloDB version 2.1.0"));
Assertions.assertTrue(JdbcMySQLConnectorClient.isDorisCompatibleVersionComment(
"enterprise version enterprise-4.0.5-rc01-0724569463d (Cloud Mode)"));
Assertions.assertTrue(JdbcMySQLConnectorClient.isDorisCompatibleVersionComment(
"enterprise version enterprise-current"));

Assertions.assertFalse(JdbcMySQLConnectorClient.isDorisCompatibleVersionComment(
"MySQL Community Server - GPL"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

public class JdbcMySQLClient extends JdbcClient {

private static final String APACHE_DORIS_SERVER_IDENTITY = "apache_doris";

private boolean convertDateToNull = false;
private boolean isDoris = false;

Expand All @@ -57,10 +59,15 @@ protected JdbcMySQLClient(JdbcClientConfig jdbcClientConfig) {
try {
conn = super.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery("SHOW VARIABLES LIKE 'version_comment'");
rs = stmt.executeQuery("SHOW VARIABLES LIKE 'server_identity'");
if (rs.next()) {
String versionComment = rs.getString("Value");
isDoris = isDorisCompatibleVersionComment(versionComment);
isDoris = isDorisServerIdentity(rs.getString("Value"));
} else {
close(rs);
rs = stmt.executeQuery("SHOW VARIABLES LIKE 'version_comment'");
if (rs.next()) {
isDoris = isDorisCompatibleVersionComment(rs.getString("Value"));
}
}
} catch (SQLException | JdbcClientException e) {
closeClient();
Expand All @@ -76,14 +83,20 @@ protected JdbcMySQLClient(JdbcClientConfig jdbcClientConfig, String dbType) {
this.dbType = dbType;
}

static boolean isDorisServerIdentity(String serverIdentity) {
return APACHE_DORIS_SERVER_IDENTITY.equalsIgnoreCase(serverIdentity);
}

static boolean isDorisCompatibleVersionComment(String versionComment) {
if (Strings.isNullOrEmpty(versionComment)) {
return false;
}
String lowerVersionComment = versionComment.toLowerCase(Locale.ROOT);
// Enterprise releases can omit the optional "(Cloud Mode)" suffix.
return lowerVersionComment.contains("doris")
|| lowerVersionComment.contains("selectdb")
|| lowerVersionComment.contains("velodb")
|| lowerVersionComment.contains("enterprise version enterprise-")
|| (lowerVersionComment.contains("enterprise version")
&& lowerVersionComment.contains("cloud mode"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ public class SessionVariable implements Serializable, Writable {
public static final String SQL_SAFE_UPDATES = "sql_safe_updates";
public static final String NET_BUFFER_LENGTH = "net_buffer_length";
public static final String HAVE_QUERY_CACHE = "have_query_cache";
public static final String SERVER_IDENTITY = "server_identity";
public static final String APACHE_DORIS_SERVER_IDENTITY = "apache_doris";
// mem limit can't smaller than bufferpool's default page size
public static final int MIN_EXEC_MEM_LIMIT = 2097152;
public static final String BATCH_SIZE = "batch_size";
Expand Down Expand Up @@ -1385,6 +1387,9 @@ public void checkQuerySlotCount(String slotCnt) {
@VarAttrDef.VarAttr(name = HAVE_QUERY_CACHE, flag = VarAttrDef.READ_ONLY)
public boolean haveQueryCache = false;

@VarAttrDef.VarAttr(name = SERVER_IDENTITY, flag = VarAttrDef.READ_ONLY)
public String serverIdentity = APACHE_DORIS_SERVER_IDENTITY;

// 8192 minus 16 + 16 bytes padding that in padding pod array.
// This remains the row cap for output blocks even when adaptive byte budgeting is enabled.
@VarAttrDef.VarAttr(name = BATCH_SIZE, fuzzy = true, checker = "checkBatchSize", needForward = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,23 @@

public class JdbcMySQLClientTest {

@Test
public void testIsDorisServerIdentity() {
Assertions.assertTrue(JdbcMySQLClient.isDorisServerIdentity("apache_doris"));
Assertions.assertTrue(JdbcMySQLClient.isDorisServerIdentity("APACHE_DORIS"));
Assertions.assertFalse(JdbcMySQLClient.isDorisServerIdentity("mysql"));
Assertions.assertFalse(JdbcMySQLClient.isDorisServerIdentity(null));
}

@Test
public void testIsDorisCompatibleVersionComment() {
Assertions.assertTrue(JdbcMySQLClient.isDorisCompatibleVersionComment("Apache Doris version 3.1.0"));
Assertions.assertTrue(JdbcMySQLClient.isDorisCompatibleVersionComment("SelectDB Cloud version 4.0.5"));
Assertions.assertTrue(JdbcMySQLClient.isDorisCompatibleVersionComment("VeloDB version 2.1.0"));
Assertions.assertTrue(JdbcMySQLClient.isDorisCompatibleVersionComment(
"enterprise version enterprise-4.0.5-rc01-0724569463d (Cloud Mode)"));
Assertions.assertTrue(JdbcMySQLClient.isDorisCompatibleVersionComment(
"enterprise version enterprise-current"));

Assertions.assertFalse(JdbcMySQLClient.isDorisCompatibleVersionComment("MySQL Community Server - GPL"));
Assertions.assertFalse(JdbcMySQLClient.isDorisCompatibleVersionComment(""));
Expand Down
Loading