SHARE
TWEET

Untitled

a guest Jan 20th, 2020 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void Query2A_SSJ(String queryDataFolder, String queryName) {
  2.         System.out.print("**********************Query2A starting (With SingleSelfJoin) *********************\n");
  3.         boolean status = OK;
  4.      
  5.         System.out.println("Query:");
  6.         String queryPath = queryDataFolder + queryName + ".txt";
  7.         String query = "";
  8.         try (InputStreamReader isr = new InputStreamReader(new FileInputStream(queryPath))) {
  9.           int data = isr.read();
  10.           while (data != -1) {
  11.             query += Character.toString((char) data);
  12.             data = isr.read();
  13.           }
  14.         } catch (IOException e) {
  15.           System.out.println("Error reading file:" + queryPath);
  16.         }
  17.         System.out.println(query);
  18.         Pattern p = Pattern.compile("([a-zA-Z]+|\\d+)");
  19.         Matcher m = p.matcher(query);
  20.         List<String> res = new ArrayList<String>();
  21.             while(m.find()) {
  22.                 res.add(m.group(1));
  23.         }  
  24.         int projected_col1 = Integer.parseInt(res.get(1));
  25.         int projected_col2 = Integer.parseInt(res.get(3));
  26.         String rel = "R"; //res.get(4);
  27.         int join_col1 = Integer.parseInt(res.get(6));
  28.         int join_col2 = Integer.parseInt(res.get(9));
  29.         int op = Integer.parseInt(res.get(7));
  30.      
  31.         CondExpr [] outFilter = new CondExpr[2];
  32.         outFilter[0] = new CondExpr();
  33.         outFilter[1] = new CondExpr();
  34.      
  35.         outFilter[0].next  = null;
  36.         outFilter[0].op    = new AttrOperator(op);
  37.         outFilter[0].type1 = new AttrType(AttrType.attrSymbol);
  38.         outFilter[0].operand1.symbol = new FldSpec (new RelSpec(RelSpec.outer), join_col1);
  39.         outFilter[0].type2 = new AttrType(AttrType.attrSymbol);
  40.         outFilter[0].operand2.symbol = new FldSpec (new RelSpec(RelSpec.innerRel), join_col2);
  41.         outFilter[1] = null;
  42.      
  43.         AttrType Rtypes[] = {
  44.           new AttrType(AttrType.attrInteger),
  45.           new AttrType(AttrType.attrInteger),
  46.           new AttrType(AttrType.attrInteger),
  47.           new AttrType(AttrType.attrInteger),
  48.         };
  49.         short []   Rsizes = new short[1];
  50.         Rsizes[0] = 30;
  51.      
  52.         Tuple t = new Tuple();
  53.         try {
  54.           t.setHdr((short) 4, Rtypes, Rsizes);
  55.         }
  56.         catch (Exception e) {
  57.           System.err.println("*** error in Tuple.setHdr() ***");
  58.           status = FAIL;
  59.           e.printStackTrace();
  60.         }
  61.        
  62.         int size = t.size();
  63.        
  64.         RID             rid;
  65.         Heapfile        f = null;
  66.         try {
  67.           f = new Heapfile("Q.in");
  68.         }
  69.         catch (Exception e) {
  70.           System.err.println("*** error in Heapfile constructor ***");
  71.           status = FAIL;
  72.           e.printStackTrace();
  73.         }
  74.         System.out.println("Before");
  75.        
  76.         t = new Tuple(size);
  77.         try {
  78.           t.setHdr((short) 4, Rtypes, Rsizes);
  79.         }
  80.         catch (Exception e) {
  81.           System.err.println("*** error in Tuple.setHdr() ***");
  82.           status = FAIL;
  83.           e.printStackTrace();
  84.         }
  85.         try (InputStreamReader isr = new InputStreamReader(new FileInputStream(queryDataFolder + rel + ".txt"))) {
  86.           int data = isr.read();
  87.           while (data != -1) {
  88.             query += Character.toString((char) data);
  89.             data = isr.read();
  90.           }
  91.         } catch (IOException e) {
  92.           System.out.println("Error reading file:" + queryPath);
  93.         }
  94.         p = Pattern.compile("(\\d+),(\\d+),(\\d+),(\\d+)");
  95.         m = p.matcher(query);
  96.         try {
  97.           while(m.find()) {
  98.             t.setIntFld(1, Integer.parseInt(m.group(1)));
  99.             t.setIntFld(2, Integer.parseInt(m.group(2)));
  100.             t.setIntFld(3, Integer.parseInt(m.group(3)));
  101.             t.setIntFld(4, Integer.parseInt(m.group(4)));
  102.             rid = f.insertRecord(t.returnTupleByteArray());
  103.           }
  104.         } catch (Exception e) {
  105.           e.printStackTrace();
  106.           Runtime.getRuntime().exit(1);
  107.         }
  108.          
  109.         t = new Tuple();
  110.         FldSpec [] Rprojection = {
  111.            new FldSpec(new RelSpec(RelSpec.outer), 1),
  112.            new FldSpec(new RelSpec(RelSpec.outer), 2),
  113.            new FldSpec(new RelSpec(RelSpec.outer), 3),
  114.            new FldSpec(new RelSpec(RelSpec.outer), 4)
  115.         };
  116.      
  117.         iterator.Iterator am = null;
  118.         try {
  119.           am  = new FileScan("Q.in", Rtypes, Rsizes,
  120.                       (short)4, (short) 4,
  121.               Rprojection, null);
  122.         }
  123.         catch (Exception e) {
  124.           status = FAIL;
  125.           System.err.println (""+e);
  126.         }
  127.      
  128.         if (status != OK) {
  129.           //bail out
  130.           System.err.println ("*** Error setting up scan for Q");
  131.           Runtime.getRuntime().exit(1);
  132.         }
  133.      
  134.         FldSpec [] proj_list = {
  135.           new FldSpec(new RelSpec(RelSpec.outer), projected_col1),
  136.           new FldSpec(new RelSpec(RelSpec.innerRel), projected_col2)
  137.         };
  138.      
  139.         AttrType[] jtype = { new AttrType(AttrType.attrInteger), new AttrType(AttrType.attrInteger) };
  140.      
  141.         SingleSelfJoin ssj= null;
  142.         try {
  143.           ssj = new SingleSelfJoin(Rtypes, 4, Rsizes,
  144.            10,
  145.            am,
  146.            "Q.in",
  147.            outFilter,
  148.            proj_list, 2);
  149.         }
  150.         catch (Exception e) {
  151.           status = FAIL;
  152.           System.err.println (""+e);
  153.         }
  154.      
  155.         if (status != OK) {
  156.           //bail out
  157.           System.err.println ("*** Error constructing Nested Loop Join");
  158.           Runtime.getRuntime().exit(1);
  159.         }
  160.      
  161.         //QueryCheck?
  162.      
  163.         t = null;
  164.      
  165.         try {
  166.           while ((t = ssj.get_next()) != null) {
  167.             t.print(jtype);
  168.           }
  169.         }
  170.         catch (Exception e) {
  171.           System.err.println (""+e);
  172.           e.printStackTrace();
  173.            Runtime.getRuntime().exit(1);
  174.         }
  175.      
  176.      
  177.         System.out.println ("\n");
  178.         try {
  179.           ssj.close();
  180.         }
  181.         catch (Exception e) {
  182.           status = FAIL;
  183.           e.printStackTrace();
  184.         }
  185.        
  186.         if (status != OK) {
  187.           //bail out
  188.           System.err.println ("*** Error setting up scan for sailors");
  189.           Runtime.getRuntime().exit(1);
  190.         }
  191.       }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top