Package com.foundationdb.ais.model

Examples of com.foundationdb.ais.model.Table


    /** ChangeSets for all tables affected by {@code newIndexes}. */
    private static List<ChangeSet> buildChangeSets(AkibanInformationSchema ais, Collection<? extends Index> stubIndexes) {
        HashMultimap<Integer,Index> tableToIndexes = HashMultimap.create();
        for(Index stub : stubIndexes) {
            // Re-look index up as external API previously only relied on names
            Table table = ais.getTable(stub.getIndexName().getFullTableName());
            String stubName = stub.getIndexName().getName();
            final Index index;
            switch(stub.getIndexType()) {
                case TABLE: index = table.getIndexIncludingInternal(stubName); break;
                case FULL_TEXT: index = table.getFullTextIndex(stubName); break;
                case GROUP: index = table.getGroup().getIndex(stubName); break;
                default:
                    throw new IllegalStateException(stub.getIndexType().toString());
            }
            assert (index != null) : stub;
            for(Integer tid : index.getAllTableIDs()) {
                tableToIndexes.put(tid, index);
            }
        }
        List<ChangeSet> changeSets = new ArrayList<>();
        for(Entry<Integer, Collection<Index>> entry : tableToIndexes.asMap().entrySet()) {
            Table table = ais.getTable(entry.getKey());
            ChangeSet.Builder builder = ChangeSet.newBuilder();
            builder.setChangeLevel(ChangeLevel.INDEX.name());
            builder.setTableId(table.getTableId());
            builder.setOldSchema(table.getName().getSchemaName());
            builder.setOldName(table.getName().getTableName());
            builder.setNewSchema(table.getName().getSchemaName());
            builder.setNewName(table.getName().getTableName());
            for(Index index : entry.getValue()) {
                TableChanges.IndexChange.Builder indexChange = TableChanges.IndexChange.newBuilder();
                indexChange.setChange(ChangeSetHelper.createAddChange(index.getIndexName().getName()));
                indexChange.setIndexType(index.getIndexType().name());
                builder.addIndexChange(indexChange);
View Full Code Here


            cs.setChangeLevel(validator.getFinalChangeLevel().name());
            cs.setTableId(tid);
            final TableName oldName, newName;
            ChangedTableDescription desc = findByID(validator.getState().descriptions, tid);
            if(desc == null) {
                Table table = newAIS.getTable(tid);
                oldName = newName = table.getName();
            } else {
                oldName = desc.getOldName();
                newName = desc.getNewName();
            }
            cs.setOldSchema(oldName.getSchemaName());
            cs.setOldName(oldName.getTableName());
            cs.setNewSchema(newName.getSchemaName());
            cs.setNewName(newName.getTableName());

            Table oldTable = oldAIS.getTable(tid);
            Table newTable = newAIS.getTable(tid);

            Set<String> handledIndexes = new HashSet<>();
            // Only the table being directly modified has explicit change list
            if(tid == changedTableID) {
                // Full column information needed to create projects for new row
                for(TableChange cc : validator.getState().columnChanges) {
                    cs.addColumnChange(ChangeSetHelper.createFromTableChange(cc));
                }
                for(TableChange ic : validator.getState().tableIndexChanges) {
                    TableChanges.IndexChange.Builder builder = TableChanges.IndexChange.newBuilder();
                    builder.setIndexType(IndexType.TABLE.name());
                    builder.setChange(ChangeSetHelper.createFromTableChange(ic));
                    cs.addIndexChange(builder);
                    if(ic.getNewName() != null) {
                        handledIndexes.add(ic.getNewName());
                    }
                }
            }

            Collection<TableIndex> additionalIndexes = Collections.emptyList();
            if(desc != null) {
                additionalIndexes = findTableIndexesToBuild(desc, oldTable, newTable);
            }

            for(TableIndex index : additionalIndexes) {
                if(!handledIndexes.contains(index.getIndexName().getName())) {
                    TableChanges.IndexChange.Builder builder = TableChanges.IndexChange.newBuilder();
                    builder.setIndexType(index.getIndexType().name());
                    String name = index.getIndexName().getName();
                    builder.setChange(ChangeSetHelper.createModifyChange(name, name));
                    cs.addIndexChange(builder);
                }
            }

            Group newGroup = newTable.getGroup();
            for(String indexName : validator.getState().dataAffectedGI.keySet()) {
                GroupIndex index = newGroup.getIndex(indexName);
                if(newTable.getGroupIndexes().contains(index)) {
                    TableChanges.IndexChange.Builder builder = TableChanges.IndexChange.newBuilder();
                    builder.setIndexType(index.getIndexType().name());
                    builder.setChange(ChangeSetHelper.createModifyChange(indexName, indexName));
                    cs.addIndexChange(builder);
                }
            }

            if(desc != null) {
                for(TableName seqName : desc.getDroppedSequences()) {
                    cs.addIdentityChange(ChangeSetHelper.createDropChange(seqName.getTableName()));
                }
                for(String identityCol : desc.getIdentityAdded()) {
                    Column c = newTable.getColumn(identityCol);
                    assert (c != null) && (c.getIdentityGenerator() != null) : c;
                    cs.addIdentityChange(ChangeSetHelper.createAddChange(c.getIdentityGenerator().getSequenceName().getTableName()));
                }
            }
View Full Code Here

        } else if (inputRowType instanceof HKeyRowType) {
            Schema schema = outputRowType.schema();
            inputTableType = schema.tableRowType(inputRowType.hKey().table());
        }
        assert inputTableType != null : inputRowType;
        Table inputTable = inputTableType.table();
        Table outputTable = outputRowType.table();
        ArgumentValidation.isSame("inputTable.getGroup()",
                                  inputTable.getGroup(),
                                  "outputTable.getGroup()",
                                  outputTable.getGroup());
        this.keepInput = flag == API.InputPreservationOption.KEEP_INPUT;
        this.inputOperator = inputOperator;
        this.group = group;
        this.inputRowType = inputRowType;
        this.outputRowType = outputRowType;
        this.limit = limit;
        this.commonAncestor = commonAncestor(inputTable, outputTable);
        switch (outputTable.getDepth() - commonAncestor.getDepth()) {
            case 0:
                branchRootOrdinal = -1;
                break;
            case 1:
                branchRootOrdinal = ordinal(outputTable);
                break;
            default:
                branchRootOrdinal = -1;
                ArgumentValidation.isTrue("false", false);
                break;
        }
        // branchRootOrdinal = -1 means that outputTable is an ancestor of inputTable. In this case, inputPrecedesBranch
        // is false. Otherwise, branchRoot's parent is the common ancestor. Find inputTable's ancestor that is also
        // a child of the common ancestor. Then compare these ordinals to determine whether input precedes branch.
        if (this.branchRootOrdinal == -1) {
            // output type is ancestor of input row type
            this.inputPrecedesBranch = false;
        } else if (inputTable == commonAncestor) {
            // input row type is parent of output type
            this.inputPrecedesBranch = true;
        } else {
            // neither input type nor output type is the common ancestor
            Table ancestorOfInputAndChildOfCommon = inputTable;
            while (ancestorOfInputAndChildOfCommon.getParentTable() != commonAncestor) {
                ancestorOfInputAndChildOfCommon = ancestorOfInputAndChildOfCommon.getParentTable();
            }
            this.inputPrecedesBranch = ordinal(ancestorOfInputAndChildOfCommon) < branchRootOrdinal;
        }
    }
View Full Code Here

    // For use by this class

    private static Table commonAncestor(Table inputTable, Table outputTable)
    {
        int minLevel = min(inputTable.getDepth(), outputTable.getDepth());
        Table inputAncestor = inputTable;
        while (inputAncestor.getDepth() > minLevel) {
            inputAncestor = inputAncestor.getParentTable();
        }
        Table outputAncestor = outputTable;
        while (outputAncestor.getDepth() > minLevel) {
            outputAncestor = outputAncestor.getParentTable();
        }
        while (inputAncestor != outputAncestor) {
            inputAncestor = inputAncestor.getParentTable();
            outputAncestor = outputAncestor.getParentTable();
        }
        return outputAncestor;
    }
View Full Code Here

            return false;
        }
        List<Table> tableList = new ArrayList<>();
        tableList.add(table.getGroup().getRoot());
        while(!tableList.isEmpty()) {
            Table aTable = tableList.remove(tableList.size() - 1);
            if(aTable != table) {
                if(aTable.rowDef().getTableStatus().getRowCount(session) > 0) {
                    return false;
                }
            }
            if((aTable != table) || !descendants) {
                for(Join join : aTable.getChildJoins()) {
                    tableList.add(join.getChild());
                }
            }
        }
        return true;
