@Override
  public void renameTable(TableIdentifier from, TableIdentifier to) {
    if (!namespaceExists(to.namespace())) {
      throw new NoSuchNamespaceException(
          "Cannot rename %s to %s because namespace %s does not exist", from, to, to.namespace());
    }

    if (tableExists(to)) {
      throw new AlreadyExistsException(
          "Cannot rename %s because destination table %s exists", from, to);
    }

    EcsURI fromURI = tableURI(from);
    if (!objectMetadata(fromURI).isPresent()) {
      throw new NoSuchTableException("Cannot rename table because table %s does not exist", from);
    }

    Properties properties = loadProperties(fromURI);
    EcsURI toURI = tableURI(to);

    if (!putNewProperties(toURI, properties.content())) {
      throw new AlreadyExistsException(
          "Cannot rename %s because destination table %s exists", from, to);
    }

    client.deleteObject(fromURI.bucket(), fromURI.name());
    LOG.info("Rename table {} to {}", from, to);
  }
@Test
  public void testRenameTable() {
    ecsCatalog.createNamespace(Namespace.of("a"));
    ecsCatalog.createTable(TableIdentifier.of("a", "t1"), SCHEMA);
    ecsCatalog.createNamespace(Namespace.of("b"));

    assertThatThrownBy(
            () ->
                ecsCatalog.renameTable(
                    TableIdentifier.of("unknown"), TableIdentifier.of("b", "t2")))
        .isInstanceOf(NoSuchTableException.class)
        .hasMessage("Cannot rename table because table unknown does not exist");

    assertThatThrownBy(
            () ->
                ecsCatalog.renameTable(
                    TableIdentifier.of("a", "t1"), TableIdentifier.of("unknown", "t2")))
        .isInstanceOf(NoSuchNamespaceException.class)
        .hasMessage("Cannot rename a.t1 to unknown.t2 because namespace unknown does not exist");

    ecsCatalog.renameTable(TableIdentifier.of("a", "t1"), TableIdentifier.of("b", "t2"));

    assertThat(ecsCatalog.tableExists(TableIdentifier.of("a", "t1")))
        .as("Old table does not exist")
        .isFalse();
    assertThat(ecsCatalog.tableExists(TableIdentifier.of("b", "t2")))
        .as("New table exists")
        .isTrue();
  }