From 2bd9793118b9af0d6b7cf5c324e091358495932d Mon Sep 17 00:00:00 2001 From: yantian Date: Wed, 18 Dec 2024 16:28:13 +0800 Subject: [PATCH] add update table and drop table --- .../org/apache/paimon/rest/RESTCatalog.java | 25 ++++++- .../rest/requests/UpdateTableRequest.java | 71 +++++++++++++++++++ 2 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 paimon-core/src/main/java/org/apache/paimon/rest/requests/UpdateTableRequest.java diff --git a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java index d1ba29779178..2ab16cbac127 100644 --- a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java +++ b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java @@ -35,6 +35,7 @@ import org.apache.paimon.rest.requests.AlterDatabaseRequest; import org.apache.paimon.rest.requests.CreateDatabaseRequest; import org.apache.paimon.rest.requests.CreateTableRequest; +import org.apache.paimon.rest.requests.UpdateTableRequest; import org.apache.paimon.rest.responses.AlterDatabaseResponse; import org.apache.paimon.rest.responses.ConfigResponse; import org.apache.paimon.rest.responses.CreateDatabaseResponse; @@ -223,14 +224,32 @@ protected void createTableImpl(Identifier identifier, Schema schema) } @Override - protected void renameTableImpl(Identifier fromTable, Identifier toTable) {} + protected void renameTableImpl(Identifier fromTable, Identifier toTable) { + updateTable(fromTable, toTable, new ArrayList<>()); + } @Override protected void alterTableImpl(Identifier identifier, List changes) - throws TableNotExistException, ColumnAlreadyExistException, ColumnNotExistException {} + throws TableNotExistException, ColumnAlreadyExistException, ColumnNotExistException { + updateTable(identifier, null, changes); + } + + // todo: how know which exception to throw + private void updateTable(Identifier fromTable, Identifier toTable, List changes) { + UpdateTableRequest request = new UpdateTableRequest(fromTable, toTable, changes); + client.post( + resourcePaths.table(fromTable.getDatabaseName(), fromTable.getTableName()), + request, + GetTableResponse.class, + headers()); + } @Override - protected void dropTableImpl(Identifier identifier) {} + protected void dropTableImpl(Identifier identifier) { + client.delete( + resourcePaths.table(identifier.getDatabaseName(), identifier.getTableName()), + headers()); + } @Override public boolean caseSensitive() { diff --git a/paimon-core/src/main/java/org/apache/paimon/rest/requests/UpdateTableRequest.java b/paimon-core/src/main/java/org/apache/paimon/rest/requests/UpdateTableRequest.java new file mode 100644 index 000000000000..ca12a1152455 --- /dev/null +++ b/paimon-core/src/main/java/org/apache/paimon/rest/requests/UpdateTableRequest.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.paimon.rest.requests; + +import org.apache.paimon.catalog.Identifier; +import org.apache.paimon.rest.RESTRequest; +import org.apache.paimon.schema.SchemaChange; + +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonCreator; +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonGetter; +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +/** Request for updating table. */ +public class UpdateTableRequest implements RESTRequest { + + private static final String FIELD_FROM_IDENTIFIER = "from"; + private static final String FIELD_TO_IDENTIFIER = "to"; + private static final String FIELD_SCHEMA_CHANGES = "changes"; + + @JsonProperty(FIELD_FROM_IDENTIFIER) + private Identifier fromIdentifier; + + @JsonProperty(FIELD_TO_IDENTIFIER) + private Identifier toIdentifier; + + @JsonProperty(FIELD_SCHEMA_CHANGES) + private List changes; + + @JsonCreator + public UpdateTableRequest( + @JsonProperty(FIELD_FROM_IDENTIFIER) Identifier fromIdentifier, + @JsonProperty(FIELD_TO_IDENTIFIER) Identifier toIdentifier, + @JsonProperty(FIELD_SCHEMA_CHANGES) List changes) { + this.fromIdentifier = fromIdentifier; + this.toIdentifier = toIdentifier; + this.changes = changes; + } + + @JsonGetter(FIELD_FROM_IDENTIFIER) + public Identifier getFromIdentifier() { + return fromIdentifier; + } + + @JsonGetter(FIELD_TO_IDENTIFIER) + public Identifier getToIdentifier() { + return toIdentifier; + } + + @JsonGetter(FIELD_SCHEMA_CHANGES) + public List getChanges() { + return changes; + } +}