-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Core: Support registerTable with REST session catalog #6512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,6 +71,8 @@ | |
| import org.apache.iceberg.rest.requests.CommitTransactionRequest; | ||
| import org.apache.iceberg.rest.requests.CreateNamespaceRequest; | ||
| import org.apache.iceberg.rest.requests.CreateTableRequest; | ||
| import org.apache.iceberg.rest.requests.ImmutableRegisterTableRequest; | ||
| import org.apache.iceberg.rest.requests.RegisterTableRequest; | ||
| import org.apache.iceberg.rest.requests.RenameTableRequest; | ||
| import org.apache.iceberg.rest.requests.UpdateNamespacePropertiesRequest; | ||
| import org.apache.iceberg.rest.requests.UpdateTableRequest; | ||
|
|
@@ -404,7 +406,40 @@ public void invalidateTable(SessionContext context, TableIdentifier ident) {} | |
| @Override | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wondering why can't we remove this method and let it use the parent implementation.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh.. This is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, @ajantha-bhat for the input. Yes, moving implementation logic makes sense to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that all the method's implementation is in |
||
| public Table registerTable( | ||
| SessionContext context, TableIdentifier ident, String metadataFileLocation) { | ||
| throw new UnsupportedOperationException("Register table is not supported"); | ||
| checkIdentifierIsValid(ident); | ||
|
|
||
| Preconditions.checkArgument( | ||
| metadataFileLocation != null && !metadataFileLocation.isEmpty(), | ||
| "Invalid metadata file location: %s", | ||
| metadataFileLocation); | ||
|
|
||
| RegisterTableRequest request = | ||
| ImmutableRegisterTableRequest.builder() | ||
| .name(ident.name()) | ||
| .metadataLocation(metadataFileLocation) | ||
| .build(); | ||
|
|
||
| LoadTableResponse response = | ||
| client.post( | ||
| paths.register(ident.namespace()), | ||
| request, | ||
| LoadTableResponse.class, | ||
| headers(context), | ||
| ErrorHandlers.tableErrorHandler()); | ||
krvikash marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| AuthSession session = tableSession(response.config(), session(context)); | ||
| RESTTableOperations ops = | ||
| new RESTTableOperations( | ||
| client, | ||
| paths.table(ident), | ||
| session::headers, | ||
| tableFileIO(context, response.config()), | ||
| response.tableMetadata()); | ||
|
|
||
| trackFileIO(ops); | ||
|
|
||
| return new BaseTable( | ||
| ops, fullTableName(ident), metricsReporter(paths.metrics(ident), session::headers)); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * 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.iceberg.rest.requests; | ||
|
|
||
| import org.apache.iceberg.rest.RESTRequest; | ||
| import org.immutables.value.Value; | ||
|
|
||
| @Value.Immutable | ||
| public interface RegisterTableRequest extends RESTRequest { | ||
|
|
||
| String name(); | ||
|
|
||
| String metadataLocation(); | ||
|
|
||
| @Override | ||
| default void validate() { | ||
| // nothing to validate as it's not possible to create an invalid instance | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * 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.iceberg.rest.requests; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonGenerator; | ||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import java.io.IOException; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.util.JsonUtil; | ||
|
|
||
| public class RegisterTableRequestParser { | ||
|
|
||
| private static final String NAME = "name"; | ||
| private static final String METADATA_LOCATION = "metadata-location"; | ||
|
|
||
| private RegisterTableRequestParser() {} | ||
|
|
||
| public static String toJson(RegisterTableRequest request) { | ||
| return toJson(request, false); | ||
| } | ||
|
|
||
| public static String toJson(RegisterTableRequest request, boolean pretty) { | ||
| return JsonUtil.generate(gen -> toJson(request, gen), pretty); | ||
| } | ||
|
|
||
| public static void toJson(RegisterTableRequest request, JsonGenerator gen) throws IOException { | ||
| Preconditions.checkArgument(null != request, "Invalid register table request: null"); | ||
|
|
||
| gen.writeStartObject(); | ||
|
|
||
| gen.writeStringField(NAME, request.name()); | ||
| gen.writeStringField(METADATA_LOCATION, request.metadataLocation()); | ||
|
|
||
| gen.writeEndObject(); | ||
| } | ||
|
|
||
| public static RegisterTableRequest fromJson(String json) { | ||
| return JsonUtil.parse(json, RegisterTableRequestParser::fromJson); | ||
| } | ||
|
|
||
| public static RegisterTableRequest fromJson(JsonNode json) { | ||
| Preconditions.checkArgument( | ||
| null != json, "Cannot parse register table request from null object"); | ||
|
|
||
| String name = JsonUtil.getString(NAME, json); | ||
| String metadataLocation = JsonUtil.getString(METADATA_LOCATION, json); | ||
|
|
||
| return ImmutableRegisterTableRequest.builder() | ||
| .name(name) | ||
| .metadataLocation(metadataLocation) | ||
| .build(); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.