Skip to content

Commit

Permalink
Merge branch 'main' into iceberg-extended-sql
Browse files Browse the repository at this point in the history
  • Loading branch information
caican00 authored May 17, 2024
2 parents ecc463e + ccebb18 commit 48d37fe
Show file tree
Hide file tree
Showing 62 changed files with 726 additions and 611 deletions.
107 changes: 107 additions & 0 deletions api/src/main/java/com/datastrato/gravitino/rel/SupportsCatalogs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino.rel;

import com.datastrato.gravitino.Catalog;
import com.datastrato.gravitino.CatalogChange;
import com.datastrato.gravitino.CatalogProvider;
import com.datastrato.gravitino.NameIdentifier;
import com.datastrato.gravitino.annotation.Evolving;
import com.datastrato.gravitino.exceptions.CatalogAlreadyExistsException;
import com.datastrato.gravitino.exceptions.NoSuchCatalogException;
import com.datastrato.gravitino.exceptions.NoSuchMetalakeException;
import java.util.Map;

/**
* Client interface for supporting catalogs. It includes methods for listing, loading, creating,
* altering and dropping catalogs.
*/
@Evolving
public interface SupportsCatalogs {

/**
* List all catalogs in the metalake.
*
* @return The list of catalog's name identifiers.
* @throws NoSuchMetalakeException If the metalake with namespace does not exist.
*/
NameIdentifier[] listCatalogs() throws NoSuchMetalakeException;

/**
* List all catalogs with their information in the metalake.
*
* @return The list of catalog's information.
* @throws NoSuchMetalakeException If the metalake with namespace does not exist.
*/
Catalog[] listCatalogsInfo() throws NoSuchMetalakeException;

/**
* Load a catalog by its identifier.
*
* @param catalogName the identifier of the catalog.
* @return The catalog.
* @throws NoSuchCatalogException If the catalog does not exist.
*/
Catalog loadCatalog(String catalogName) throws NoSuchCatalogException;

/**
* Check if a catalog exists.
*
* @param catalogName The identifier of the catalog.
* @return True if the catalog exists, false otherwise.
*/
default boolean catalogExists(String catalogName) {
try {
loadCatalog(catalogName);
return true;
} catch (NoSuchCatalogException e) {
return false;
}
}

/**
* Create a catalog with specified identifier.
*
* <p>The parameter "provider" is a short name of the catalog, used to tell Gravitino which
* catalog should be created. The short name should be the same as the {@link CatalogProvider}
* interface provided.
*
* @param catalogName the name of the catalog.
* @param type the type of the catalog.
* @param provider the provider of the catalog.
* @param comment the comment of the catalog.
* @param properties the properties of the catalog.
* @return The created catalog.
* @throws NoSuchMetalakeException If the metalake does not exist.
* @throws CatalogAlreadyExistsException If the catalog already exists.
*/
Catalog createCatalog(
String catalogName,
Catalog.Type type,
String provider,
String comment,
Map<String, String> properties)
throws NoSuchMetalakeException, CatalogAlreadyExistsException;

/**
* Alter a catalog with specified identifier.
*
* @param catalogName the identifier of the catalog.
* @param changes the changes to apply to the catalog.
* @return The altered catalog.
* @throws NoSuchCatalogException If the catalog does not exist.
* @throws IllegalArgumentException If the changes cannot be applied to the catalog.
*/
Catalog alterCatalog(String catalogName, CatalogChange... changes)
throws NoSuchCatalogException, IllegalArgumentException;

/**
* Drop a catalog with specified identifier.
*
* @param catalogName the name of the catalog.
* @return True if the catalog was dropped, false otherwise.
*/
boolean dropCatalog(String catalogName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino.rel;

import com.datastrato.gravitino.Metalake;
import com.datastrato.gravitino.MetalakeChange;
import com.datastrato.gravitino.annotation.Evolving;
import com.datastrato.gravitino.exceptions.MetalakeAlreadyExistsException;
import com.datastrato.gravitino.exceptions.NoSuchMetalakeException;
import java.util.Map;

/**
* Client interface for supporting metalakes. It includes methods for listing, loading, creating,
* altering and dropping metalakes.
*/
@Evolving
public interface SupportsMetalakes {

/**
* List all metalakes.
*
* @return The list of metalakes.
*/
Metalake[] listMetalakes();

/**
* Load a metalake by its identifier.
*
* @param name the name of the metalake.
* @return The metalake.
* @throws NoSuchMetalakeException If the metalake does not exist.
*/
Metalake loadMetalake(String name) throws NoSuchMetalakeException;

/**
* Check if a metalake exists.
*
* @param name The name of the metalake.
* @return True if the metalake exists, false otherwise.
*/
default boolean metalakeExists(String name) {
try {
loadMetalake(name);
return true;
} catch (NoSuchMetalakeException e) {
return false;
}
}

/**
* Create a metalake with specified identifier.
*
* @param name The name of the metalake.
* @param comment The comment of the metalake.
* @param properties The properties of the metalake.
* @return The created metalake.
* @throws MetalakeAlreadyExistsException If the metalake already exists.
*/
Metalake createMetalake(String name, String comment, Map<String, String> properties)
throws MetalakeAlreadyExistsException;

/**
* Alter a metalake with specified identifier.
*
* @param name The name of the metalake.
* @param changes The changes to apply.
* @return The altered metalake.
* @throws NoSuchMetalakeException If the metalake does not exist.
* @throws IllegalArgumentException If the changes cannot be applied to the metalake.
*/
Metalake alterMetalake(String name, MetalakeChange... changes)
throws NoSuchMetalakeException, IllegalArgumentException;

/**
* Drop a metalake with specified identifier.
*
* @param name The identifier of the metalake.
* @return True if the metalake was dropped, false otherwise.
*/
boolean dropMetalake(String name);
}
2 changes: 1 addition & 1 deletion api/src/test/resources/log4j2.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name = ConsoleLogConfigDemo
appender.console.type = Console
appender.console.name = consoleLogger
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L - %m%n

# Root logger level
rootLogger.level = debug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void setup() throws IOException {

@AfterAll
public static void stop() throws IOException {
client.dropMetalake(NameIdentifier.of(metalakeName));
client.dropMetalake(metalakeName);

if (hdfs != null) {
hdfs.close();
Expand All @@ -85,22 +85,18 @@ private static void createMetalake() {
Assertions.assertEquals(0, gravitinoMetalakes.length);

GravitinoMetalake createdMetalake =
client.createMetalake(NameIdentifier.of(metalakeName), "comment", Collections.emptyMap());
GravitinoMetalake loadMetalake = client.loadMetalake(NameIdentifier.of(metalakeName));
client.createMetalake(metalakeName, "comment", Collections.emptyMap());
GravitinoMetalake loadMetalake = client.loadMetalake(metalakeName);
Assertions.assertEquals(createdMetalake, loadMetalake);

metalake = loadMetalake;
}

private static void createCatalog() {
metalake.createCatalog(
NameIdentifier.of(metalakeName, catalogName),
Catalog.Type.FILESET,
provider,
"comment",
ImmutableMap.of());
catalogName, Catalog.Type.FILESET, provider, "comment", ImmutableMap.of());

catalog = metalake.loadCatalog(NameIdentifier.of(metalakeName, catalogName));
catalog = metalake.loadCatalog(catalogName);
}

private static void createSchema() {
Expand Down Expand Up @@ -547,11 +543,7 @@ public void testDropCatalogWithEmptySchema() {
// Create a catalog without specifying location.
Catalog filesetCatalog =
metalake.createCatalog(
NameIdentifier.of(metalakeName, catalogName),
Catalog.Type.FILESET,
provider,
"comment",
ImmutableMap.of());
catalogName, Catalog.Type.FILESET, provider, "comment", ImmutableMap.of());

// Create a schema without specifying location.
String schemaName =
Expand All @@ -574,11 +566,9 @@ public void testDropCatalogWithEmptySchema() {
"schema should not be exists");

// Drop the catalog.
dropped = metalake.dropCatalog(NameIdentifier.of(metalakeName, catalogName));
dropped = metalake.dropCatalog(catalogName);
Assertions.assertTrue(dropped, "catalog should be dropped");
Assertions.assertFalse(
metalake.catalogExists(NameIdentifier.of(metalakeName, catalogName)),
"catalog should not be exists");
Assertions.assertFalse(metalake.catalogExists(catalogName), "catalog should not be exists");
}

private Fileset createFileset(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name = ConsoleLogConfig
appender.console.type = Console
appender.console.name = consoleLogger
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L - %m%n

# Log files location
property.logPath = ${sys:gravitino.log.path:-catalog-hadoop/build/integration-test.log}
Expand Down
Loading

0 comments on commit 48d37fe

Please sign in to comment.