View Full Code Here

    @Override
    public void truncateTable(final Session session, final int tableId, final boolean descendants)
    {
        logger.trace("truncating tableId={}", tableId);
        final AkibanInformationSchema ais = schemaManager.getAis(session);
        final Table table = ais.getTable(tableId);

        if(canFastTruncate(session, table, descendants)) {
            store.truncateGroup(session, table.getGroup());
            // All other tables in the group have no rows. Only need to truncate this table.
            for(TableListener listener : listenerService.getTableListeners()) {
                listener.onTruncate(session, table, true);
            }
            return;
View Full Code Here

        // Execution interface

        Execution(QueryContext context, QueryBindingsCursor bindingsCursor)
        {
            super(context, bindingsCursor);
            Table table = index.rootMostTable();
            this.cursor = adapter(table).newIndexCursor(context, index, indexKeyRange, ordering, scanSelector, false);
        }
View Full Code Here

            validateGroup (ais, group, output);
        }
    }
   
    private void validateGroup (AkibanInformationSchema ais, Group group, AISValidationOutput output) {
        Table root = null;
        for (Table table : ais.getTables().values()) {
            if (table.getGroup() == group && table.isRoot()) {
                if (root == null) {
                    root = table;
                } else {
                    output.reportFailure(new AISValidationFailure (
                            new GroupHasMultipleRootsException(group.getName(), root.getName(), table.getName())));
                }
            }
        }
    }
