コード例 #1
0
ファイル: FileScan.java プロジェクト: akh64bit/Parser
  /**
   * constructor
   *
   * @param file_name heapfile to be opened
   * @param in1[] array showing what the attributes of the input fields are.
   * @param s1_sizes[] shows the length of the string fields.
   * @param len_in1 number of attributes in the input tuple
   * @param n_out_flds number of fields in the out tuple
   * @param proj_list shows what input fields go where in the output tuple
   * @param outFilter select expressions
   * @exception IOException some I/O fault
   * @exception FileScanException exception from this class
   * @exception TupleUtilsException exception from this class
   * @exception InvalidRelation invalid relation
   */
  public FileScan(
      String file_name,
      AttrType in1[],
      short s1_sizes[],
      short len_in1,
      int n_out_flds,
      FldSpec[] proj_list,
      CondExpr[] outFilter)
      throws IOException, FileScanException, TupleUtilsException, InvalidRelation {
    _in1 = in1;
    in1_len = len_in1;
    s_sizes = s1_sizes;

    Jtuple = new Tuple();
    AttrType[] Jtypes = new AttrType[n_out_flds];
    short[] ts_size;
    ts_size =
        TupleUtils.setup_op_tuple(Jtuple, Jtypes, in1, len_in1, s1_sizes, proj_list, n_out_flds);

    OutputFilter = outFilter;
    perm_mat = proj_list;
    nOutFlds = n_out_flds;
    tuple1 = new Tuple();

    try {
      tuple1.setHdr(in1_len, _in1, s1_sizes);
    } catch (Exception e) {
      throw new FileScanException(e, "setHdr() failed");
    }
    t1_size = tuple1.size();

    try {
      f = new Heapfile(file_name);

    } catch (Exception e) {
      throw new FileScanException(e, "Create new heapfile failed");
    }

    try {
      scan = f.openScan();
    } catch (Exception e) {
      throw new FileScanException(e, "openScan() failed");
    }
  }
