Skip to content

Commit

Permalink
add update table and drop table
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry-024 committed Dec 18, 2024
1 parent 8080694 commit 2bd9793
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 3 deletions.
25 changes: 22 additions & 3 deletions paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<SchemaChange> 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<SchemaChange> 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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SchemaChange> changes;

@JsonCreator
public UpdateTableRequest(
@JsonProperty(FIELD_FROM_IDENTIFIER) Identifier fromIdentifier,
@JsonProperty(FIELD_TO_IDENTIFIER) Identifier toIdentifier,
@JsonProperty(FIELD_SCHEMA_CHANGES) List<SchemaChange> 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<SchemaChange> getChanges() {
return changes;
}
}

0 comments on commit 2bd9793

Please sign in to comment.