use of com.alibaba.otter.canal.parse.inbound.TableMeta in project canal by alibaba.
the class MemoryTableMeta method find.
@Override
public TableMeta find(String schema, String table) {
List<String> keys = Arrays.asList(schema, table);
TableMeta tableMeta = tableMetas.get(keys);
if (tableMeta == null) {
synchronized (this) {
tableMeta = tableMetas.get(keys);
if (tableMeta == null) {
Schema schemaRep = repository.findSchema(schema);
if (schemaRep == null) {
return null;
}
SchemaObject data = schemaRep.findTable(table);
if (data == null) {
return null;
}
SQLStatement statement = data.getStatement();
if (statement == null) {
return null;
}
if (statement instanceof SQLCreateTableStatement) {
tableMeta = parse((SQLCreateTableStatement) statement);
}
if (tableMeta != null) {
if (table != null) {
tableMeta.setTable(table);
}
if (schema != null) {
tableMeta.setSchema(schema);
}
tableMetas.put(keys, tableMeta);
}
}
}
}
return tableMeta;
}
use of com.alibaba.otter.canal.parse.inbound.TableMeta in project canal by alibaba.
the class MemoryTableMeta_DDL_Test method test_any.
@Test
public void test_any() 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_any.sql");
String sql = StringUtils.join(IOUtils.readLines(new FileInputStream(create)), "\n");
memoryTableMeta.apply(null, "test", sql, null);
List<String> tableNames = new ArrayList<>();
for (Schema schema : memoryTableMeta.getRepository().getSchemas()) {
tableNames.addAll(schema.showTables());
}
for (String table : tableNames) {
TableMeta sourceMeta = memoryTableMeta.find("test", table);
System.out.println(sourceMeta.toString());
}
}
use of com.alibaba.otter.canal.parse.inbound.TableMeta in project canal by alibaba.
the class MemoryTableMeta_DDL_Test method test1.
@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);
}
use of com.alibaba.otter.canal.parse.inbound.TableMeta in project canal by alibaba.
the class MemoryTableMeta_DDL_Test method test_create_if_not_exist.
@Test
public void test_create_if_not_exist() 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_create_if_not_exist.sql");
String sql = StringUtils.join(IOUtils.readLines(new FileInputStream(create)), "\n");
memoryTableMeta.apply(null, "test", sql, null);
List<String> tableNames = new ArrayList<>();
for (Schema schema : memoryTableMeta.getRepository().getSchemas()) {
tableNames.addAll(schema.showTables());
}
for (String table : tableNames) {
TableMeta sourceMeta = memoryTableMeta.find("test", table);
System.out.println(sourceMeta.toString());
}
}
use of com.alibaba.otter.canal.parse.inbound.TableMeta in project canal by alibaba.
the class MemoryTableMeta_Random_DDL_Test method compareTableMeta.
private void compareTableMeta(int num, MemoryTableMeta source, MemoryTableMeta target) {
List<String> tableNames = new ArrayList<>();
for (Schema schema : source.getRepository().getSchemas()) {
tableNames.addAll(schema.showTables());
}
for (String table : tableNames) {
TableMeta sourceMeta = source.find("test", table);
TableMeta targetMeta = target.find("test", table);
boolean result = DatabaseTableMeta.compareTableMeta(sourceMeta, targetMeta);
if (!result) {
Assert.fail(sourceMeta.toString() + " vs " + targetMeta.toString());
}
}
}
Aggregations