use of com.alibaba.druid.sql.repository.SchemaRepository in project druid by alibaba.
the class SchemaStatTest21_issue3980 method test_schemaStat.
public void test_schemaStat() throws Exception {
SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
String sql = "select n.user_name,\n" + "n.user_passwd,\n" + "n.user_project,\n" + "n.start_date,\n" + "n.end_date\n" + "from (\n" + "select t.name as user_name,\n" + "t.passwd as user_passwd,\n" + "cast(from_unixtime(t.from_time, \"yyyyMMdd\") as int) as start_date,\n" + "cast(from_unixtime(t.to_time, \"yyyyMMdd\") as int) as end_date\n" + "from tableA as t\n" + "where t.user_id = 1\n" + "union all\n" + "select p.project as user_project\n" + "from tableB as p\n" + "where p.project_id = 10\n" + ") as n;";
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL);
SQLStatement stmt = parser.parseStatementList().get(0);
SchemaStatVisitor statVisitor = SQLUtils.createSchemaStatVisitor(repository);
stmt.accept(statVisitor);
System.out.println("Tables : " + statVisitor.getTables());
System.out.println("columns : " + statVisitor.getColumns());
// group by
System.out.println(statVisitor.getGroupByColumns());
// group by
System.out.println("relationships : " + statVisitor.getRelationships());
System.out.println("conditions : " + statVisitor.getConditions());
System.out.println("functions : " + statVisitor.getFunctions());
assertEquals(7, statVisitor.getColumns().size());
assertEquals(2, statVisitor.getConditions().size());
assertEquals(2, statVisitor.getFunctions().size());
SQLPropertyExpr expr = (SQLPropertyExpr) statVisitor.getFunctions().get(0).getArguments().get(0);
SQLIdentifierExpr tableAlias = (SQLIdentifierExpr) expr.getOwner();
tableAlias.getResolvedTableSource();
}
use of com.alibaba.druid.sql.repository.SchemaRepository in project canal by alibaba.
the class FastsqlSchemaTest 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");
System.out.println(table.getStatement().toString());
Assert.assertTrue(table.findColumn("value1") != null);
}
use of com.alibaba.druid.sql.repository.SchemaRepository in project canal by alibaba.
the class FastsqlSchemaTest 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");
System.out.println(table.getStatement().toString());
Assert.assertTrue(table.findColumn("id") != null);
}
use of com.alibaba.druid.sql.repository.SchemaRepository in project canal by alibaba.
the class FastsqlSchemaTest method test_persistent.
@Test
public void test_persistent() throws Throwable {
SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
String sql = " create table example_vc_tbl( c1 int not null auto_increment primary key," + "c2 varchar(70), vc1 int as (length(c2)) virtual," + "DIM_SUM varchar(128) AS (MD5(UPPER(CONCAT(c2, c1)))) PERSISTENT)";
repository.console(sql);
repository.setDefaultSchema("test");
SchemaObject table = repository.findTable("example_vc_tbl");
System.out.println(table.getStatement().toString());
Assert.assertTrue(table.findColumn("c1") != null);
}
use of com.alibaba.druid.sql.repository.SchemaRepository in project druid by alibaba.
the class MySqlCreateTable_showColumns_test_4 method test_0.
public void test_0() throws Exception {
SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
String sql = "create table tmp_eric (pk int key, ia int unique);";
SQLStatement stmt = SQLUtils.parseSingleMysqlStatement(sql);
assertEquals("CREATE TABLE tmp_eric (\n" + "\tpk int PRIMARY KEY,\n" + "\tia int UNIQUE\n" + ");", stmt.toString());
}
Aggregations