コード例 #2
0
ファイル: IndexCatalog.java プロジェクト: akh64bit/Parser
  // ADD INDEX TO A RELATION
  public void addIndex(String relation, String attrName, IndexType accessType, int buckets)
      throws IOException, Catalogioerror, Cataloghferror, Catalogmissparam, Catalogattrnotfound,
          Catalogbadtype, Catalognomem, Catalogindexnotfound, IndexCatalogException,
          java.lang.Exception {
    RID rid = null;
    IndexDesc indexRec = null;
    AttrDesc attrRec = null;
    int intKey = 0;
    float floatKey = (float) 0.0;
    String charKey = null;
    int attrCnt = 0;
    KeyClass key = null;
    int recSize = 0;

    Heapfile datafile = null;
    String indexName = null;
    Tuple tuple = null;
    BTreeFile btree = null;
    Scan pscan = null;
    AttrType[] typeArray = null;
    short[] sizeArray = null;

    // CHECK PARM

    if ((relation == null) || (attrName == null)) throw new Catalogmissparam(null, "MISSING_PARAM");

    // CHECK FOR EXISTING INDEX

    try {
      getInfo(relation, attrName, accessType, indexRec);
    } catch (Catalogioerror e) {
      System.err.println("Catalog I/O Error!" + e);
      throw new Catalogioerror(null, "");
    } catch (Cataloghferror e1) {
      System.err.println("Catalog Heapfile Error!" + e1);
      throw new Cataloghferror(null, "");
    } catch (Catalogmissparam e2) {
      System.err.println("Catalog Missing Param Error!" + e2);
      throw new Catalogmissparam(null, "");
    }

    // GET ATTRIBUTE INFO

    try {
      ExtendedSystemDefs.MINIBASE_ATTRCAT.getInfo(relation, attrName, attrRec);
    } catch (Exception e2) {
      throw new IndexCatalogException(e2, "getInfo() failed");
    }

    // Can only index on int's and strings currently
    if ((attrRec.attrType.attrType != AttrType.attrInteger)
        && (attrRec.attrType.attrType != AttrType.attrString))
      throw new Catalogbadtype(null, "Catalog: BAD TYPE!");

    // UPDATE ATTRIBUTE INFO

    attrRec.indexCnt++;

    try {
      ExtendedSystemDefs.MINIBASE_ATTRCAT.removeInfo(relation, attrName);
      ExtendedSystemDefs.MINIBASE_ATTRCAT.addInfo(attrRec);
    } catch (Exception e) {
      throw new IndexCatalogException(e, "add/remove info failed");
    }

    // BUILD INDEX FILE NAME

    indexName = buildIndexName(relation, attrName, accessType);

    // ADDED BY BILL KIMMEL - DELETE LATER
    System.out.println("Index name is " + indexName);

    // IF BTREE

    if (accessType.indexType == IndexType.B_Index) {
      btree = new BTreeFile(indexName, attrRec.attrType.attrType, attrRec.attrLen, 0);
    }

    // ADD ENTRY IN INDEXCAT

    indexRec.relName = new String(relation);
    indexRec.attrName = new String(attrName);
    indexRec.accessType = accessType;

    if (accessType.indexType == IndexType.B_Index)
      indexRec.order = new TupleOrder(TupleOrder.Ascending);
    else indexRec.order = new TupleOrder(TupleOrder.Random);

    indexRec.distinctKeys = DISTINCTKEYS;
    indexRec.clustered = 0; // 0 means non-clustered!!!!

    indexRec.indexPages = INDEXPAGES;

    try {
      addInfo(indexRec);
    } catch (Exception e) {
      throw new IndexCatalogException(e, "addInfo() failed");
    }

    // PREPARE TO SCAN DATA FILE

    try {
      datafile = new Heapfile(relation);
      if (datafile == null) throw new Catalognomem(null, "NO Enough Memory!");
    } catch (Exception e) {
      throw new IndexCatalogException(e, "create heapfile failed");
    }

    try {
      pscan = datafile.openScan();
    } catch (Exception e) {
      throw new IndexCatalogException(e, "openScan() failed");
    }

    // PREPARE TUPLE

    try {
      ExtendedSystemDefs.MINIBASE_ATTRCAT.getTupleStructure(
          relation, attrCnt, typeArray, sizeArray);
    } catch (Exception e) {
      throw new IndexCatalogException(e, "getTupleStructure");
    }

    tuple = new Tuple(Tuple.max_size);
    if (tuple == null) throw new Catalognomem(null, "Catalog, No Enough Memory!");

    try {
      tuple.setHdr((short) attrCnt, typeArray, sizeArray);
    } catch (Exception e) {
      throw new IndexCatalogException(e, "setHdr() failed");
    }

    recSize = tuple.size();

    // NOW PROCESS THE HEAPFILE AND INSERT KEY,RID INTO INDEX

    while (true) {
      try {
        tuple = pscan.getNext(rid);
        if (tuple == null) return;
      } catch (Exception e) {
        throw new IndexCatalogException(e, "getNext() failed");
      }

      // PULL OUT THE KEY VALUE FROM HEAPFILE RECORD

      if (attrRec.attrType.attrType == AttrType.attrInteger) {
        intKey = tuple.getIntFld(attrRec.attrPos);
        key = new IntegerKey(intKey);
      } else if (attrRec.attrType.attrType == AttrType.attrReal) {
        floatKey = tuple.getFloFld(attrRec.attrPos);
        key = new IntegerKey((int) floatKey);
      } else if (attrRec.attrType.attrType == AttrType.attrString) {
        charKey = new String(tuple.getStrFld(attrRec.attrPos));
        key = new StringKey(charKey);
      }

      // NOW INSERT RECORD INTO INDEX

      if (accessType.indexType == IndexType.B_Index) {
        try {
          btree.insert(key, rid);
        } catch (Exception e) {
          throw new IndexCatalogException(e, "insert failed");
        }
      }
    }
  };
