Browse Source

Merge pull request #12 from alibaba/master

merge
rewerma 6 years ago
parent
commit
3e49e33f9f

+ 2 - 1
driver/src/main/java/com/alibaba/otter/canal/parse/driver/mysql/packets/MysqlGTIDSet.java

@@ -86,7 +86,8 @@ public class MysqlGTIDSet implements GTIDSet {
         if (gtidData == null || gtidData.length() < 1) {
         if (gtidData == null || gtidData.length() < 1) {
             m = new HashMap<String, UUIDSet>();
             m = new HashMap<String, UUIDSet>();
         } else {
         } else {
-            String[] uuidStrs = gtidData.split(",");
+            // 存在多个GTID时会有回车符
+            String[] uuidStrs = gtidData.replaceAll("\n", "").split(",");
             m = new HashMap<String, UUIDSet>(uuidStrs.length);
             m = new HashMap<String, UUIDSet>(uuidStrs.length);
             for (int i = 0; i < uuidStrs.length; i++) {
             for (int i = 0; i < uuidStrs.length; i++) {
                 UUIDSet uuidSet = UUIDSet.parse(uuidStrs[i]);
                 UUIDSet uuidSet = UUIDSet.parse(uuidStrs[i]);

+ 8 - 4
parse/src/test/java/com/alibaba/otter/canal/parse/inbound/mysql/tsdb/FastsqlSchemaTest.java

@@ -18,13 +18,17 @@ public class FastsqlSchemaTest {
     @Test
     @Test
     public void testSimple() throws FileNotFoundException, IOException {
     public void testSimple() throws FileNotFoundException, IOException {
         SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
         SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
-        String sql = "create table yushitai_test.card_record ( id bigint auto_increment) auto_increment=256 "
-                     + "; alter table yushitai_test.card_record add column customization_id bigint unsigned NOT NULL COMMENT 'TEST' ;"
-                     + "; rename table yushitai_test.card_record to yushitai_test._card_record_del;";
+        String sql = "create table yushitai_test.card_record ( id bigint auto_increment, name varchar(32) DEFAULT NULL) auto_increment=256 "
+                     + "alter table yushitai_test.card_record add index index_name(name) ;"
+                     + "alter table yushitai_test.card_record add index index_name(name) ;"
+                     + "alter table yushitai_test.card_record add Constraint pk_id PRIMARY KEY (id);"
+                     + "alter table yushitai_test.card_record add Constraint pk_id PRIMARY KEY (id);"
+                     + "alter table yushitai_test.card_record add Constraint UNIQUE index uk_name(name);"
+                     + "alter table yushitai_test.card_record add Constraint UNIQUE index uk_name(name);";
         repository.console(sql);
         repository.console(sql);
 
 
         repository.setDefaultSchema("yushitai_test");
         repository.setDefaultSchema("yushitai_test");
-        SchemaObject table = repository.findTable("_card_record_del");
+        SchemaObject table = repository.findTable("card_record");
         System.out.println(table.getStatement().toString());
         System.out.println(table.getStatement().toString());
     }
     }
 }
 }

+ 15 - 0
parse/src/test/java/com/alibaba/otter/canal/parse/inbound/mysql/tsdb/MemoryTableMeta_DDL_Test.java

@@ -37,4 +37,19 @@ public class MemoryTableMeta_DDL_Test {
         meta = memoryTableMeta.find("yushitai_test", "_card_record_gho");
         meta = memoryTableMeta.find("yushitai_test", "_card_record_gho");
         Assert.assertNull(meta);
         Assert.assertNull(meta);
     }
     }
+
+    @Test
+    public void test2() throws Throwable {
+        MemoryTableMeta memoryTableMeta = new MemoryTableMeta();
+        URL url = Thread.currentThread().getContextClassLoader().getResource("dummy.txt");
+        File dummyFile = new File(url.getFile());
+        File create = new File(dummyFile.getParent() + "/ddl", "ddl_test2.sql");
+        String sql = StringUtils.join(IOUtils.readLines(new FileInputStream(create)), "\n");
+        memoryTableMeta.apply(null, "test", sql, null);
+
+        TableMeta meta = memoryTableMeta.find("yushitai_test", "card_record");
+        System.out.println(meta);
+        Assert.assertEquals(meta.getFieldMetaByName("id").isKey(), true);
+        Assert.assertEquals(meta.getFieldMetaByName("name").isUnique(), true);
+    }
 }
 }

+ 8 - 0
parse/src/test/resources/ddl/ddl_test2.sql

@@ -0,0 +1,8 @@
+CREATE TABLE yushitai_test.card_record (
+	id bigint AUTO_INCREMENT,
+	name varchar(32) DEFAULT NULL,
+	alias varchar(32) DEFAULT NULL,
+	INDEX index_name(name),
+	CONSTRAINT pk_id PRIMARY KEY (id),
+	UNIQUE uk_name (name,alias)
+) AUTO_INCREMENT = 256

+ 2 - 2
pom.xml

@@ -99,7 +99,7 @@
         <java_source_version>1.7</java_source_version>
         <java_source_version>1.7</java_source_version>
         <java_target_version>1.7</java_target_version>
         <java_target_version>1.7</java_target_version>
         <file_encoding>UTF-8</file_encoding>
         <file_encoding>UTF-8</file_encoding>
-        <spring_version>3.2.9.RELEASE</spring_version>
+        <spring_version>3.2.18.RELEASE</spring_version>
     </properties>
     </properties>
 
 
     <modules>
     <modules>
@@ -247,7 +247,7 @@
             <dependency>
             <dependency>
                 <groupId>com.alibaba.fastsql</groupId>
                 <groupId>com.alibaba.fastsql</groupId>
                 <artifactId>fastsql</artifactId>
                 <artifactId>fastsql</artifactId>
-                <version>2.0.0_preview_617</version>
+                <version>2.0.0_preview_630</version>
             </dependency>
             </dependency>
             <dependency>
             <dependency>
                 <groupId>com.alibaba</groupId>
                 <groupId>com.alibaba</groupId>