forked from apache/gravitino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[apache#3483] refactor(API): separate API for client using: SupportsS…
…chemas (apache#3419) ### What changes were proposed in this pull request? Today Gravitino java client and server sides share the same interfaces, like SupportsMetalakes, SupportsCatalogs, SupportsSchemas, etc. These interfaces are good for server side, but not good for client side. After some discussion with Jerry and others, if we want to make it easier to use, and still keep server side code stable, the only way is to separate the APIs: create individual APIs for the java client. This PR will introduce the simplified API for client: SupportsSchemas. The interface for serverside has been moved into core module with package name "com.datastrato.gravitino.schema"; The current one in api module with package name "com.datastrato.gravitino.rel" is for client side, whose method signatures have been changed, so the client code will be clear. Besides, the "Catalog.asSchema()", "Catalog.asTableCatalog()" should only be implemented on the client side, not server side (as server side we can use the subclasses of "CatalogOperations"). I updated the occurrances of such usages, mainly in some integration tests. The integration tests which uses Java client to manipulate metadata also be updated. ### Why are the changes needed? To make the client API simple and easy to use. Fix: apache#3483 ### Does this PR introduce _any_ user-facing change? Will change the Java client API, mainly on the method signatures; for example, "listSchemas()" won't need an input parameter, "schemaExists()" will use a String value as the input parameter instead of a NameIdentifier object, etc. ### How was this patch tested? All existing integration tests will cover the API change.
- Loading branch information
1 parent
ee5d499
commit e930b0c
Showing
82 changed files
with
697 additions
and
784 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
api/src/main/java/com/datastrato/gravitino/SupportsSchemas.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
// Referred from Apache Spark's connector/catalog implementation | ||
// sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/SupportNamespaces.java | ||
|
||
package com.datastrato.gravitino; | ||
|
||
import com.datastrato.gravitino.annotation.Evolving; | ||
import com.datastrato.gravitino.exceptions.NoSuchCatalogException; | ||
import com.datastrato.gravitino.exceptions.NoSuchSchemaException; | ||
import com.datastrato.gravitino.exceptions.NonEmptySchemaException; | ||
import com.datastrato.gravitino.exceptions.SchemaAlreadyExistsException; | ||
import java.util.Map; | ||
|
||
/** | ||
* The client interface to support schema operations. The server side should use the other one with | ||
* the same name in the core module. | ||
*/ | ||
@Evolving | ||
public interface SupportsSchemas { | ||
|
||
/** | ||
* List schemas under the entity. | ||
* | ||
* <p>If an entity such as a table, view exists, its parent schemas must also exist and must be | ||
* returned by this discovery method. For example, if table a.b.t exists, this method invoked as | ||
* listSchemas(a) must return [a.b] in the result array | ||
* | ||
* @return An array of schema identifier under the namespace. | ||
* @throws NoSuchCatalogException If the catalog does not exist. | ||
*/ | ||
NameIdentifier[] listSchemas() throws NoSuchCatalogException; | ||
|
||
/** | ||
* Check if a schema exists. | ||
* | ||
* <p>If an entity such as a table, view exists, its parent namespaces must also exist. For | ||
* example, if table a.b.t exists, this method invoked as schemaExists(a.b) must return true. | ||
* | ||
* @param schemaName The name of the schema. | ||
* @return True if the schema exists, false otherwise. | ||
*/ | ||
default boolean schemaExists(String schemaName) { | ||
try { | ||
loadSchema(schemaName); | ||
return true; | ||
} catch (NoSuchSchemaException e) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Create a schema in the catalog. | ||
* | ||
* @param schemaName The name of the schema. | ||
* @param comment The comment of the schema. | ||
* @param properties The properties of the schema. | ||
* @return The created schema. | ||
* @throws NoSuchCatalogException If the catalog does not exist. | ||
* @throws SchemaAlreadyExistsException If the schema already exists. | ||
*/ | ||
Schema createSchema(String schemaName, String comment, Map<String, String> properties) | ||
throws NoSuchCatalogException, SchemaAlreadyExistsException; | ||
|
||
/** | ||
* Load metadata properties for a schema. | ||
* | ||
* @param schemaName The name of the schema. | ||
* @return A schema. | ||
* @throws NoSuchSchemaException If the schema does not exist (optional). | ||
*/ | ||
Schema loadSchema(String schemaName) throws NoSuchSchemaException; | ||
|
||
/** | ||
* Apply the metadata change to a schema in the catalog. | ||
* | ||
* @param schemaName The name of the schema. | ||
* @param changes The metadata changes to apply. | ||
* @return The altered schema. | ||
* @throws NoSuchSchemaException If the schema does not exist. | ||
*/ | ||
Schema alterSchema(String schemaName, SchemaChange... changes) throws NoSuchSchemaException; | ||
|
||
/** | ||
* Drop a schema from the catalog. If cascade option is true, recursively drop all objects within | ||
* the schema. | ||
* | ||
* <p>If the catalog implementation does not support this operation, it may throw {@link | ||
* UnsupportedOperationException}. | ||
* | ||
* @param schemaName The name of the schema. | ||
* @param cascade If true, recursively drop all objects within the schema. | ||
* @return True if the schema exists and is dropped successfully, false if the schema doesn't | ||
* exist. | ||
* @throws NonEmptySchemaException If the schema is not empty and cascade is false. | ||
*/ | ||
boolean dropSchema(String schemaName, boolean cascade) throws NonEmptySchemaException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.