Ejemplo n.º 1
0
  private void applyParameterMappings(Database catalog_db) {
    ParameterMappingsSet mappings = new ParameterMappingsSet();

    // Load ParameterMappingSet from file
    if (m_paramMappingsFile != null) {
      try {
        mappings.load(m_paramMappingsFile, catalog_db);
      } catch (IOException ex) {
        String msg = "Failed to load ParameterMappingsSet file '" + m_paramMappingsFile + "'";
        throw new RuntimeException(msg, ex);
      }
    }
    // Build ParameterMappingSet from user-provided inputs
    else {
      for (String procName : m_paramMappings.keySet()) {
        Procedure catalog_proc = catalog_db.getProcedures().getIgnoreCase(procName);
        assert (catalog_proc != null)
            : "Invalid Procedure name for ParameterMappings '" + procName + "'";
        for (Integer procParamIdx : m_paramMappings.get(procName).keySet()) {
          ProcParameter catalog_procParam =
              catalog_proc.getParameters().get(procParamIdx.intValue());
          assert (catalog_procParam != null)
              : "Invalid ProcParameter for '" + procName + "' at offset " + procParamIdx;
          Pair<String, Integer> stmtPair = m_paramMappings.get(procName).get(procParamIdx);
          assert (stmtPair != null);

          Statement catalog_stmt = catalog_proc.getStatements().getIgnoreCase(stmtPair.getFirst());
          assert (catalog_stmt != null)
              : "Invalid Statement name '"
                  + stmtPair.getFirst()
                  + "' for ParameterMappings "
                  + "for Procedure '"
                  + procName
                  + "'";
          StmtParameter catalog_stmtParam =
              catalog_stmt.getParameters().get(stmtPair.getSecond().intValue());
          assert (catalog_stmtParam != null)
              : "Invalid StmtParameter for '"
                  + catalog_stmt.fullName()
                  + "' at offset "
                  + stmtPair.getSecond();

          // HACK: This assumes that the ProcParameter is not an array
          // and that we want to map the first invocation of the Statement
          // directly to the ProcParameter.
          ParameterMapping pm =
              new ParameterMapping(catalog_stmt, 0, catalog_stmtParam, catalog_procParam, 0, 1.0);
          mappings.add(pm);
        } // FOR (ProcParameter)
      } // FOR (Procedure)
    }

    // Apply it!
    ParametersUtil.applyParameterMappings(catalog_db, mappings);
  }
Ejemplo n.º 2
0
  public CatalogContext(Catalog catalog, File pathToCatalogJar) {
    // check the heck out of the given params in this immutable class
    assert (catalog != null);
    if (catalog == null) {
      throw new RuntimeException("Can't create CatalogContext with null catalog.");
    }

    this.jarPath = pathToCatalogJar;
    this.catalog = catalog;
    this.cluster = CatalogUtil.getCluster(this.catalog);
    this.database = CatalogUtil.getDatabase(this.catalog);
    this.hosts = this.cluster.getHosts();
    this.sites = this.cluster.getSites();

    if (this.jarPath != null) {
      this.catalogClassLoader = new JarClassLoader(this.jarPath.getAbsolutePath());
      this.paramMappings =
          ParametersUtil.getParameterMappingsSetFromJar(this.database, this.jarPath);
    } else {
      this.catalogClassLoader = null;
      this.paramMappings = null;
    }

    // ------------------------------------------------------------
    // PROCEDURES
    // ------------------------------------------------------------
    this.procedures = database.getProcedures();
    this.proceduresArray = new Procedure[this.procedures.size() + 1];
    for (Procedure proc : this.procedures) {
      this.proceduresArray[proc.getId()] = proc;
      if (proc.getSystemproc()) {
        this.sysProcedures.add(proc);
      } else if (proc.getMapreduce()) {
        this.mrProcedures.add(proc);
      } else {
        this.regularProcedures.add(proc);
      }
    } // FOR

    authSystem = new AuthSystem(database, cluster.getSecurityenabled());

    siteTracker = null; // new SiteTracker(cluster.getSites());

    // count nodes
    this.numberOfHosts = cluster.getHosts().size();

    // count exec sites
    this.numberOfSites = cluster.getSites().size();

    // ------------------------------------------------------------
    // PARTITIONS
    // ------------------------------------------------------------
    this.numberOfPartitions = cluster.getNum_partitions();
    this.partitions = new Partition[this.numberOfPartitions];
    this.partitionIdArray = new Integer[this.numberOfPartitions];
    this.partitionSingletons = new PartitionSet[this.numberOfPartitions];
    this.partitionSiteXref = new int[this.numberOfPartitions];
    for (Partition part : CatalogUtil.getAllPartitions(catalog)) {
      int p = part.getId();
      this.partitions[p] = part;
      this.partitionIdArray[p] = Integer.valueOf(p);
      this.partitionSingletons[p] = new PartitionSet(p);
      this.partitionIdCollection.add(this.partitionIdArray[p]);
      this.partitionSiteXref[part.getId()] = ((Site) part.getParent()).getId();
    } // FOR

    // ------------------------------------------------------------
    // TABLES
    // ------------------------------------------------------------
    for (Table tbl : database.getTables()) {
      if (tbl.getSystable()) {
        sysTables.add(tbl);
      } else if (tbl.getMapreduce()) {
        mapReduceTables.add(tbl);
      } else if (tbl.getMaterializer() != null) {
        viewTables.add(tbl);
      } else {
        dataTables.add(tbl);
        if (tbl.getIsreplicated()) {
          replicatedTables.add(tbl);
        }
        if (tbl.getEvictable()) {
          evictableTables.add(tbl);
        }
      }
    } // FOR

    // PLANFRAGMENTS
    this.initPlanFragments();
  }