com.facebook.presto.metadata.Metadata.renameColumn()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(1.7k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中com.facebook.presto.metadata.Metadata.renameColumn()方法的一些代码示例,展示了Metadata.renameColumn()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metadata.renameColumn()方法的具体详情如下:
包路径:com.facebook.presto.metadata.Metadata
类名称:Metadata
方法名:renameColumn

Metadata.renameColumn介绍

[英]Rename the specified column.
[中]重命名指定的列。

代码示例

代码示例来源:origin: prestodb/presto

metadata.renameColumn(session, tableHandle, columnHandle, target);

代码示例来源:origin: uk.co.nichesolutions.presto/presto-main

@Override
  public CompletableFuture<?> execute(RenameColumn statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine)
  {
    Session session = stateMachine.getSession();
    QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTable());
    Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);

    String source = statement.getSource().toLowerCase(ENGLISH);
    String target = statement.getTarget().toLowerCase(ENGLISH);

    if (!tableHandle.isPresent()) {
      throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
    }
    accessControl.checkCanRenameColumn(session.getRequiredTransactionId(), session.getIdentity(), tableName);

    Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle.get());
    if (!columnHandles.containsKey(source)) {
      throw new SemanticException(MISSING_COLUMN, statement, "Column '%s' does not exist", source);
    }

    if (columnHandles.containsKey(target)) {
      throw new SemanticException(COLUMN_ALREADY_EXISTS, statement, "Column '%s' already exists", target);
    }
    metadata.renameColumn(session, tableHandle.get(), columnHandles.get(source), target);

    return completedFuture(null);
  }
}

相关文章