View Full Code Here

    public void validate(AkibanInformationSchema ais, AISValidationOutput output) {
        for(Table t : ais.getTables().values()) {
            if(t.getOrdinal() == null) {
                output.reportFailure(new AISValidationFailure(noOrdinal(t)));
            } else {
                Table p = t.getParentTable();
                if((p != null) && (p.getOrdinal() != null) && (t.getOrdinal() < p.getOrdinal())) {
                    output.reportFailure(new AISValidationFailure(lowerOrdinal(p, t)));
                }
            }
        }
    }
View Full Code Here

            tableRowType = ((Schema) inputRowType.schema()).tableRowType(((HKeyRowType) inputRowType).hKey().table());
        } else {
            ArgumentValidation.isTrue("invalid rowType", false);
            tableRowType = null;
        }
        Table inputTable = tableRowType.table();
        this.ancestors = new ArrayList<>(outputRowTypes.size());
        List<TableRowType> branchOutputRowTypes = null;
        Table branchRoot = null;
        boolean outputInputTable = false;
        for (TableRowType outputRowType : outputRowTypes) {
            if (outputRowType == tableRowType) {
                ArgumentValidation.isTrue("flag == API.InputPreservationOption.DISCARD_INPUT",
                                          flag == API.InputPreservationOption.DISCARD_INPUT);
                outputInputTable = true;
            } else if (outputRowType.ancestorOf(tableRowType)) {
                ancestors.add(outputRowType.table());
            } else if (tableRowType.ancestorOf(outputRowType)) {
                if (branchOutputRowTypes == null)
                    branchOutputRowTypes = new ArrayList<>();
                branchOutputRowTypes.add(outputRowType);
                if (branchRoot != inputTable) {
                    // Get immediate child of input above desired output.
                    Table childTable = outputRowType.table();
                    while (true) {
                        Table parentTable = childTable.getParentTable();
                        if (parentTable ==  inputTable) break;
                        childTable = parentTable;
                    }
                    if (branchRoot != childTable) {
                        if (branchRoot == null) {
View Full Code Here

TOP

Related Classes of com.foundationdb.ais.model.Table

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.