Package com.foundationdb.server.error

Examples of com.foundationdb.server.error.NoSuchColumnException


    }

    protected Column getColumn (Table table, String field) {
        Column column = table.getColumn(field);
        if (column == null) {
            throw new NoSuchColumnException(field);
        }
        return column;
    }
View Full Code Here


                throw new NoSuchTableException(parts[0], parts[1]);
            }
        }
        Column column = columnar.getColumn(parts[2]);
        if(column == null) {
            throw new NoSuchColumnException(String.format("%s.%s.%s", parts[0], parts[1], parts[2]));
        }
        output.putString(column.getType().toStringConcise(false), null);
    }
View Full Code Here

            if (joinNode.getUsingClause() != null) {
                for (ResultColumn rc : joinNode.getUsingClause()) {
                    String columnName = rc.getName();
                    ColumnBinding leftBinding = getColumnBinding(fromLeft, columnName);
                    if (leftBinding == null)
                        throw new NoSuchColumnException(columnName, rc);
                    ColumnBinding rightBinding = getColumnBinding(fromRight, columnName);
                    if (rightBinding == null)
                        throw new NoSuchColumnException(columnName, rc);
                    conditions = addJoinEquality(conditions,
                                                 columnName, leftBinding, rightBinding,
                                                 nodeFactory, parserContext);
                    BindingContext bindingContext = getBindingContext();
                    // USING is tricky case, since join columns do not repeat in expansion.
View Full Code Here

        String columnName = columnReference.getColumnName();
        if (columnReference.getTableNameNode() != null) {
            FromTable fromTable = findFromTable(columnReference.getTableNameNode());
            columnBinding = getColumnBinding(fromTable, columnName);
            if (columnBinding == null)
                throw new NoSuchColumnException(columnName, columnReference);
        }
        else {
            if (resultColumnsAvailable(getBindingContext().resultColumnsAvailableContext,
                                       columnReference)) {
                ResultColumnList resultColumns = getBindingContext().resultColumns;
                if (resultColumns != null) {
                    ResultColumn resultColumn = resultColumns.getResultColumn(columnName);
                    if (resultColumn != null) {
                        if (resultColumn.getExpression() instanceof ColumnReference) {
                            columnBinding = (ColumnBinding)((ColumnReference)resultColumn.getExpression()).getUserData();
                        }
                        if (columnBinding == null)
                            columnBinding = new ColumnBinding(null, resultColumn);
                    }
                }
            }
            if (columnBinding == null) {
                boolean ambiguous = false;
                outer:
                for (BindingContext bindingContext : bindingContexts) {
                    ColumnBinding contextBinding = null;
                    for (FromTable fromTable : bindingContext.tables) {
                        ColumnBinding tableBinding = getColumnBinding(fromTable, columnName);
                        if (tableBinding != null &&
                                !bindingContext.ignoreDueToUsing(fromTable, columnName)) {
                            if (contextBinding != null) {
                                ambiguous = true;
                                break outer;
                            }
                            contextBinding = tableBinding;
                        }
                    }
                    if (contextBinding != null) {
                        columnBinding = contextBinding;
                        break;
                    }
                }
                if (columnBinding == null) {
                    if (ambiguous)
                        throw new AmbiguousColumNameException(columnName, columnReference);
                    else
                        throw new NoSuchColumnException(columnName, columnReference);
                }
            }
        }
        columnReference.setUserData(columnBinding);
    }
View Full Code Here

            for (ResultColumn targetColumn : targetColumns) {
                ColumnReference columnReference = targetColumn.getReference();
                String columnName = columnReference.getColumnName();
                Column column = table.getColumn(columnName);
                if (column == null)
                    throw new NoSuchColumnException(columnName, columnReference);
                ColumnBinding columnBinding = new ColumnBinding(null, column, false);
                columnReference.setUserData(columnBinding);
            }
        }
        if (node.getReturningList() != null) {
View Full Code Here

                } break;

                case NodeTypes.DROP_COLUMN_NODE: {
                    String columnName = ((ModifyColumnNode)node).getColumnName();
                    if(Column.isInternalName(columnName) || (origTable.getColumn(columnName) == null)) {
                        skipOrThrow(context, ((ModifyColumnNode)node).getExistenceCheck(), null, new NoSuchColumnException(columnName));
                    } else {
                        columnChanges.add(TableChange.createDrop(columnName));
                    }
                } break;

                case NodeTypes.MODIFY_COLUMN_DEFAULT_NODE:
                case NodeTypes.MODIFY_COLUMN_CONSTRAINT_NODE:
                case NodeTypes.MODIFY_COLUMN_CONSTRAINT_NOT_NULL_NODE:
                case NodeTypes.MODIFY_COLUMN_TYPE_NODE: {
                    ModifyColumnNode modNode = (ModifyColumnNode)node;
                    String columnName = modNode.getColumnName();
                    Column column = origTable.getColumn(columnName);
                    if(Column.isInternalName(columnName) || (column == null)) {
                        skipOrThrow(context, modNode.getExistenceCheck(), null, new NoSuchColumnException(columnName));
                    } else {
                        // Special case: The only requested change is RESTART WITH.
                        // Cannot go through the current ALTER flow as the new value may appear to be the same,
                        // triggering NONE change, but should still take affect as values may have been allocated.
                        if((elements.size() == 1) && isRestartWithNode(modNode)) {
                            Sequence curSeq = column.getIdentityGenerator();
                            if(curSeq == null) {
                                throw new ColumnNotGeneratedException(column);
                            }
                            AkibanInformationSchema aisCopy = new AkibanInformationSchema();
                            Sequence newSeq = Sequence.create(aisCopy,
                                                              curSeq.getSchemaName(),
                                                              curSeq.getSequenceName().getTableName(),
                                                              modNode.getAutoincrementStart(),
                                                              curSeq.getIncrement(),
                                                              curSeq.getMinValue(),
                                                              curSeq.getMaxValue(),
                                                              curSeq.isCycle());
                            ddl.alterSequence(session, curSeq.getSequenceName(), newSeq);
                            return ChangeLevel.METADATA;
                        } else {
                            columnChanges.add(TableChange.createModify(columnName, columnName));
                            columnDefNodes.add((ColumnDefinitionNode)node);
                        }
                    }
                } break;

                case NodeTypes.FK_CONSTRAINT_DEFINITION_NODE: {
                    FKConstraintDefinitionNode fkNode = (FKConstraintDefinitionNode) node;
                    if(fkNode.getConstraintType() == ConstraintType.DROP) {
                        if(fkNode.isGrouping()) {
                            if(origTable.getParentJoin() == null) {
                                skipOrThrow(context, fkNode.getExistenceCheck(), null, new NoSuchGroupingFKException(origTable.getName()));
                                fkNode = null;
                            }
                        } else {
                            if(fkNode.getConstraintName() == null) {
                                Collection<ForeignKey> fkeys = origTable.getReferencingForeignKeys();
                                if(fkeys.size() == 0) {
                                    skipOrThrow(context, fkNode.getExistenceCheck(), null, new UnsupportedFKIndexException());
                                    fkNode = null;
                                } else if(fkeys.size() != 1) {
                                    throw new UnsupportedFKIndexException();
                                } else {
                                    try {
                                        fkNode.setConstraintName(fkeys.iterator().next().getConstraintName().getTableName());
                                    } catch(StandardException ex) {
                                        throw new SQLParserInternalException(ex);
                                    }
                                }
                            } else if(origTable.getReferencingForeignKey(fkNode.getConstraintName().getTableName()) == null) {
                                skipOrThrow(context,
                                            fkNode.getExistenceCheck(),
                                            null,
                                            new NoSuchForeignKeyException(fkNode.getConstraintName().getTableName(), origTable.getName()));
                                fkNode = null;
                            }
                            if(fkNode != null) {
                                // Also drop the referencing index.
                                indexChanges.add(TableChange.createDrop(fkNode.getConstraintName().getTableName()));
                            }
                        }
                    }
                    if(fkNode != null) {
                        fkDefNodes.add(fkNode);
                    }
                } break;

                case NodeTypes.CONSTRAINT_DEFINITION_NODE: {
                    ConstraintDefinitionNode cdn = (ConstraintDefinitionNode) node;
                    if(cdn.getConstraintType() == ConstraintType.DROP) {
                        String name = cdn.getName();
                        switch(cdn.getVerifyType()) {
                            case PRIMARY_KEY:
                                if(origTable.getPrimaryKey() == null) {
                                    skipOrThrow(context, cdn.getExistenceCheck(),
                                                null,
                                                new NoSuchConstraintException(origTable.getName(), Index.PRIMARY));
                                    name = null;
                                } else {
                                    name = origTable.getPrimaryKey().getIndex().getIndexName().getName();
                                }
                            break;
                            case DROP:
                                boolean found = false;
                                String indexName = indexNameForConstrainName(origTable, name);
                                if (indexName != null) {
                                    found = true;
                                    name = indexName;
                                } else if (origTable.getReferencingForeignKey(name) != null) {
                                    fkDefNodes.add(newFKDropNode(node, name, Boolean.FALSE));
                                    found = true;
                                } else if (origTable.getParentJoin() != null && origTable.getParentJoin().getName().equals(name)) {
                                    fkDefNodes.add(newFKDropNode(node, name, Boolean.TRUE));
                                    found = true;
                                    name = null;
                                }
                                if(!found) {
                                   skipOrThrow(context,
                                               cdn.getExistenceCheck(),
                                               null,
                                               new NoSuchConstraintException(origTable.getName(), name));
                                    name = null;
                                }
                                break;
                            case UNIQUE:
                                Index index = origTable.getIndex(name);
                                if(index == null || !index.isUnique()) {
                                    skipOrThrow(context,
                                                cdn.getExistenceCheck(),
                                                null,
                                                new NoSuchUniqueException(origTable.getName(), cdn.getName()));
                                    name = null;
                                }
                            break;
                            case CHECK:
                                throw new UnsupportedCheckConstraintException();
                        }
                        if (name != null) {
                            indexChanges.add(TableChange.createDrop(name));
                        }
                    } else if (cdn.getConstraintType() == ConstraintType.PRIMARY_KEY) {
                        if (origTable.getPrimaryKeyIncludingInternal().isAkibanPK())
                        {
                            columnChanges.add(TableChange.createDrop(Column.ROW_ID_NAME));
                            String indexName = origTable.getPrimaryKeyIncludingInternal().getIndex().getIndexName().getName();
                            indexChanges.add(TableChange.createDrop(indexName));
                        }
                        conDefNodes.add(cdn);
                    } else {
                        conDefNodes.add(cdn);
                    }
                } break;

                case NodeTypes.INDEX_DEFINITION_NODE:
                    IndexDefinitionNode idn = (IndexDefinitionNode)node;
                    if(idn.getJoinType() != null) {
                        throw new UnsupportedSQLException("ALTER ADD INDEX containing group index");
                    }
                    indexDefNodes.add(idn);
                    break;
                   
                case NodeTypes.AT_DROP_INDEX_NODE: {
                    AlterDropIndexNode dropIndexNode = (AlterDropIndexNode)node;
                    String name = dropIndexNode.getIndexName();
                    if(origTable.getIndex(name) == null) {
                        skipOrThrow(context, dropIndexNode.getExistenceCheck(), null, new NoSuchIndexException(name));
                    } else {
                        indexChanges.add(TableChange.createDrop(name));
                    }
                }
                break;

                case NodeTypes.AT_RENAME_NODE:
                    TableName newName = DDLHelper.convertName(defaultSchema,
                                                              ((AlterTableRenameNode)node).newName());
                    TableName oldName = origTable.getName();
                    ddl.renameTable(session, oldName, newName);
                    return ChangeLevel.METADATA;
                   
                case NodeTypes.AT_RENAME_COLUMN_NODE:
                    AlterTableRenameColumnNode alterRenameCol = (AlterTableRenameColumnNode) node;
                    String oldColName = alterRenameCol.getName();
                    String newColName = alterRenameCol.newName();
                    final Column oldCol = origTable.getColumn(oldColName);

                    if (oldCol == null) {
                        throw new NoSuchColumnException(oldColName);
                    }
                    columnChanges.add(TableChange.createModify(oldColName, newColName));
                break;

                default:
