Package org.voltdb.catalog

Examples of org.voltdb.catalog.Procedure


       
        // Procedures to exclude in ConflictGraph
        if (args.hasParam(ArgumentsParser.PARAM_CONFLICTS_EXCLUDE_PROCEDURES)) {
            String param = args.getParam(ArgumentsParser.PARAM_CONFLICTS_EXCLUDE_PROCEDURES);
            for (String procName : param.split(",")) {
                Procedure catalog_proc = args.catalogContext.procedures.getIgnoreCase(procName);
                if (catalog_proc != null) {
                    calculator.ignoreProcedure(catalog_proc);
                } else {
                    LOG.warn("Invalid procedure name to exclude '" + procName + "'");
                }
            } // FOR
        }
       
        // Statements to exclude in ConflictGraph
        if (args.hasParam(ArgumentsParser.PARAM_CONFLICTS_EXCLUDE_STATEMENTS)) {
            String param = args.getParam(ArgumentsParser.PARAM_CONFLICTS_EXCLUDE_STATEMENTS);
            for (String name : param.split(",")) {
                String splits[] = name.split("\\.");
                if (splits.length != 2) {
                    LOG.warn("Invalid procedure name to exclude '" + name + "': " + Arrays.toString(splits));
                    continue;
                }
                Procedure catalog_proc = args.catalogContext.procedures.getIgnoreCase(splits[0]);
                if (catalog_proc == null) {
                    LOG.warn("Invalid procedure name to exclude '" + name + "'");
                    continue;
                }
                   
                Statement catalog_stmt = catalog_proc.getStatements().getIgnoreCase(splits[1]);
                if (catalog_stmt != null) {
                    calculator.ignoreStatement(catalog_stmt);
                } else {
                    LOG.warn("Invalid statement name to exclude '" + name + "'");
                }
            } // FOR
        }
       
        calculator.process();
        ConflictGraph graph = new ConflictGraph(args.catalog_db);
       
        // If we have a Procedure to "focus" on, then we need to remove any edges
        // that don't involve that Procedure
        if (args.hasParam(ArgumentsParser.PARAM_CONFLICTS_FOCUS_PROCEDURE)) {
            String procName = args.getParam(ArgumentsParser.PARAM_CONFLICTS_FOCUS_PROCEDURE);
            Procedure catalog_proc = args.catalogContext.procedures.getIgnoreCase(procName);
            if (catalog_proc != null) {
                ConflictVertex v = graph.getVertex(catalog_proc);
                assert(v != null);
                GraphUtil.removeEdgesWithoutVertex(graph, v);
                GraphUtil.removeDisconnectedVertices(graph);
View Full Code Here


            assert (catalog_tbl.getColumns().size() == clone_tbl.getColumns().size()) : catalog_tbl.getColumns() + " != " + clone_tbl.getColumns();
        } // FOR

        // And don't forget MultiProcParameter!
        for (Procedure catalog_proc : catalog_db.getProcedures()) {
            Procedure clone_proc = clone_db.getProcedures().get(catalog_proc.getName());
            for (ProcParameter catalog_param : catalog_proc.getParameters()) {
                if (catalog_param instanceof MultiProcParameter) {
                    MultiProcParameter mpp = (MultiProcParameter) catalog_param;
                    ProcParameter clone_params[] = new ProcParameter[mpp.size()];
                    for (int i = 0; i < clone_params.length; i++) {
                        clone_params[i] = clone_proc.getParameters().get(mpp.get(i).getIndex());
                    } // FOR

                    // This will automatically add our guy into clone_tbl
                    MultiProcParameter clone_mpp = MultiProcParameter.get(clone_params);
                    assert (clone_mpp != null);
                }
            }
            assert (catalog_proc.getParameters().size() == clone_proc.getParameters().size()) : catalog_proc.getParameters() + " != " + clone_proc.getParameters();
        } // FOR

        return (clone_db);
    }
