use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGCreateTableTest_1 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE products (" + //
" product_no integer," + //
" name text," + //
" price numeric" + ");";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
// print(statementList);
Assert.assertEquals(1, statementList.size());
PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
statemen.accept(visitor);
// System.out.println("Tables : " + visitor.getTables());
// System.out.println("fields : " + visitor.getColumns());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("products")));
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("products")).getCreateCount() == 1);
Assert.assertTrue(visitor.getColumns().size() == 3);
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGCreateTableTest_13 method test_0.
public void test_0() throws Exception {
String sql = "CREATE index fact_pageview_sum_p_day_id_idx ON fact_pageview_sum USING btree (p_day_id);";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
assertEquals("CREATE INDEX fact_pageview_sum_p_day_id_idx ON fact_pageview_sum USING btree (p_day_id);", SQLUtils.toPGString(stmt));
assertEquals("create index fact_pageview_sum_p_day_id_idx on fact_pageview_sum using btree (p_day_id);", SQLUtils.toPGString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
assertEquals(1, statementList.size());
PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
stmt.accept(visitor);
// System.out.println("Tables : " + visitor.getTables());
// System.out.println("fields : " + visitor.getColumns());
assertTrue(visitor.getTables().containsKey(new TableStat.Name("fact_pageview_sum")));
// assertTrue(visitor.getTables().get(new TableStat.Name("fact_pageview_sum")).getCreateCount() == 1);
assertEquals(1, visitor.getColumns().size());
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class DropTableTest method test_0.
public void test_0() throws Exception {
String sql = "DROP TABLE films, distributors;";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
// print(statementList);
Assert.assertEquals(1, statementList.size());
PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
statemen.accept(visitor);
// System.out.println("Tables : " + visitor.getTables());
// System.out.println("fields : " + visitor.getColumns());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("films")));
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("distributors")));
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("films")).getDropCount() == 1);
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("distributors")).getDropCount() == 1);
Assert.assertTrue(visitor.getColumns().size() == 0);
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGAlterTableTest method test_0.
public void test_0() throws Exception {
String sql = "ALTER TABLE dependencies ALTER COLUMN id TYPE bigint";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
// print(statementList);
Assert.assertEquals(1, statementList.size());
PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
statemen.accept(visitor);
// System.out.println("Tables : " + visitor.getTables());
// System.out.println("fields : " + visitor.getColumns());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("dependencies")));
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("dependencies")).getAlterCount() == 1);
Assert.assertTrue(visitor.getColumns().size() == 1);
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGInsertTest12_issue_2192 method test_0.
public void test_0() throws Exception {
String sql = "insert into test1 as xx (tid,tid1,tvalue)\n" + "values (1,1,1),(2,2,2)\n" + "on conflict(tid,tid1) do update\n" + "set tvalue = xx.tvalue + excluded.tvalue;";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
// print(statementList);
assertEquals(1, statementList.size());
PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
stmt.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
// System.out.println("coditions : " + visitor.getConditions());
assertTrue(visitor.getTables().containsKey(new TableStat.Name("test1")));
assertEquals(3, visitor.getColumns().size());
//
// assertTrue(visitor.getColumns().contains(new TableStat.Column("distributors", "did")));
// assertTrue(visitor.getColumns().contains(new TableStat.Column("distributors", "dname")));
assertEquals("INSERT INTO test1 xx (tid, tid1, tvalue)\n" + "VALUES (1, 1, 1), \n" + "(2, 2, 2)\n" + "ON CONFLICT (tid, tid1) DO UPDATE SET tvalue = xx.tvalue + excluded.tvalue;", stmt.toString());
}
Aggregations