コード例 #3
0
ファイル: STSTest2.java プロジェクト: anirudhgali/Minibase
  /** Constructor */
  public STSDriver2() {
    System.out.print("Started STS tests2" + "\n");

    // build ColaMarkets table
    colamarkets = new Vector();

    double[] v = new double[] {1.0, 1.0, 2.0, 3.0};

    colamarkets.addElement(new ColaMarkets(1, "cola_a", new Sdo_geometry(Sdo_gtype.RECTANGLE, v)));

    v = new double[] {2.5, 3.5, 3.5, 4.5};

    colamarkets.addElement(new ColaMarkets(2, "cola_b", new Sdo_geometry(Sdo_gtype.RECTANGLE, v)));

    boolean status = OK;
    int numMarkets = 2;
    int numMarkets_attrs = 3;

    String dbpath = "/tmp/" + System.getProperty("user.name") + ".minibase.ststest2db";
    String logpath = "/tmp/" + System.getProperty("user.name") + ".sts2log";

    String remove_cmd = "/bin/rm -rf ";
    String remove_logcmd = remove_cmd + logpath;
    String remove_dbcmd = remove_cmd + dbpath;
    String remove_sts2cmd = remove_cmd + dbpath;

    try {
      Runtime.getRuntime().exec(remove_logcmd);
      Runtime.getRuntime().exec(remove_dbcmd);
      Runtime.getRuntime().exec(remove_sts2cmd);
    } catch (IOException e) {
      System.err.println("" + e);
    }

    /*
    ExtendedSystemDefs extSysDef =
      new ExtendedSystemDefs( "/tmp/minibase.jointestdb", "/tmp/joinlog",
         1000,500,200,"Clock");
    */

    SystemDefs sysdef = new SystemDefs(dbpath, 1000, NUMBUF, "Clock");

    // creating the sailors relation
    AttrType[] Mtypes = new AttrType[3];
    Mtypes[0] = new AttrType(AttrType.attrInteger);
    Mtypes[1] = new AttrType(AttrType.attrString);
    Mtypes[2] = new AttrType(AttrType.attrSdogeometry);

    // SOS
    short[] Msizes = new short[1];
    Msizes[0] = 30; // first elt. is 30

    Tuple t = new Tuple();
    try {
      t.setHdr((short) 3, Mtypes, Msizes);
    } catch (Exception e) {
      System.err.println("*** error in Tuple.setHdr() ***");
      status = FAIL;
      e.printStackTrace();
    }

    int size = t.size();
    System.out.println("Size:" + size);

    // selecting the tuple into file "colamarkets"
    RID rid;
    Heapfile f = null;
    try {
      f = new Heapfile("colamarkets.in");
    } catch (Exception e) {
      System.err.println("*** error in Heapfile constructor ***");
      status = FAIL;
      e.printStackTrace();
    }

    t = new Tuple(size);
    try {
      t.setHdr((short) 3, Mtypes, Msizes);
    } catch (Exception e) {
      System.err.println("*** error in Tuple.setHdr() ***");
      status = FAIL;
      e.printStackTrace();
    }

    for (int i = 0; i < numMarkets; i++) {
      try {
        t.setIntFld(1, ((ColaMarkets) colamarkets.elementAt(i)).marketId);
        t.setStrFld(2, ((ColaMarkets) colamarkets.elementAt(i)).name);
        t.setSdogeometryFld(3, ((ColaMarkets) colamarkets.elementAt(i)).shape);
      } catch (Exception e) {
        System.err.println("*** Heapfile error in Tuple.setStrFld() ***");
        status = FAIL;
        e.printStackTrace();
      }

      try {
        rid = f.insertRecord(t.returnTupleByteArray());
      } catch (Exception e) {
        System.err.println("*** error in Heapfile.selectRecord() ***");
        status = FAIL;
        e.printStackTrace();
      }
    }

    if (status != OK) {
      // bail out
      System.err.println("*** Error creation relation for colamarkets");
      Runtime.getRuntime().exit(1);
    }
  }