View Full Code Here

            // We need to fix the reference to the ProcParameter (if one exists)
            StmtParameter src_stmt_param = (StmtParameter) src_item;
            StmtParameter dest_stmt_param = (StmtParameter) clone;

            if (src_stmt_param.getProcparameter() != null) {
                Procedure dest_proc = (Procedure) dest_stmt_param.getParent().getParent();
                ProcParameter src_proc_param = src_stmt_param.getProcparameter();
                ProcParameter dest_proc_param = dest_proc.getParameters().get(src_proc_param.getName());
                if (dest_proc_param == null) {
                    LOG.warn("dest_proc:      " + dest_proc);
                    LOG.warn("dest_stmt:      " + dest_stmt_param.getParent());
                    LOG.warn("src_proc_param: " + src_proc_param);
                    LOG.warn("dest_proc.getParameters(): " + CatalogUtil.debug(dest_proc.getParameters()));
                    CatalogUtil.saveCatalog(dest_catalog, CatalogUtil.CATALOG_FILENAME);
                }

                assert (dest_proc_param != null);
                dest_stmt_param.setProcparameter(dest_proc_param);
View Full Code Here

     * @param src_db
     * @param dest_db
     */
    public static void cloneConflicts(Database src_db, Database dest_db) {
        for (Procedure src_proc : src_db.getProcedures()) {
            Procedure dest_proc = dest_db.getProcedures().get(src_proc.getName());
            assert(dest_proc != null) : src_proc;
           
            for (ConflictSet src_conflicts : src_proc.getConflicts()) {
                Procedure dest_otherProc = dest_db.getProcedures().get(src_conflicts.getProcedure().getName());
                ConflictSet dest_conflicts = dest_proc.getConflicts().add(src_conflicts.getName());
                dest_conflicts.setProcedure(dest_otherProc);
               
                for (ConflictPair src_pair : src_conflicts.getReadwriteconflicts()) {
                    ConflictPair dest_pair = clone(src_pair, dest_db.getCatalog());
                    dest_pair.setStatement0(dest_proc.getStatements().get(src_pair.getStatement0().getName()));
                    dest_pair.setStatement1(dest_otherProc.getStatements().get(src_pair.getStatement1().getName()));
                    for (TableRef src_ref : src_pair.getTables()) {
                        TableRef dest_ref = dest_pair.getTables().add(src_ref.getName());
                        dest_ref.setTable(dest_db.getTables().get(src_ref.getTable().getName()));
                    } // FOR
                } // FOR
                for (ConflictPair src_pair : src_conflicts.getWritewriteconflicts()) {
                    ConflictPair dest_pair = clone(src_pair, dest_db.getCatalog());
                    dest_pair.setStatement0(dest_proc.getStatements().get(src_pair.getStatement0().getName()));
                    dest_pair.setStatement1(dest_otherProc.getStatements().get(src_pair.getStatement1().getName()));
                    for (TableRef src_ref : src_pair.getTables()) {
                        TableRef dest_ref = dest_pair.getTables().add(src_ref.getName());
                        dest_ref.setTable(dest_db.getTables().get(src_ref.getTable().getName()));
                    } // FOR
                } // FOR
View Full Code Here

        // get the short name of the class (no package)
        String[] parts = className.split("\\.");
        String shortName = parts[parts.length - 1];

        // add an entry to the catalog
        final Procedure procedure = db.getProcedures().add(shortName);
        procedure.setId(compiler.getNextProcedureId());
        for (String userName : procedureDescriptor.m_authUsers) {
            final User user = db.getUsers().get(userName);
            if (user == null) {
                throw compiler.new VoltCompilerException("Procedure " + className + " has a user " + userName + " that does not exist");
            }
            final UserRef userRef = procedure.getAuthusers().add(userName);
            userRef.setUser(user);
        }
        for (String groupName : procedureDescriptor.m_authGroups) {
            final Group group = db.getGroups().get(groupName);
            if (group == null) {
                throw compiler.new VoltCompilerException("Procedure " + className + " has a group " + groupName + " that does not exist");
            }
            final GroupRef groupRef = procedure.getAuthgroups().add(groupName);
            groupRef.setGroup(group);
        }
        procedure.setClassname(className);
        // sysprocs don't use the procedure compiler
        procedure.setSystemproc(false);
        procedure.setHasjava(true);

        // get the annotation
        // first try to get one that has been passed from the compiler
        ProcInfoData info = compiler.getProcInfoOverride(shortName);
        // then check for the usual one in the class itself
        // and create a ProcInfo.Data instance for it
        if (info == null) {
            info = new ProcInfoData();
            ProcInfo annotationInfo = procClass.getAnnotation(ProcInfo.class);
            if (annotationInfo != null) {
                info.partitionInfo = annotationInfo.partitionInfo();
                info.partitionParam = annotationInfo.partitionParam();
                info.singlePartition = annotationInfo.singlePartition();
                info.mapInputQuery = annotationInfo.mapInputQuery();
                // info.mapEmitTable = annotationInfo.mapEmitTable();
                info.reduceInputQuery = annotationInfo.reduceInputQuery();
                // info.reduceEmitTable = annotationInfo.reduceEmitTable();
            }
        }
        assert (info != null);

        VoltProcedure procInstance = null;
        try {
            procInstance = (VoltProcedure) procClass.newInstance();
        } catch (InstantiationException e1) {
            e1.printStackTrace();
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        }

        // MapReduce!
        if (ClassUtil.getSuperClasses(procClass).contains(VoltMapReduceProcedure.class)) {
            procedure.setMapreduce(true);

            // The Map input query is required
            // The Reduce input query is optional
            if (info.mapInputQuery == null || info.mapInputQuery.isEmpty()) {
                String msg = "Procedure: " + shortName + " must include a mapInputQuery";
                throw compiler.new VoltCompilerException(msg);
            }

            Database catalog_db = CatalogUtil.getDatabase(procedure);
            VoltMapReduceProcedure<?> mrInstance = (VoltMapReduceProcedure<?>) procInstance;

            // Initialize the MapOutput table
            // Create an invocation of the VoltMapProcedure so that we can grab
            // the MapOutput's schema
            VoltTable.ColumnInfo[] schema = mrInstance.getMapOutputSchema();
            String tableMapOutput = "MAP_" + procedure.getName();
            Table catalog_tbl = catalog_db.getTables().add(tableMapOutput);
            assert (catalog_tbl != null);
            for (int i = 0; i < schema.length; i++) {
                Column catalog_col = catalog_tbl.getColumns().add(schema[i].getName());
                catalog_col.setIndex(i);
                catalog_col.setNullable(i > 0);
                catalog_col.setType(schema[i].getType().getValue());
                if (i == 0)
                    catalog_tbl.setPartitioncolumn(catalog_col);
            } // FOR
            catalog_tbl.setMapreduce(true);
            catalog_tbl.setIsreplicated(false);

            // Initialize the reduceOutput table
            VoltTable.ColumnInfo[] schema_reduceOutput = mrInstance.getReduceOutputSchema();
            String tableReduceOutput = "REDUCE_" + procedure.getName();
            catalog_tbl = catalog_db.getTables().add(tableReduceOutput);
            assert (catalog_tbl != null);
            for (int i = 0; i < schema_reduceOutput.length; i++) {
                Column catalog_col = catalog_tbl.getColumns().add(schema_reduceOutput[i].getName());
                catalog_col.setIndex(i);
                catalog_col.setNullable(i > 0);
                catalog_col.setType(schema_reduceOutput[i].getType().getValue());
                if (i == 0)
                    catalog_tbl.setPartitioncolumn(catalog_col);
            } // FOR
            catalog_tbl.setMapreduce(true);
            catalog_tbl.setIsreplicated(false);

            // Initialize the Procedure catalog object
            procedure.setMapinputquery(info.mapInputQuery);
            procedure.setMapemittable(tableMapOutput);
            procedure.setReduceemittable(tableReduceOutput);
            procedure.setReduceinputquery(info.reduceInputQuery);
        }

        // track if there are any writer stmts
        boolean procHasWriteStmts = false;

        // iterate through the fields and deal with
        Field[] fields = procClass.getFields();
        for (Field f : fields) {
            if (f.getType() == SQLStmt.class) {
                // String fieldName = f.getName();
                SQLStmt stmt = null;

                try {
                    stmt = (SQLStmt) f.get(procInstance);
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }

                // add the statement to the catalog
                Statement catalogStmt = procedure.getStatements().add(f.getName());
               
                // compile the statement
                try {
                    StatementCompiler.compile(compiler, hsql, catalog, db, estimates, catalogStmt, stmt.getText(), info.singlePartition);
                } catch (VoltCompiler.VoltCompilerException e) {
                    e.printStackTrace();
                    String msg = shortName + "." + f.getName() + ": " + e.getMessage();
                    throw compiler.new VoltCompilerException(msg);
                }

                // If this Field has a Prefetchable annotation or the Statement was
                // identified as prefetchable in the project XML, then we will want to
                // set the "prefetchable" flag in the catalog for the Statement + Procedure
                if (f.getAnnotation(Prefetchable.class) != null ||
                    procedureDescriptor.m_prefetchable.contains(catalogStmt.getName())) {
                    catalogStmt.setPrefetchable(true);
                    procedure.setPrefetchable(true);
                }
                // If this Field has a Deferrable annotation or the Statement was
                // identified as deferrable in the project XML, then we will want to
                // set the "deferrable" flag in the catalog for the Statement + Procedure
                if (f.getAnnotation(Deferrable.class) != null) {
                    catalogStmt.setDeferrable(true);
                    procedure.setDeferrable(true);
                }

                // if a single stmt is not read only, then the proc is not read
                // only
                if (catalogStmt.getReadonly() == false)
                    procHasWriteStmts = true;
            }
        }

        // set the read onlyness of a proc
        procedure.setReadonly(procHasWriteStmts == false);

        Class<?>[] paramTypes = populateProcedureParameters(compiler, procClass, procedure);

        // parse the procinfo
        procedure.setSinglepartition(info.singlePartition);
        if (info.partitionInfo != null && info.partitionInfo.isEmpty() == false) {
            parsePartitionInfo(compiler, db, procedure, info.partitionInfo);
            if (procedure.getPartitionparameter() >= paramTypes.length) {
                String msg = "PartitionInfo parameter not a valid parameter for procedure: " + procedure.getClassname();
                throw compiler.new VoltCompilerException(msg);
            }

            // check the type of partition parameter meets our high standards
            Class<?> partitionType = paramTypes[procedure.getPartitionparameter()];
            Class<?>[] validPartitionClzzes = { Long.class, Integer.class, Short.class, Byte.class, long.class, int.class, short.class, byte.class, String.class };
            boolean found = false;
            for (Class<?> candidate : validPartitionClzzes) {
                if (partitionType == candidate)
                    found = true;
            }
            // assume on of the two tests above passes and one fails
            if (!found) {
                String msg = "PartitionInfo parameter must be a String or Number for procedure: " + procedure.getClassname();
                throw compiler.new VoltCompilerException(msg);
            }
        } else {
            procedure.setPartitionparameter(NullProcParameter.PARAM_IDX);
        }
       
        // ProcInfo.partitionParam overrides everything else
        if (info.partitionParam != -1) {
            if (info.partitionParam >= paramTypes.length || info.partitionParam < 0) {
                String msg = "PartitionInfo 'partitionParam' not a valid parameter for procedure: " + procedure.getClassname();
                throw compiler.new VoltCompilerException(msg);
            }
            procedure.setPartitionparameter(info.partitionParam);
        }

        // put the compiled code for this procedure into the jarfile
        // VoltCompiler.addClassToJar(procClass, compiler);
    }
View Full Code Here

     * @param invocation
     * @return
     * @throws Exception
     */
    public int getBasePartition(StoredProcedureInvocation invocation) throws Exception {
        Procedure catalog_proc = this.catalogContext.database.getProcedures().get(invocation.getProcName());
        if (catalog_proc == null) {
            catalog_proc = this.catalogContext.database.getProcedures().getIgnoreCase(invocation.getProcName());
        }
        assert(catalog_proc != null) :
            "Invalid procedure name '" + invocation.getProcName() + "'";
View Full Code Here

     * @param xact
     * @throws Exception
     */
    public void getAllPartitions(final PartitionSet partitions,
                                 final TransactionTrace xact) throws Exception {
        Procedure catalog_proc = xact.getCatalogItem(this.catalogContext.database);
        int base_partition = this.getBasePartition(catalog_proc, xact.getParams(), true);
        partitions.add(base_partition);
        for (QueryTrace query : xact.getQueries()) {
            this.getAllPartitions(partitions,
                                  query.getCatalogItem(this.catalogContext.database),
View Full Code Here

        // get the short name of the class (no package)
        String[] parts = className.split("\\.");
        String shortName = parts[parts.length - 1];

        // add an entry to the catalog
        final Procedure procedure = db.getProcedures().add(shortName);
        procedure.setId(compiler.getNextProcedureId());
        for (String userName : procedureDescriptor.m_authUsers) {
            final User user = db.getUsers().get(userName);
            if (user == null) {
                throw compiler.new VoltCompilerException("Procedure " + className + " has a user " + userName + " that does not exist");
            }
            final UserRef userRef = procedure.getAuthusers().add(userName);
            userRef.setUser(user);
        }
        for (String groupName : procedureDescriptor.m_authGroups) {
            final Group group = db.getGroups().get(groupName);
            if (group == null) {
                throw compiler.new VoltCompilerException("Procedure " + className + " has a group " + groupName + " that does not exist");
            }
            final GroupRef groupRef = procedure.getAuthgroups().add(groupName);
            groupRef.setGroup(group);
        }
        procedure.setClassname(className);
        // sysprocs don't use the procedure compiler
        procedure.setSystemproc(false);
        procedure.setHasjava(false);

        // get the annotation
        // first try to get one that has been passed from the compiler
        ProcInfoData info = compiler.getProcInfoOverride(shortName);
        // then check for the usual one in the class itself
        // and create a ProcInfo.Data instance for it
        if (info == null) {
            info = new ProcInfoData();
            if (procedureDescriptor.m_partitionString != null) {
                info.partitionInfo = procedureDescriptor.m_partitionString;
                info.singlePartition = true;
            }
        }
        assert (info != null);

        // ADD THE STATEMENT

        // add the statement to the catalog
        Statement catalogStmt = procedure.getStatements().add(HStoreConstants.ANON_STMT_NAME);

        // compile the statement
        StatementCompiler.compile(compiler, hsql, catalog, db, estimates, catalogStmt, procedureDescriptor.m_singleStmt, info.singlePartition);

        // if the single stmt is not read only, then the proc is not read only
        boolean procHasWriteStmts = (catalogStmt.getReadonly() == false);

        // set the read onlyness of a proc
        procedure.setReadonly(procHasWriteStmts == false);

        // set procedure parameter types
        CatalogMap<ProcParameter> params = procedure.getParameters();
        CatalogMap<StmtParameter> stmtParams = catalogStmt.getParameters();

        // set the procedure parameter types from the statement parameter types
        int i = 0;
        for (StmtParameter stmtParam : CatalogUtil.getSortedCatalogItems(stmtParams, "index")) {
            // name each parameter "param1", "param2", etc...
            ProcParameter procParam = params.add("param" + String.valueOf(i));
            procParam.setIndex(stmtParam.getIndex());
            procParam.setIsarray(false);
            procParam.setType(stmtParam.getJavatype());
            i++;
        }

        // parse the procinfo
        procedure.setSinglepartition(info.singlePartition);
        if (info.singlePartition) {
            parsePartitionInfo(compiler, db, procedure, info.partitionInfo);
            if (procedure.getPartitionparameter() >= params.size()) {
                String msg = "PartitionInfo parameter not a valid parameter for procedure: " + procedure.getClassname();
                throw compiler.new VoltCompilerException(msg);
            }
        }
    }
View Full Code Here

        args.require(ArgumentsParser.PARAM_CATALOG);

        String proc_name = args.getOptParam(0);
        String stmt_name = args.getOptParam(1);

        Procedure catalog_proc = args.catalog_db.getProcedures().getIgnoreCase(proc_name);
        assert (catalog_proc != null) : "Invalid Procedure Name: " + proc_name;

        Statement catalog_stmt = catalog_proc.getStatements().getIgnoreCase(stmt_name);
        assert (catalog_stmt != null) : "Invalid Statement Name: " + proc_name + "." + stmt_name;

        AbstractPlanNode root = PlanNodeUtil.getRootPlanNodeForStatement(catalog_stmt, false);
        PlanNodeGraph graph = new PlanNodeGraph(root);
View Full Code Here

            assert (obj != null) : "Invalid MultiAttributeCatalogType for " + attributes;
            SINGLETONS.get(catalog_db).put(attributes, obj);

            // Add the parameter object to the procedure's list
            if (obj instanceof MultiProcParameter) {
                Procedure catalog_proc = ((MultiProcParameter) obj).getParent();
                ((MultiProcParameter) obj).setIndex(catalog_proc.getParameters().size());
                catalog_proc.getParameters().add((MultiProcParameter) obj);
            }
        }

        return (obj);
    }
View Full Code Here

TOP

Related Classes of org.voltdb.catalog.Procedure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.