Java 类com.facebook.presto.sql.tree.AddColumn 实例源码

项目:presto-query-formatter    文件:StatementFormatter.java   
@Override
protected Void visitAddColumn(AddColumn node, Integer indent)
{
    builder.append("ALTER TABLE ")
            .append(node.getName())
            .append(" ADD COLUMN ")
            .append(node.getColumn().getName())
            .append(" ")
            .append(node.getColumn().getType());

    return null;
}
项目:presto    文件:AddColumnTask.java   
@Override
public CompletableFuture<?> execute(AddColumn statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine)
{
    Session session = stateMachine.getSession();
    QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getName());
    Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
    if (!tableHandle.isPresent()) {
        throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
    }

    accessControl.checkCanAddColumns(session.getRequiredTransactionId(), session.getIdentity(), tableName);

    Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle.get());

    TableElement element = statement.getColumn();
    Type type = metadata.getType(parseTypeSignature(element.getType()));
    if ((type == null) || type.equals(UNKNOWN)) {
        throw new SemanticException(TYPE_MISMATCH, element, "Unknown type for column '%s' ", element.getName());
    }
    if (columnHandles.containsKey(element.getName())) {
        throw new SemanticException(COLUMN_ALREADY_EXISTS, statement, "Column '%s' already exists", element.getName());
    }

    metadata.addColumn(session, tableHandle.get(), new ColumnMetadata(element.getName(), type, false));

    return completedFuture(null);
}
项目:presto    文件:SqlFormatter.java   
@Override
protected Void visitAddColumn(AddColumn node, Integer indent)
{
    builder.append("ALTER TABLE ")
            .append(node.getName())
            .append(" ADD COLUMN ")
            .append(node.getColumn().getName())
            .append(" ")
            .append(node.getColumn().getType());

    return null;
}
项目:EchoQuery    文件:SqlFormatter.java   
@Override
protected Void visitAddColumn(AddColumn node, Integer indent)
{
    builder.append("ALTER TABLE ")
            .append(node.getName())
            .append(" ADD COLUMN ")
            .append(node.getColumn().getName())
            .append(" ")
            .append(node.getColumn().getType());

    return null;
}
项目:presto    文件:AstBuilder.java   
@Override
public Node visitAddColumn(SqlBaseParser.AddColumnContext context)
{
    return new AddColumn(getLocation(context), getQualifiedName(context.qualifiedName()), (TableElement) visit(context.tableElement()));
}
项目:presto    文件:TestSqlParser.java   
@Test
public void testAddColumn()
        throws Exception
{
    assertStatement("ALTER TABLE foo.t ADD COLUMN c bigint", new AddColumn(QualifiedName.of("foo", "t"), new TableElement("c", "bigint")));
}