diff --git a/parse/src/test/java/com/alibaba/otter/canal/parse/inbound/mysql/tsdb/FastsqlSchemaTest.java b/parse/src/test/java/com/alibaba/otter/canal/parse/inbound/mysql/tsdb/FastsqlSchemaTest.java new file mode 100644 index 00000000..c7e25607 --- /dev/null +++ b/parse/src/test/java/com/alibaba/otter/canal/parse/inbound/mysql/tsdb/FastsqlSchemaTest.java @@ -0,0 +1,30 @@ +package com.alibaba.otter.canal.parse.inbound.mysql.tsdb; + +import java.io.FileNotFoundException; +import java.io.IOException; + +import org.junit.Test; + +import com.alibaba.fastsql.sql.repository.SchemaObject; +import com.alibaba.fastsql.sql.repository.SchemaRepository; +import com.alibaba.fastsql.util.JdbcConstants; + +/** + * @author agapple 2018年6月7日 下午5:36:13 + * @since 3.1.9 + */ +public class FastsqlSchemaTest { + + @Test + public void testSimple() throws FileNotFoundException, IOException { + 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;"; + repository.console(sql); + + repository.setDefaultSchema("yushitai_test"); + SchemaObject table = repository.findTable("_card_record_del"); + System.out.println(table.getStatement().toString()); + } +} diff --git a/parse/src/test/java/com/alibaba/otter/canal/parse/inbound/mysql/tsdb/MemoryTableMeta_DDL_Test.java b/parse/src/test/java/com/alibaba/otter/canal/parse/inbound/mysql/tsdb/MemoryTableMeta_DDL_Test.java new file mode 100644 index 00000000..e3005b62 --- /dev/null +++ b/parse/src/test/java/com/alibaba/otter/canal/parse/inbound/mysql/tsdb/MemoryTableMeta_DDL_Test.java @@ -0,0 +1,40 @@ +package com.alibaba.otter.canal.parse.inbound.mysql.tsdb; + +import java.io.File; +import java.io.FileInputStream; +import java.net.URL; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.alibaba.otter.canal.parse.inbound.TableMeta; + +/** + * @author agapple 2017年8月1日 下午7:15:54 + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = { "/tsdb/mysql-tsdb.xml" }) +public class MemoryTableMeta_DDL_Test { + + @Test + public void test1() 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_test1.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.assertNotNull(meta.getFieldMetaByName("customization_id")); + + meta = memoryTableMeta.find("yushitai_test", "_card_record_gho"); + Assert.assertNull(meta); + } +} diff --git a/parse/src/test/resources/ddl/ddl_test1.sql b/parse/src/test/resources/ddl/ddl_test1.sql new file mode 100644 index 00000000..a708fdac --- /dev/null +++ b/parse/src/test/resources/ddl/ddl_test1.sql @@ -0,0 +1,21 @@ +create table yushitai_test.card_record ( +id bigint auto_increment, +last_update timestamp not null DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +hint varchar(64) charset ascii not null, +value varchar(255) charset ascii not null, +primary key(id), +unique key hint_uidx(hint) +) auto_increment=256 ; + +DROP TABLE IF EXISTS _card_record_gho /* generated by server */ ; +DROP TABLE IF EXISTS _card_record_del /* generated by server */ ; + +create /* gh-ost */ table yushitai_test._card_record_gho like yushitai_test.card_record ; +alter /* gh-ost */ table yushitai_test._card_record_gho add column customization_id bigint unsigned NOT NULL COMMENT 'TEST' ; + +create /* gh-ost */ table yushitai_test._card_record_del ( +id int auto_increment primary key +) engine=InnoDB comment='ghost-cut-over-sentry' ; + +DROP TABLE IF EXISTS _card_record_del /* generated by server */ ; +rename /* gh-ost */ table yushitai_test.card_record to yushitai_test._card_record_del, yushitai_test._card_record_gho to yushitai_test.card_record; \ No newline at end of file diff --git a/pom.xml b/pom.xml index f48a488a..1c4ff11b 100644 --- a/pom.xml +++ b/pom.xml @@ -254,7 +254,7 @@ com.alibaba.fastsql fastsql - 2.0.0_preview_366 + 2.0.0_preview_371 com.alibaba