Search in sources :

Example 16 with SchemaObject

use of com.alibaba.druid.sql.repository.SchemaObject in project druid by alibaba.

the class SQLRefactorVisitor method findMapping.

private TableMapping findMapping(SQLExprTableSource x) {
    SchemaObject schemaObject = x.getSchemaObject();
    if (schemaObject == null) {
        return null;
    }
    long nameHashCode = FnvHash.hashCode64(schemaObject.getName());
    return tableMappings.get(nameHashCode);
}
Also used : SchemaObject(com.alibaba.druid.sql.repository.SchemaObject)

Example 17 with SchemaObject

use of com.alibaba.druid.sql.repository.SchemaObject in project druid by alibaba.

the class SchemaStatVisitor method statAllColumn.

private void statAllColumn(SQLAllColumnExpr x, SQLExprTableSource tableSource) {
    SQLExprTableSource exprTableSource = tableSource;
    SQLName expr = exprTableSource.getName();
    SQLCreateTableStatement createStmt = null;
    SchemaObject tableObject = exprTableSource.getSchemaObject();
    if (tableObject != null) {
        SQLStatement stmt = tableObject.getStatement();
        if (stmt instanceof SQLCreateTableStatement) {
            createStmt = (SQLCreateTableStatement) stmt;
        }
    }
    if (createStmt != null && createStmt.getTableElementList().size() > 0) {
        SQLName tableName = createStmt.getName();
        for (SQLTableElement e : createStmt.getTableElementList()) {
            if (e instanceof SQLColumnDefinition) {
                SQLColumnDefinition columnDefinition = (SQLColumnDefinition) e;
                SQLName columnName = columnDefinition.getName();
                Column column = addColumn(tableName, columnName.toString());
                if (isParentSelectItem(x.getParent())) {
                    column.setSelec(true);
                }
            }
        }
    } else if (expr != null) {
        Column column = addColumn(expr, "*");
        if (isParentSelectItem(x.getParent())) {
            column.setSelec(true);
        }
    }
}
Also used : SchemaObject(com.alibaba.druid.sql.repository.SchemaObject) Column(com.alibaba.druid.stat.TableStat.Column)

Example 18 with SchemaObject

use of com.alibaba.druid.sql.repository.SchemaObject in project druid by alibaba.

the class CanalSQLSchemaTest method testSimple.

@Test
public void testSimple() throws Throwable {
    SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
    String sql1 = "CREATE TABLE `table_x1` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, " + "`key1` longtext NOT NULL COMMENT 'key1', `value1` longtext NOT NULL COMMENT 'value1', PRIMARY KEY (`id`) )" + "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
    String sql2 = " CREATE TABLE IF NOT EXISTS `table_x1` ( `id` bigint(20) NOT NULL AUTO_INCREMENT," + "`key1` longtext NOT NULL COMMENT 'key1',PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
    repository.console(sql1);
    repository.console(sql2);
    repository.setDefaultSchema("test");
    SchemaObject table = repository.findTable("table_x1");
    Assert.assertTrue(table.findColumn("value1") != null);
}
Also used : SchemaObject(com.alibaba.druid.sql.repository.SchemaObject) SchemaRepository(com.alibaba.druid.sql.repository.SchemaRepository) Test(org.junit.Test)

Example 19 with SchemaObject

use of com.alibaba.druid.sql.repository.SchemaObject in project druid by alibaba.

the class CanalSQLSchemaTest method test_block_format.

@Test
public void test_block_format() throws Throwable {
    SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
    String sql = " CREATE TABLE `parent` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT," + "`created_at` timestamp NULL DEFAULT NULL, " + "PRIMARY KEY (`id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 BLOCK_FORMAT=ENCRYPTED";
    repository.console(sql);
    repository.setDefaultSchema("test");
    SchemaObject table = repository.findTable("parent");
    Assert.assertTrue(table.findColumn("id") != null);
}
Also used : SchemaObject(com.alibaba.druid.sql.repository.SchemaObject) SchemaRepository(com.alibaba.druid.sql.repository.SchemaRepository) Test(org.junit.Test)

Example 20 with SchemaObject

use of com.alibaba.druid.sql.repository.SchemaObject in project druid by alibaba.

the class CanalSQLSchemaTest method test_invisible.

@Test
public void test_invisible() throws Throwable {
    SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
    String sql = " CREATE TABLE `proposal_order_info` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT," + "`created_at` timestamp NULL DEFAULT NULL, " + "PRIMARY KEY (`id`) , " + "KEY `idx_create_time` (`created_at`) /*!80000 INVISIBLE */" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 BLOCK_FORMAT=ENCRYPTED";
    repository.console(sql);
    repository.setDefaultSchema("test");
    SchemaObject table = repository.findTable("proposal_order_info");
    Assert.assertTrue(table.findColumn("id") != null);
}
Also used : SchemaObject(com.alibaba.druid.sql.repository.SchemaObject) SchemaRepository(com.alibaba.druid.sql.repository.SchemaRepository) Test(org.junit.Test)

Aggregations

SchemaObject (com.alibaba.druid.sql.repository.SchemaObject)23 SchemaRepository (com.alibaba.druid.sql.repository.SchemaRepository)13 Test (org.junit.Test)10 Column (com.alibaba.druid.stat.TableStat.Column)3 Schema (com.alibaba.druid.sql.repository.Schema)2 SQLObject (com.alibaba.druid.sql.ast.SQLObject)1 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)1 SQLCreateTableStatement (com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement)1 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)1 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)1 Token (com.alibaba.druid.sql.parser.Token)1 SQLASTOutputVisitor (com.alibaba.druid.sql.visitor.SQLASTOutputVisitor)1 TableMeta (com.alibaba.otter.canal.parse.inbound.TableMeta)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1