trafodion-codereview mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traflm <...@git.apache.org>
Subject [GitHub] incubator-trafodion pull request #683: new spj of startwith and connectby
Date Fri, 02 Sep 2016 16:15:32 GMT
Github user traflm commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/683#discussion_r77372705
  
    --- Diff: core/sql/lib_mgmt/src/main/java/org/trafodion/libmgmt/FileMgmt.java ---
    @@ -547,6 +558,64 @@ private static void checkFile(String fname, int dataSize) throws
SQLException {
     			throw new SQLException("Jar file size is over the threshold[100Mb]");
     		}
     	}
    +	
    +	public static void connectBy(String columnName, String originSql, String startWithSql,
String startWithKey,ResultSet[] rs) throws SQLException{
    +		String[] out =new String[1];
    +		getStartWith(startWithSql, startWithKey, out); 
    +		String[] s = out[0].replaceAll("^\\[|\\]$", "").split("\\s*,\\s*");
    +		String clause = " ";
    +		for(int i = 0;i<s.length;i++){
    +			if(i == s.length -1){
    +				clause += columnName + "=\'" + s[i] + "\'";
    +			}else{
    +				clause += columnName + "=\'" + s[i] + "\' or ";
    +			}
    +		}
    +		String connectSql = String.format(originSql, clause);
    +		Connection conn = getConn();
    +		PreparedStatement ps = conn.prepareStatement(connectSql);
    +		try{
    +			rs[0] = ps.executeQuery();
    +		} catch(SQLException e){
    +			LOG.error(originSql,e);
    +			throw e;
    +		} 
    +	}
    +	
    +	
    +	public static void getStartWith(String sql, String startWithKey, String[] out) throws
SQLException{
    +		String sqlTest = String.format(sql, startWithKey);
    +		int searchLevel = 0;
    +		ArrayList<String> ids = new ArrayList<String>();
    +		Connection conn = getConn();
    +		PreparedStatement ps = conn.prepareStatement(sqlTest);
    +		try{
    +			ids.addAll(bfsSearch(sql,startWithKey,searchLevel,ps));
    +			out[0]= Arrays.toString(ids.toArray());
    +		} catch(SQLException e){
    +			LOG.error(sql,e);
    +			throw e;
    +		} 
    +	}
    +	
    +	private static ArrayList<String> bfsSearch(String sql, String startWithKey,int
searchLevel, PreparedStatement ps) throws SQLException{
    --- End diff --
    
    @zellerh , the SPJ can now create volatile table, that bug is already fixed recently in
T2 driver.
    
    Agree with Han's opinion. using a table to hold intermediate result is more generic. And
the current solution is still serial, or did I misunderstand? 
    
    After getting all the start seeds, it should be able to spawn multiple threads to do it
in parallel, but using volatile table and using SQL's parallel infrastructure seems a better
approach.
    
    It is not easy to write a generic one, but this will be a very useful SPJ, so thanks for
the effort.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message