use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGSelectTest16 method test_0.
public void test_0() throws Exception {
String sql = "WITH RECURSIVE search_graph(id, link, data, depth, path, cycle) AS (" + " SELECT g.id, g.link, g.data, 1," + " ARRAY[g.id]," + " false" + " FROM graph g" + " UNION ALL" + " SELECT g.id, g.link, g.data, sg.depth + 1," + " path || g.id," + " g.id = ANY(path)" + " FROM graph g, search_graph sg" + " WHERE g.id = sg.link AND NOT cycle" + ")" + "SELECT * FROM search_graph;";
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());
// System.out.println("coditions : " + visitor.getConditions());
Assert.assertEquals(9, visitor.getColumns().size());
Assert.assertEquals(2, visitor.getTables().size());
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("graph", "id")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("graph", "link")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("graph", "data")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("search_graph", "depth")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("graph", "path")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("search_graph", "link")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("graph", "cycle")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("sg", "depth")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("sg", "link")));
}
use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGSelectTest17 method test_0.
public void test_0() throws Exception {
String sql = "WITH RECURSIVE search_graph(id, link, data, depth, path, cycle) AS (" + " SELECT g.id, g.link, g.data, 1," + " ARRAY[ROW(g.f1, g.f2)]," + " false" + " FROM graph g" + " UNION ALL" + " SELECT g.id, g.link, g.data, sg.depth + 1," + " path || ROW(g.f1, g.f2)," + " ROW(g.f1, g.f2) = ANY(path)" + " FROM graph g, search_graph sg" + " WHERE g.id = sg.link AND NOT cycle" + ")" + "SELECT * FROM search_graph;";
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());
// System.out.println("coditions : " + visitor.getConditions());
Assert.assertEquals(11, visitor.getColumns().size());
Assert.assertEquals(2, visitor.getTables().size());
}
use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGSelectTest22 method test_0.
public void test_0() throws Exception {
String sql = "SELECT i.relname, d.indisunique, a.attname" + " FROM pg_class t, pg_class i, pg_index d, pg_attribute " + " WHERE i.relkind = 'i'" + " AND d.indexrelid = i.oid" + " AND d.indisprimary = 'f'" + " AND t.oid = d.indrelid" + " AND t.relname = 'schema_migrations'" + " AND a.attrelid = t.oid" + " AND ( d.indkey[0]=a.attnum OR d.indkey[1]=a.attnum" + " OR d.indkey[2]=a.attnum OR d.indkey[3]=a.attnum" + " OR d.indkey[4]=a.attnum OR d.indkey[5]=a.attnum" + " OR d.indkey[6]=a.attnum OR d.indkey[7]=a.attnum" + " OR d.indkey[8]=a.attnum OR d.indkey[9]=a.attnum )" + " ORDER BY i.relname" + "";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
// print(statementList);
Assert.assertEquals("SELECT i.relname, d.indisunique, a.attname" + "\nFROM pg_class t, pg_class i, pg_index d, pg_attribute" + "\nWHERE i.relkind = 'i'" + "\n\tAND d.indexrelid = i.oid" + "\n\tAND d.indisprimary = 'f'" + "\n\tAND t.oid = d.indrelid" + "\n\tAND t.relname = 'schema_migrations'" + "\n\tAND a.attrelid = t.oid" + "\n\tAND (d.indkey[0] = a.attnum" + "\n\t\tOR d.indkey[1] = a.attnum" + "\n\t\tOR d.indkey[2] = a.attnum" + "\n\t\tOR d.indkey[3] = a.attnum" + "\n\t\tOR d.indkey[4] = a.attnum" + "\n\t\tOR d.indkey[5] = a.attnum" + "\n\t\tOR d.indkey[6] = a.attnum" + "\n\t\tOR d.indkey[7] = a.attnum" + "\n\t\tOR d.indkey[8] = a.attnum" + "\n\t\tOR d.indkey[9] = a.attnum)" + "\nORDER BY i.relname", output(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());
// System.out.println("coditions : " + visitor.getConditions());
Assert.assertEquals(11, visitor.getColumns().size());
Assert.assertEquals(3, visitor.getTables().size());
}
use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGSetTest method test_0.
public void test_0() throws Exception {
String sql = "SET standard_conforming_strings=on";
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());
// System.out.println("coditions : " + visitor.getConditions());
Assert.assertEquals(0, visitor.getColumns().size());
String mergedSql = ParameterizedOutputVisitorUtils.parameterize(sql, JdbcUtils.POSTGRESQL);
System.out.println(mergedSql);
}
use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGSetTest2 method test_0.
public void test_0() throws Exception {
String sql = "SET search_path = \"public\",\"$user\", public";
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());
// System.out.println("coditions : " + visitor.getConditions());
Assert.assertEquals(0, visitor.getColumns().size());
String mergedSql = ParameterizedOutputVisitorUtils.parameterize(sql, JdbcUtils.POSTGRESQL);
assertEquals("SET search_path = \"public\",\"$user\", public", mergedSql);
}
Aggregations