Package org.voltdb.catalog

Examples of org.voltdb.catalog.Index


     * @param catalogTable
     * @return An ordered list of the primary key columns
     */
    public static Collection<Column> getPrimaryKeyColumns(Table catalogTable) {
        Collection<Column> columns = new ArrayList<Column>();
        Index catalog_idx = null;
        try {
            catalog_idx = CatalogUtil.getPrimaryKeyIndex(catalogTable);
        } catch (Exception ex) {
            // IGNORE
            return (columns);
        }
        assert(catalog_idx != null);

        for (ColumnRef catalog_col_ref : getSortedCatalogItems(catalog_idx.getColumns(), "index")) {
            columns.add(catalog_col_ref.getColumn());
        }
        return (columns);
    }
View Full Code Here


            ConstraintType const_type = ConstraintType.get(catalog_const.getType());
            if (const_type == ConstraintType.FOREIGN_KEY && include_fkeys == false) continue;

            // Primary Keys / Unique Constraints
            if (const_type == ConstraintType.PRIMARY_KEY || const_type == ConstraintType.UNIQUE) {
                Index catalog_idx = catalog_const.getIndex();
                IndexType idx_type = IndexType.get(catalog_idx.getType());
                String idx_suffix = idx_type.getSQLSuffix();

                ret += add + spacer +
                       (!idx_suffix.isEmpty() ? "CONSTRAINT " + catalog_const.getTypeName() + " " : "") +
                       (const_type == ConstraintType.PRIMARY_KEY ? "PRIMARY KEY" : "UNIQUE") + " (";

                String col_add = "";
                for (ColumnRef catalog_colref : CatalogUtil.getSortedCatalogItems(catalog_idx.getColumns(), "index")) {
                    ret += col_add + catalog_colref.getColumn().getTypeName();
                    col_add = ", ";
                } // FOR
                ret += ")";
                skip_indexes.add(catalog_idx);

            // Foreign Key
            } else if (const_type == ConstraintType.FOREIGN_KEY) {
                Table catalog_fkey_tbl = catalog_const.getForeignkeytable();
                String col_add = "";
                String our_columns = "";
                String fkey_columns = "";
                for (ColumnRef catalog_colref : catalog_const.getForeignkeycols()) {
                    // The name of the ColumnRef is the column in our base table
                    Column our_column = catalog_tbl.getColumns().getIgnoreCase(catalog_colref.getTypeName());
                    assert(our_column != null);
                    our_columns += col_add + our_column.getTypeName();

                    Column fkey_column = catalog_colref.getColumn();
                    assert(fkey_column != null);
                    fkey_columns += col_add + fkey_column.getTypeName();

                    col_add = ", ";
                }
                ret += add + spacer + "CONSTRAINT " + catalog_const.getTypeName() + " " +
                                      "FOREIGN KEY (" + our_columns + ") " +
                                      "REFERENCES " + catalog_fkey_tbl.getTypeName() + " (" + fkey_columns + ")";
            }
            skip_constraints.add(catalog_const);
        }
        ret += "\n);\n";

        // All other Indexes
        for (Index catalog_idx : catalog_tbl.getIndexes()) {
            if (skip_indexes.contains(catalog_idx)) continue;

            ret += "CREATE INDEX " + catalog_idx.getTypeName() +
                   " ON " + catalog_tbl.getTypeName() + " (";
            add = "";
            for (ColumnRef catalog_colref : CatalogUtil.getSortedCatalogItems(catalog_idx.getColumns(), "index")) {
                ret += add + catalog_colref.getColumn().getTypeName();
                add = ", ";
            }
            ret += ");\n";
        }
View Full Code Here

                LOG.error(String.format("Failed to find index columns for table '%s'\n%s",
                                        catalog_tbl.getName(), StringUtil.formatMaps(m)));
                throw new Exception(String.format("No columns selected for index on %s", viewName));
            }
            String idxName = "SYS_IDX_" + viewName;
            Index virtual_idx = virtual_tbl.getIndexes().get(idxName);
            if (virtual_idx == null) {
                virtual_idx = virtual_tbl.getIndexes().add(idxName);
            }
            virtual_idx.getColumns().clear();
           
            IndexType idxType = (indexColumns.size() == 1 ? IndexType.HASH_TABLE : IndexType.BALANCED_TREE);
            virtual_idx.setType(idxType.getValue());
            i = 0;
            for (Column catalog_col : indexColumns) {
                ColumnRef cref = virtual_idx.getColumns().add(catalog_col.getTypeName());
                cref.setColumn(catalog_col);
                cref.setIndex(i++);
            } // FOR
           
            if (debug.val)
View Full Code Here

        // if no path is a sequential scan, call a subroutine for that
        if (path.index == null)
            return getScanAccessPlanForTable(table, path.otherExprs);

        // now assume this will be an index scan and get the relevant index
        Index index = path.index;

        // build the list of search-keys for the index in question
        IndexScanPlanNode scanNode = new IndexScanPlanNode(m_context, PlanAssembler.getNextPlanNodeId());
        List<AbstractExpression> searchKeys = scanNode.getSearchKeyExpressions();
        for (AbstractExpression expr : path.indexExprs) {
            AbstractExpression expr2 = ExpressionUtil.getOtherTableExpression(expr, table.getTypeName());
            assert(expr2 != null);
            searchKeys.add(expr2);
        }

        // create the IndexScanNode with all its metadata
        scanNode.setKeyIterate(path.keyIterate);
        scanNode.setLookupType(path.lookupType);
        scanNode.setSortDirection(path.sortDirection);
        scanNode.setTargetTableName(table.getTypeName());
        scanNode.setTargetTableAlias(table.getTypeName());
        scanNode.setTargetIndexName(index.getTypeName());
        scanNode.setEndExpression(ExpressionUtil.combine(path.endExprs));
        scanNode.setPredicate(ExpressionUtil.combine(path.otherExprs));

        AbstractPlanNode rootNode = scanNode;
View Full Code Here

            updateColumnsRefs((Table) src_view.getParent(), src_view.getGroupbycols(), (Table) dest_view.getParent(), dest_view.getGroupbycols());

        // Index
        } else if (src_item instanceof Index) {
            // ColumnRefs
            Index src_idx = (Index) src_item;
            Index dest_idx = (Index) clone;
            updateColumnsRefs((Table) src_idx.getParent(), src_idx.getColumns(), (Table) dest_idx.getParent(), dest_idx.getColumns());

        // Constraint
        } else if (src_item instanceof Constraint) {
            // ColumnRefs
            Constraint src_cons = (Constraint) src_item;
            Constraint dest_cons = (Constraint) clone;

            Table src_fkey_tbl = src_cons.getForeignkeytable();
            if (src_fkey_tbl != null) {
                Database dest_db = (Database) dest_cons.getParent().getParent();
                Table dest_fkey_tbl = dest_db.getTables().get(src_fkey_tbl.getName());
                if (dest_fkey_tbl != null) {
                    dest_cons.setForeignkeytable(dest_fkey_tbl);
                    for (ColumnRef src_cref : ((Constraint) src_item).getForeignkeycols()) {
                        CatalogCloner.clone(src_cref, dest_catalog);

                        // Correct what it's pointing to
                        ColumnRef dest_colref = dest_cons.getForeignkeycols().get(src_cref.getName());
                        assert (dest_colref != null);
                        dest_colref.setColumn(dest_fkey_tbl.getColumns().get(src_cref.getColumn().getName()));
                    } // FOR
                }
            }

            // Important: We have to add ConstraintRefs to Columns *after* we add the columns
            Table src_tbl = (Table) src_cons.getParent();
            Table dest_tbl = (Table) dest_cons.getParent();
            for (Column src_col : src_tbl.getColumns()) {
                Column dest_col = dest_tbl.getColumns().get(src_col.getName());
                assert (dest_col != null);
                for (ConstraintRef src_conref : src_col.getConstraints()) {
                    if (!src_conref.getConstraint().equals(src_cons))
                        continue;
                    CatalogCloner.clone(src_conref, dest_catalog);

                    // Correct what it's pointing to
                    ConstraintRef dest_conref = dest_col.getConstraints().get(src_conref.getName());
                    assert (dest_conref != null);
                    // System.out.println("dest_tbl: " + dest_tbl);
                    // System.out.println("dest_tbl.getConstraints(): " +
                    // CatalogUtil.debug(dest_tbl.getConstraints()));
                    // System.out.println("src_confref: " + src_conref);
                    // System.out.println("src_confref.getConstraint(): " +
                    // src_conref.getConstraint());
                    dest_conref.setConstraint(dest_tbl.getConstraints().get(src_conref.getConstraint().getName()));
                } // FOR
            } // FOR

            Index src_index = src_cons.getIndex();
            if (src_index != null) {
                Index dest_index = dest_tbl.getIndexes().get(src_index.getName());
                dest_cons.setIndex(dest_index);
            }

        // StmtParameter
        } else if (src_item instanceof StmtParameter) {
View Full Code Here

            m[0].put("project", ((Database)catalog_obj).getProject());
        }
       
        // INDEX
        if (catalog_obj instanceof Index) {
            Index catalog_idx = (Index)catalog_obj;
            Collection<Column> cols = CatalogUtil.getColumns(CatalogUtil.getSortedCatalogItems(catalog_idx.getColumns(), "index"));
            m[0].put("columns", CatalogUtil.getDisplayNames(cols));
        }
        // CONSTRAINT
        else if (catalog_obj instanceof Constraint) {
            Constraint catalog_const = (Constraint)catalog_obj;
            Collection<Column> cols = null;
            if (catalog_const.getType() == ConstraintType.FOREIGN_KEY.getValue()) {
                cols = CatalogUtil.getColumns(catalog_const.getForeignkeycols());   
            } else {
                Index catalog_idx = catalog_const.getIndex();
                cols = CatalogUtil.getColumns(catalog_idx.getColumns());
            }
            m[0].put("columns", CatalogUtil.getDisplayNames(cols));
        }
        // COLUMN
        else if (catalog_obj instanceof Column) {
View Full Code Here

                int idx = table_idxs.get(new_catalog_tbl);
                table_idxs.put(new_catalog_tbl, idx + 1);

                // TODO: Support different index types
                String idx_name = "IDX_" + new_catalog_tbl.getName() + "_DESIGNER_" + idx;
                Index new_catalog_index = catalog_tbl.getIndexes().add(idx_name);
                new_catalog_index.setType(IndexType.HASH_TABLE.getValue());

                // need to set other index data here (column, etc)
                for (int i = 0, cnt = index.getColumns().size(); i < cnt; i++) {
                    Column catalog_col = index.getColumns().get(i);
                    Column new_catalog_col = new_catalog_tbl.getColumns().get(catalog_col.getName());
                    ColumnRef cref = new_catalog_index.getColumns().add(new_catalog_col.getName());
                    cref.setColumn(new_catalog_col);
                    cref.setIndex(i);
                } // FOR
            } // FOR
        } // FOR
View Full Code Here

                    Table catalog_tbl = catalog_db.getTables().get(table_name);
                    assert(catalog_tbl != null) :
                        String.format("Invalid table '%s' extracted from %s. Valid tables: %s",
                                      table_name, element, CatalogUtil.getDisplayNames(catalog_db.getTables()));
                   
                    Index catalog_idx = catalog_tbl.getIndexes().get(index_name);
                    assert(catalog_idx != null) :
                        String.format("Invalid index '%s.%s' extracted from %s. Valid indexes: %s",
                                table_name, index_name, element,
                                CatalogUtil.getDisplayNames(catalog_tbl.getIndexes()));
                    found.add(catalog_idx);
View Full Code Here

                    Column target_col = (Column)ctypes[i];
                    Table target_tbl = target_col.getParent();

                    // Find what index it's using
                    // This is a rough approximation...
                    Index target_idx = null;
                    for (Index idx : indexes) {
                        if (idx.getParent().equals(target_tbl)) {
                            for (Column col : CatalogUtil.getColumns(idx.getColumns())) {
                                if (col.equals(target_col)) {
                                    target_idx = idx;
View Full Code Here

                // IndexScanPlanNode
                if (node instanceof IndexScanPlanNode) {
                    IndexScanPlanNode cast_node = (IndexScanPlanNode) node;
                    Table catalog_tbl = catalog_db.getTables().get(cast_node.getTargetTableName());
                    assert (catalog_tbl != null);
                    Index catalog_idx = catalog_tbl.getIndexes().get(cast_node.getTargetIndexName());
                    assert (catalog_idx != null);

                    // Search Key Expressions
                    List<ColumnRef> index_cols = CatalogUtil.getSortedCatalogItems(catalog_idx.getColumns(), "index");
                    for (int i = 0, cnt = cast_node.getSearchKeyExpressions().size(); i < cnt; i++) {
                        AbstractExpression index_exp = cast_node.getSearchKeyExpressions().get(i);
                        Column catalog_col = index_cols.get(i).getColumn();
                        if (debug.val)
                            LOG.debug("[" + i + "] " + catalog_col);
View Full Code Here

TOP

Related Classes of org.voltdb.catalog.Index

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.