use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor in project druid by alibaba.
the class OracleSelectTest39 method test_0.
public void test_0() throws Exception {
//
String sql = //
"select * from ge_rms_company start with comCode ='11' connect by nocycle prior comCode=UPPERCOMCODE";
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
print(statementList);
Assert.assertEquals(1, statementList.size());
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
statemen.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("coditions : " + visitor.getConditions());
System.out.println("relationships : " + visitor.getRelationships());
System.out.println("orderBy : " + visitor.getOrderByColumns());
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("ge_rms_company")));
Assert.assertEquals(3, visitor.getColumns().size());
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("acduser.vw_acd_info", "xzqh")));
// Assert.assertTrue(visitor.getOrderByColumns().contains(new TableStat.Column("employees", "last_name")));
}
use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor in project druid by alibaba.
the class OracleSelectTest40 method test_0.
public void test_0() throws Exception {
//
String sql = //
"WITH a AS (" + //
" SELECT to_char(csl.create_time,'yyyyMMdd') create_time, cwl.client_key ck, csl.src_id src_id " + //
" FROM xxxx csl, xxxx cwl " + //
" WHERE 1 =1 AND csl.src_id = cwl.src_id AND csl.curr_url = cwl.curr_url " + //
" AND to_char(csl.create_time,'yyyyMMdd') BETWEEN ? " + //
" AND ? AND cwl.day = to_char(csl.create_time,'yyyyMMdd') " + //
" GROUP BY cwl.client_key, csl.src_id, csl.create_time ORDER BY csl.src_id )" + //
", b AS (" + //
" SELECT itn.buyerpaytime, itn.esc_orderid, itn.oldck, " + //
" MAX(con.PAYED_AMOUNT) gmv, MAX(con.buyer_onlyid) buyer " + //
" FROM xxxx itn, xxxx don, xxxx con " + //
" WHERE don.esc_orderid = itn.esc_orderid " + //
" AND con.esc_orderid = itn.esc_orderid " + //
" AND don.order_status IN (4,5,6,7,8) AND itn.buyerpaytime BETWEEN ? AND ? " + //
" GROUP BY itn.esc_orderid, itn.oldck, itn.buyerpaytime ) " + //
"SELECT MAX(cos.location) AS position , a.src_id AS srcid , " + //
" COUNT(DISTINCT b.esc_orderid) AS orders , SUM(b.gmv) AS uvGmv, " + //
" COUNT(DISTINCT buyer) AS buyers FROM a, b, cp_operate_statistics cos " + //
"WHERE a.ck = b.oldck(+) AND to_char(cos.day,'yyyyMMdd') = a.create_time " + //
" AND a.create_time = b.buyerpaytime AND a.src_id = cos.src_id GROUP BY a.src_id ORDER BY a.src_id";
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
print(statementList);
Assert.assertEquals(1, statementList.size());
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
stmt.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("coditions : " + visitor.getConditions());
System.out.println("relationships : " + visitor.getRelationships());
System.out.println("orderBy : " + visitor.getOrderByColumns());
Assert.assertEquals(2, visitor.getTables().size());
Assert.assertEquals(15, visitor.getColumns().size());
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("acduser.vw_acd_info", "xzqh")));
// Assert.assertTrue(visitor.getOrderByColumns().contains(new TableStat.Column("employees", "last_name")));
}
use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor in project druid by alibaba.
the class OracleSelectTest24 method test_0.
public void test_0() throws Exception {
//
String sql = //
"select /*+ no_parallel_index(t, \"HT_TASK_TRADE_HIS_GOR_IND \") dbms_stats cursor_sharing_exact use_weak_name_resl dynamic_sampling(0) no_monitoring no_expand index_ffs(t, \"HT_TASK_TRADE_HIS_GOR_IND \") */ count(*) as nrw,count(distinct sys_op_lbid(196675,'L',t.rowid)) as nlb,count(distinct hextoraw(sys_op_descend( \"GMT_MODIFIED \")||sys_op_descend( \"OWNER \")||sys_op_descend( \"RECORD_TYPE \"))) as ndk,sys_op_countchg(substrb(t.rowid,1,15),1) as clf from \"ESCROW \". \"HT_TASK_TRADE_HISTORY \" sample block ( 34.6426417370,1) t where \"GMT_MODIFIED \" is not null or \"OWNER \" is not null or \"RECORD_TYPE \" is not null";
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
String output = SQLUtils.toOracleString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
System.out.println(output);
Assert.assertEquals(1, statementList.size());
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
stmt.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("coditions : " + visitor.getConditions());
System.out.println("relationships : " + visitor.getRelationships());
System.out.println("orderBy : " + visitor.getOrderByColumns());
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("ESCROW.HT_TASK_TRADE_HISTORY")));
Assert.assertEquals(4, visitor.getColumns().size());
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("ESCROW.HT_TASK_TRADE_HISTORY", "*")));
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
}
use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor in project druid by alibaba.
the class OracleSelectTest27 method test_0.
public void test_0() throws Exception {
//
String sql = //
"select object_id tab_id_noprint , -9999999 col_id_noprint " + //
", 'table '||lower(owner)||' '||object_id||' '||lower(object_name)||' '||y.tid from dba_objects x" + ", search.retl_table_config_search y where object_type='TABLE' and x.owner=upper(case when instr(y.TSCHEMA,'|',1,1)>0 then substr(y.TSCHEMA,1,instr(y.TSCHEMA,'|',1,1)-1) else y.TSCHEMA end) and x.object_name=upper(y.TNAME) and ( owner not in ('SYS','SYSTEM','OUTLN','PUBLIC','WMSYS') or ( owner in ('SYS') and object_name in ('TAB$','OBJ$','COL$','CCOL$','CDEF$') ) ) union all select g.object_id as tab_id_noprint, g.column_id as tab_id_noprint , 'column '||g.column_id||' '||g.data_type||' '||g.data_length ||' '||decode(h.column_name,null ,0 ,1)||' '||lower(g.column_name) from ( select a.object_id ,a.owner, a.object_name as table_name, b.name as column_name ,b.segcol# as column_id, b.type# as data_type, b.segcollength as data_length from dba_objects a ,sys.col$ b ,search.retl_table_config_search g where a.object_id=b.obj# and a.object_type='TABLE' and a.owner=upper(case when instr(g.TSCHEMA,'|',1,1)>0 then substr(g.TSCHEMA,1,instr(g.TSCHEMA,'|',1,1)-1) else g.TSCHEMA end) and a.object_name=upper(g.TNAME) and b.segcol#!=0 and ( owner not in ('SYS','SYSTEM','OUTLN','PUBLIC','WMSYS') or ( owner in ('SYS') and a.object_name in ('TAB$','OBJ$','COL$','CCOL$','CDEF$') ) ) ) g, ( select upper(case when instr(TSCHEMA,'|',1,1)>0 then substr(TSCHEMA,1,instr(TSCHEMA,'|',1,1)-1) else TSCHEMA end) as owner, upper(a.tname) as table_name, upper(b.COLUMN_VALUE) as column_name from search.retl_table_config_search a, table(cast(erosazm.str2varlist(a.pks) as erosazm.vartabletype)) b ) h where g.owner=h.owner(+) and g.table_name=h.table_name(+) and g.column_name=h.column_name(+) order by tab_id_noprint,col_id_noprint";
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
print(statementList);
Assert.assertEquals(1, statementList.size());
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
stmt.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("coditions : " + visitor.getConditions());
System.out.println("relationships : " + visitor.getRelationships());
System.out.println("orderBy : " + visitor.getOrderByColumns());
Assert.assertEquals(3, visitor.getTables().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("dba_objects")));
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("search.retl_table_config_search")));
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("sys.col$")));
Assert.assertEquals(19, visitor.getColumns().size());
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "*")));
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
}
use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor in project druid by alibaba.
the class OracleSelectTest29 method test_0.
public void test_0() throws Exception {
//
String sql = "(select id,super_category_id_1 from category where super_category_id_1 is not null and super_category_id_1 != '-1') union (select id,super_category_id_2 from category where super_category_id_2 is not null and super_category_id_2 != '-1') union (select id,super_category_id_3 from category where super_category_id_3 is not null and super_category_id_3 != '-1') union (select id,super_category_id_4 from category where super_category_id_4 is not null and super_category_id_4 != '-1') union (select id,super_category_id_5 from category where super_category_id_5 is not null and super_category_id_5 != '-1')";
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
print(statementList);
Assert.assertEquals(1, statementList.size());
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
statemen.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("coditions : " + visitor.getConditions());
System.out.println("relationships : " + visitor.getRelationships());
System.out.println("orderBy : " + visitor.getOrderByColumns());
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("category")));
Assert.assertEquals(6, visitor.getColumns().size());
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "*")));
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
}
Aggregations