Skip to content

Commit

Permalink
[Improve][Connector-v2] Support mysql 8.1/8.2/8.3 for jdbc (apache#7530)
Browse files Browse the repository at this point in the history
  • Loading branch information
dailai authored Aug 30, 2024
1 parent 590f7d1 commit 657fe69
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/en/connector-v2/sink/Mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Support Mysql Version

- 5.5/5.6/5.7/8.0/8.4
- 5.5/5.6/5.7/8.0/8.1/8.2/8.3/8.4

## Support Those Engines

Expand Down
2 changes: 1 addition & 1 deletion docs/en/connector-v2/source/Mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Read external data source data through JDBC.

## Support Mysql Version

- 5.5/5.6/5.7/8.0/8.4
- 5.5/5.6/5.7/8.0/8.1/8.2/8.3/8.4

## Support Those Engines

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,27 @@
package org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.mysql;

public enum MySqlVersion {
V_5_5,
V_5_6,
V_5_7,
V_8,
V_8_4;
V_5_5("5.5"),
V_5_6("5.6"),
V_5_7("5.7"),
V_8("8.0"),
V_8_1("8.1"),
V_8_2("8.2"),
V_8_3("8.3"),
V_8_4("8.4");

private final String versionPrefix;

MySqlVersion(String versionPrefix) {
this.versionPrefix = versionPrefix;
}

public static MySqlVersion parse(String version) {
if (version != null) {
if (version.startsWith("5.5")) {
return V_5_5;
}
if (version.startsWith("5.6")) {
return V_5_6;
}
if (version.startsWith("5.7")) {
return V_5_7;
}
if (version.startsWith("8.0")) {
return V_8;
}
if (version.startsWith("8.4")) {
return V_8_4;
for (MySqlVersion mySqlVersion : values()) {
if (version.startsWith(mySqlVersion.versionPrefix)) {
return mySqlVersion;
}
}
}
throw new UnsupportedOperationException("Unsupported MySQL version: " + version);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.mysql;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class MysqlVersionTest {

@Test
public void testMysqlVersionParse() {
Assertions.assertEquals(MySqlVersion.V_5_5, MySqlVersion.parse("5.5.0"));
Assertions.assertEquals(MySqlVersion.V_5_5, MySqlVersion.parse("5.5.1"));
Assertions.assertEquals(MySqlVersion.V_5_5, MySqlVersion.parse("5.5.12"));

Assertions.assertEquals(MySqlVersion.V_5_6, MySqlVersion.parse("5.6.0"));
Assertions.assertEquals(MySqlVersion.V_5_6, MySqlVersion.parse("5.6.1"));
Assertions.assertEquals(MySqlVersion.V_5_6, MySqlVersion.parse("5.6.12"));

Assertions.assertEquals(MySqlVersion.V_5_7, MySqlVersion.parse("5.7.0"));
Assertions.assertEquals(MySqlVersion.V_5_7, MySqlVersion.parse("5.7.1"));
Assertions.assertEquals(MySqlVersion.V_5_7, MySqlVersion.parse("5.7.12"));

Assertions.assertEquals(MySqlVersion.V_8, MySqlVersion.parse("8.0.0"));
Assertions.assertEquals(MySqlVersion.V_8, MySqlVersion.parse("8.0.1"));
Assertions.assertEquals(MySqlVersion.V_8, MySqlVersion.parse("8.0.12"));

Assertions.assertEquals(MySqlVersion.V_8_1, MySqlVersion.parse("8.1.0"));
Assertions.assertEquals(MySqlVersion.V_8_1, MySqlVersion.parse("8.1.4"));
Assertions.assertEquals(MySqlVersion.V_8_1, MySqlVersion.parse("8.1.14"));

Assertions.assertEquals(MySqlVersion.V_8_2, MySqlVersion.parse("8.2.0"));
Assertions.assertEquals(MySqlVersion.V_8_2, MySqlVersion.parse("8.2.4"));
Assertions.assertEquals(MySqlVersion.V_8_2, MySqlVersion.parse("8.2.14"));

Assertions.assertEquals(MySqlVersion.V_8_3, MySqlVersion.parse("8.3.0"));
Assertions.assertEquals(MySqlVersion.V_8_3, MySqlVersion.parse("8.3.4"));
Assertions.assertEquals(MySqlVersion.V_8_3, MySqlVersion.parse("8.3.14"));

Assertions.assertEquals(MySqlVersion.V_8_4, MySqlVersion.parse("8.4.0"));
Assertions.assertEquals(MySqlVersion.V_8_4, MySqlVersion.parse("8.4.4"));
Assertions.assertEquals(MySqlVersion.V_8_4, MySqlVersion.parse("8.4.14"));
}
}

0 comments on commit 657fe69

Please sign in to comment.