View Full Code Here

        if(table == null) {
            throw new NoSuchTableException(parts[0], parts[1]);
        }
        Column column = table.getColumn(parts[2]);
        if(column == null) {
            throw new NoSuchColumnException(String.format("%s.%s.%s", parts[0], parts[1], parts[2]));
        }
        Sequence seq = column.getIdentityGenerator();
        if(seq == null) {
            output.putNull();
        } else {
View Full Code Here

            toColumns = new ArrayList<>(copyStmt.getColumnList().size());
            for (ResultColumn rc : copyStmt.getColumnList()) {
                ColumnReference cref = rc.getReference();
                Column column = toTable.getColumn(cref.getColumnName());
                if (column == null)
                    throw new NoSuchColumnException(cref.getColumnName(), cref);
                toColumns.add(column);
            }
        }
        if (copyStmt.getFilename() != null)
            fromFile = new File(copyStmt.getFilename());
View Full Code Here

            }

            final Column column = indexCol.getColumn();
            final Column newColumn = newRefTable.getColumn(column.getName());
            if(newColumn == null) {
                throw new NoSuchColumnException(column.getName());
            }
            // API call problem, not something user can generate
            if(!column.getType().typeClass().equals(newColumn.getType().typeClass())) {
                throw new IllegalArgumentException(
                    "Column type mismatch for " + column.getName() + ": " + column.getTypeName() + " vs " + newColumn.getTypeName()
View Full Code Here

TOP

Related Classes of com.foundationdb.server.error.NoSuchColumnException

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.