Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Query2A_SSJ(String queryDataFolder, String queryName) {
- System.out.print("**********************Query2A starting (With SingleSelfJoin) *********************\n");
- boolean status = OK;
- System.out.println("Query:");
- String queryPath = queryDataFolder + queryName + ".txt";
- String query = "";
- try (InputStreamReader isr = new InputStreamReader(new FileInputStream(queryPath))) {
- int data = isr.read();
- while (data != -1) {
- query += Character.toString((char) data);
- data = isr.read();
- }
- } catch (IOException e) {
- System.out.println("Error reading file:" + queryPath);
- }
- System.out.println(query);
- Pattern p = Pattern.compile("([a-zA-Z]+|\\d+)");
- Matcher m = p.matcher(query);
- List<String> res = new ArrayList<String>();
- while(m.find()) {
- res.add(m.group(1));
- }
- int projected_col1 = Integer.parseInt(res.get(1));
- int projected_col2 = Integer.parseInt(res.get(3));
- String rel = "R"; //res.get(4);
- int join_col1 = Integer.parseInt(res.get(6));
- int join_col2 = Integer.parseInt(res.get(9));
- int op = Integer.parseInt(res.get(7));
- CondExpr [] outFilter = new CondExpr[2];
- outFilter[0] = new CondExpr();
- outFilter[1] = new CondExpr();
- outFilter[0].next = null;
- outFilter[0].op = new AttrOperator(op);
- outFilter[0].type1 = new AttrType(AttrType.attrSymbol);
- outFilter[0].operand1.symbol = new FldSpec (new RelSpec(RelSpec.outer), join_col1);
- outFilter[0].type2 = new AttrType(AttrType.attrSymbol);
- outFilter[0].operand2.symbol = new FldSpec (new RelSpec(RelSpec.innerRel), join_col2);
- outFilter[1] = null;
- AttrType Rtypes[] = {
- new AttrType(AttrType.attrInteger),
- new AttrType(AttrType.attrInteger),
- new AttrType(AttrType.attrInteger),
- new AttrType(AttrType.attrInteger),
- };
- short [] Rsizes = new short[1];
- Rsizes[0] = 30;
- Tuple t = new Tuple();
- try {
- t.setHdr((short) 4, Rtypes, Rsizes);
- }
- catch (Exception e) {
- System.err.println("*** error in Tuple.setHdr() ***");
- status = FAIL;
- e.printStackTrace();
- }
- int size = t.size();
- RID rid;
- Heapfile f = null;
- try {
- f = new Heapfile("Q.in");
- }
- catch (Exception e) {
- System.err.println("*** error in Heapfile constructor ***");
- status = FAIL;
- e.printStackTrace();
- }
- System.out.println("Before");
- t = new Tuple(size);
- try {
- t.setHdr((short) 4, Rtypes, Rsizes);
- }
- catch (Exception e) {
- System.err.println("*** error in Tuple.setHdr() ***");
- status = FAIL;
- e.printStackTrace();
- }
- try (InputStreamReader isr = new InputStreamReader(new FileInputStream(queryDataFolder + rel + ".txt"))) {
- int data = isr.read();
- while (data != -1) {
- query += Character.toString((char) data);
- data = isr.read();
- }
- } catch (IOException e) {
- System.out.println("Error reading file:" + queryPath);
- }
- p = Pattern.compile("(\\d+),(\\d+),(\\d+),(\\d+)");
- m = p.matcher(query);
- try {
- while(m.find()) {
- t.setIntFld(1, Integer.parseInt(m.group(1)));
- t.setIntFld(2, Integer.parseInt(m.group(2)));
- t.setIntFld(3, Integer.parseInt(m.group(3)));
- t.setIntFld(4, Integer.parseInt(m.group(4)));
- rid = f.insertRecord(t.returnTupleByteArray());
- }
- } catch (Exception e) {
- e.printStackTrace();
- Runtime.getRuntime().exit(1);
- }
- t = new Tuple();
- FldSpec [] Rprojection = {
- new FldSpec(new RelSpec(RelSpec.outer), 1),
- new FldSpec(new RelSpec(RelSpec.outer), 2),
- new FldSpec(new RelSpec(RelSpec.outer), 3),
- new FldSpec(new RelSpec(RelSpec.outer), 4)
- };
- iterator.Iterator am = null;
- try {
- am = new FileScan("Q.in", Rtypes, Rsizes,
- (short)4, (short) 4,
- Rprojection, null);
- }
- catch (Exception e) {
- status = FAIL;
- System.err.println (""+e);
- }
- if (status != OK) {
- //bail out
- System.err.println ("*** Error setting up scan for Q");
- Runtime.getRuntime().exit(1);
- }
- FldSpec [] proj_list = {
- new FldSpec(new RelSpec(RelSpec.outer), projected_col1),
- new FldSpec(new RelSpec(RelSpec.innerRel), projected_col2)
- };
- AttrType[] jtype = { new AttrType(AttrType.attrInteger), new AttrType(AttrType.attrInteger) };
- SingleSelfJoin ssj= null;
- try {
- ssj = new SingleSelfJoin(Rtypes, 4, Rsizes,
- 10,
- am,
- "Q.in",
- outFilter,
- proj_list, 2);
- }
- catch (Exception e) {
- status = FAIL;
- System.err.println (""+e);
- }
- if (status != OK) {
- //bail out
- System.err.println ("*** Error constructing Nested Loop Join");
- Runtime.getRuntime().exit(1);
- }
- //QueryCheck?
- t = null;
- try {
- while ((t = ssj.get_next()) != null) {
- t.print(jtype);
- }
- }
- catch (Exception e) {
- System.err.println (""+e);
- e.printStackTrace();
- Runtime.getRuntime().exit(1);
- }
- System.out.println ("\n");
- try {
- ssj.close();
- }
- catch (Exception e) {
- status = FAIL;
- e.printStackTrace();
- }
- if (status != OK) {
- //bail out
- System.err.println ("*** Error setting up scan for sailors");
- Runtime.getRuntime().exit(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement