Package org.voltdb.catalog

Examples of org.voltdb.catalog.Column


        this.has_preprocessed = true;
    }

    @Override
    public void process(Database catalog_db, TransactionTrace xact) throws Exception {
        final Column catalog_col = this.getCatalogItem(catalog_db);
        final Table catalog_tbl = (Table) catalog_col.getParent();
        // For each query, check whether they are going to our table
        // If so, then we need to update our statistics
        int col_index = catalog_col.getIndex();
        for (QueryTrace query : xact.getQueries()) {
            Statement catalog_stmt = query.getCatalogItem(catalog_db);
            QueryType query_type = QueryType.get(catalog_stmt.getQuerytype());
            // For now we only examine the tuples as they are being inserted
            // into the table
View Full Code Here


        HashMap<Column, ArrayList<AbstractExpression>> eqColumns = new HashMap<Column, ArrayList<AbstractExpression>>();
        HashMap<Column, ArrayList<AbstractExpression>> gtColumns = new HashMap<Column, ArrayList<AbstractExpression>>();
        HashMap<Column, ArrayList<AbstractExpression>> ltColumns = new HashMap<Column, ArrayList<AbstractExpression>>();
        for (AbstractExpression expr : exprs)
        {
            Column col = getColumnForFilterExpression(table, expr);
            if (col != null)
            {
                if (expr.getExpressionType() == ExpressionType.COMPARE_EQUAL)
                {
                    if (eqColumns.containsKey(col) == false)
                        eqColumns.put(col, new ArrayList<AbstractExpression>());
                    eqColumns.get(col).add(expr);
                }
                else if ((expr.getExpressionType() == ExpressionType.COMPARE_GREATERTHAN) ||
                        (expr.getExpressionType() == ExpressionType.COMPARE_GREATERTHANOREQUALTO))
                {
                    if (gtColumns.containsKey(col) == false)
                        gtColumns.put(col, new ArrayList<AbstractExpression>());
                    gtColumns.get(col).add(expr);
                }
                else if ((expr.getExpressionType() == ExpressionType.COMPARE_LESSTHAN) ||
                        (expr.getExpressionType() == ExpressionType.COMPARE_LESSTHANOREQUALTO))
                {
                    if (ltColumns.containsKey(col) == false)
                        ltColumns.put(col, new ArrayList<AbstractExpression>());
                    ltColumns.get(col).add(expr);
                }
                else
                {
                    retval.otherExprs.add(expr);
                }
            }
            else
            {
                retval.otherExprs.add(expr);
            }
        }

        // See if we can use index scan for ORDER BY.
        // The only scenario where we can use index scan is when the ORDER BY
        // columns is a subset of the tree index columns, in the same order from
        // left to right. It also requires that all columns are ordered in the
        // same direction. For example, if a table has a tree index of columns
        // A, B, C, then 'ORDER BY A, B', 'ORDER BY A DESC, B DESC, C DESC'
        // work, but not 'ORDER BY A, C' or 'ORDER BY A, B DESC'.
        if (indexScannable && m_parsedStmt instanceof ParsedSelectStmt) {
            ParsedSelectStmt parsedSelectStmt = (ParsedSelectStmt) m_parsedStmt;
            if (!parsedSelectStmt.orderColumns.isEmpty()) {
                List<ColumnRef> sortedColumns = CatalogUtil.getSortedCatalogItems(index.getColumns(), "index");
                Iterator<ColumnRef> colRefIter = sortedColumns.iterator();

                boolean ascending = parsedSelectStmt.orderColumns.get(0).ascending;
                for (ParsedColInfo colInfo : parsedSelectStmt.orderColumns) {
                    if (!colRefIter.hasNext()) {
                        retval.sortDirection = SortDirectionType.INVALID;
                        break;
                    }

                    ColumnRef colRef = colRefIter.next();
                    if (colInfo.tableName.equals(table.getTypeName()) &&
                        colInfo.columnName.equals(colRef.getColumn().getTypeName()) &&
                        colInfo.ascending == ascending) {

                        if (ascending)
                            retval.sortDirection = SortDirectionType.ASC;
                        else
                            retval.sortDirection = SortDirectionType.DESC;

                        retval.use = IndexUseType.INDEX_SCAN;
                    } else {
                        retval.sortDirection = SortDirectionType.INVALID;
                        break;
                    }
                }
            }
        }

        // cover as much of the index as possible with expressions that use
        // index columns
        for (ColumnRef colRef : CatalogUtil.getSortedCatalogItems(index.getColumns(), "index")) {
            Column col = colRef.getColumn();
            if (eqColumns.containsKey(col) && (eqColumns.get(col).size() >= 0)) {
                AbstractExpression expr = eqColumns.get(col).remove(0);
                retval.indexExprs.add(expr);
                retval.endExprs.add(expr);
            } else {
View Full Code Here

            (expr.getExpressionType() != ExpressionType.COMPARE_LESSTHANOREQUALTO))
        {
            return null;
        }

        Column indexedColumn = getColumnForFilterExpressionRecursive(table, expr);
        if (indexedColumn == null)
            return indexedColumn;

        // EE index comparators do not support expressions on the key.
        // The indexed column must not be part of a sub-expression.
View Full Code Here

            return getTableColumn(table, tve.getColumnName());
        }

        // recursive step
        //
        Column leftCol = getColumnForFilterExpressionRecursive(table, expr.getLeft());
        Column rightCol = getColumnForFilterExpressionRecursive(table, expr.getRight());

        assert(leftCol == null ||
               getTableColumn(table, leftCol.getTypeName()) != null);

        assert(rightCol == null ||
               getTableColumn(table, rightCol.getTypeName()) != null);

        // Left and right columns must not be from the same table,
        // e.g. where t.a = t.b is really a self join.
        if (leftCol != null && rightCol != null) {
            return null;
View Full Code Here

                    protected void populate_children(AbstractTreeWalker.Children<Column> children, Column element) {
                        // For the current element, we need to look at it's
                        // parents in the
                        // DependencyGraph and select the one that our foreign
                        // key column points to
                        Column catalog_fkey_col = CatalogUtil.getForeignKeyParent(element);
                        if (catalog_fkey_col != null)
                            children.addAfter(catalog_fkey_col);
                    }

                    @Override
View Full Code Here

        List<Column> ret = new ArrayList<Column>();
        String key = CatalogKey.createKey(catalog_col);
        for (String ancestor_key : this.column_ancestors.get(key)) {
            // If this table is missing from the catalog, then we want to stop
            // the ancestor list
            Column ancestor_col = CatalogKey.getFromKey(catalog_db, ancestor_key, Column.class);
            if (ancestor_col == null)
                break;
            // Otherwise, add it to our list
            ret.add(ancestor_col);
        } // FOR
View Full Code Here

        Database catalog_db = (Database) catalog_col.getParent().getParent();
        Set<Column> ret = new HashSet<Column>();
        String key = CatalogKey.createKey(catalog_col);
        if (this.column_descendants.containsKey(key)) {
            for (String dependent_key : this.column_descendants.get(key)) {
                Column dependent_col = CatalogKey.getFromKey(catalog_db, dependent_key, Column.class);
                // If the table is missing, that's ok...
                if (dependent_col != null)
                    ret.add(dependent_col);
            } // FOR
        }
View Full Code Here

            assert(catalog_view.getGroupbycols().isEmpty() == false) :
                String.format("Missing vertical partitioning columns in %s when trying to process %s\n%s\nCACHED: %s",
                              catalog_view.fullName(), catalog_stmt.fullName(), CatalogUtil.debug(catalog_view), CatalogUtil.debug(this.vp_columns.get(catalog_tbl)));
            Collection<Column> view_cols = CatalogUtil.getColumns(catalog_view.getGroupbycols());
            assert(view_cols.isEmpty() == false) : "Missing vertical partitioning columns in " + catalog_view.fullName() + " when trying to process " + catalog_stmt.fullName();
            Column partitioning_col = catalog_tbl.getPartitioncolumn();
            assert(partitioning_col != null);

            // The current vertical partition is valid for this query if all the
            // following are true:
            // (1) The partitioning_col is in output_cols
            // (2) The partitioning_col is *not* in the predicate_cols
            // (3) At least one of the vertical partition's columns is in
            // predicate_cols
            if (debug.val) {
                Map<String, Object> m = new LinkedHashMap<String, Object>();
                m.put("VerticalP", catalog_view.getName());
                m.put("Partitioning Col", partitioning_col.fullName());
                m.put("Output Cols", output_cols);
                m.put("Statement Cols", stmt_cols);
                m.put("VerticalP Cols", view_cols);
                LOG.debug(String.format("Checking whether %s can use vertical partition for %s\n%s", catalog_stmt.fullName(), catalog_tbl.getName(), StringUtil.formatMaps(m)));
            }
View Full Code Here

        for (Table catalog_tbl : catalog_db.getTables()) {
            Table clone_tbl = clone_db.getTables().get(catalog_tbl.getName());
            for (Column catalog_col : catalog_tbl.getColumns()) {
                if (catalog_col instanceof MultiColumn) {
                    MultiColumn mc = (MultiColumn) catalog_col;
                    Column clone_cols[] = new Column[mc.size()];
                    for (int i = 0; i < clone_cols.length; i++) {
                        clone_cols[i] = clone_tbl.getColumns().get(mc.get(i).getName());
                    } // FOR

                    MultiColumn clone_mc = MultiColumn.get(clone_cols);
View Full Code Here

            // CatalogUtil.clone(src_cons, dest_catalog);
            // } // FOR

            // Partitioning Column
            if (src_tbl.getPartitioncolumn() != null) {
                Column src_part_col = src_tbl.getPartitioncolumn();
                Column dest_part_col = null;

                // Special Case: Replicated Column Marker
                if (src_part_col instanceof ReplicatedColumn) {
                    dest_part_col = ReplicatedColumn.get(dest_tbl);
                // Special Case: MultiColumn
                } else if (src_part_col instanceof MultiColumn) {
                    MultiColumn mc = (MultiColumn) src_part_col;
                    Column dest_cols[] = new Column[mc.size()];
                    for (int i = 0; i < dest_cols.length; i++) {
                        dest_cols[i] = dest_tbl.getColumns().get(mc.get(i).getName());
                    } // FOR
                    dest_part_col = MultiColumn.get(dest_cols);

                } else {
                    dest_part_col = dest_tbl.getColumns().get(src_part_col.getName());
                }
                assert (dest_part_col != null) : "Missing partitioning column " + CatalogUtil.getDisplayName(src_part_col);
                dest_tbl.setPartitioncolumn(dest_part_col);
            }
        // MaterializedViewInfo
        } else if (src_item instanceof MaterializedViewInfo) {
            // ColumnRefs
            MaterializedViewInfo src_view = (MaterializedViewInfo) src_item;
            MaterializedViewInfo dest_view = (MaterializedViewInfo) clone;
            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);
View Full Code Here

TOP

Related Classes of org.voltdb.catalog.Column

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.