Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#2318][#2319][#2320][#2321][#1904][#1902][#1900][#1874] Improvement(all): Make repeated string a constant (#2325)

cai can32cd234d249d
diff --git a/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopCatalogOperations.java b/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopCatalogOperations.java
index ea7a23abeb..a5bb443129 100644
--- a/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopCatalogOperations.java
+++ b/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopCatalogOperations.java
@@ -53,6 +53,9 @@ import org.slf4j.LoggerFactory;
public class HadoopCatalogOperations implements CatalogOperations, SupportsSchemas, FilesetCatalog {
+ private static final String SCHEMA_DOES_NOT_EXIST_MSG = "Schema %s does not exist";
+ private static final String FILESET_DOES_NOT_EXIST_MSG = "Fileset %s does not exist";
+
private static final Logger LOG = LoggerFactory.getLogger(HadoopCatalogOperations.class);
private static final HadoopCatalogPropertiesMetadata CATALOG_PROPERTIES_METADATA =
@@ -107,7 +110,7 @@ public class HadoopCatalogOperations implements CatalogOperations, SupportsSchem
try {
NameIdentifier schemaIdent = NameIdentifier.of(namespace.levels());
if (!store.exists(schemaIdent, Entity.EntityType.SCHEMA)) {
- throw new NoSuchSchemaException("Schema %s does not exist", schemaIdent);
+ throw new NoSuchSchemaException(SCHEMA_DOES_NOT_EXIST_MSG, schemaIdent);
}
List<FilesetEntity> filesets =
@@ -136,7 +139,7 @@ public class HadoopCatalogOperations implements CatalogOperations, SupportsSchem
.build();
} catch (NoSuchEntityException exception) {
- throw new NoSuchFilesetException(exception, "Fileset %s does not exist", ident);
+ throw new NoSuchFilesetException(exception, FILESET_DOES_NOT_EXIST_MSG, ident);
} catch (IOException ioe) {
throw new RuntimeException("Failed to load fileset %s" + ident, ioe);
}
@@ -163,7 +166,7 @@ public class HadoopCatalogOperations implements CatalogOperations, SupportsSchem
try {
schemaEntity = store.get(schemaIdent, Entity.EntityType.SCHEMA, SchemaEntity.class);
} catch (NoSuchEntityException exception) {
- throw new NoSuchSchemaException(exception, "Schema %s does not exist", schemaIdent);
+ throw new NoSuchSchemaException(exception, SCHEMA_DOES_NOT_EXIST_MSG, schemaIdent);
} catch (IOException ioe) {
throw new RuntimeException("Failed to load schema " + schemaIdent, ioe);
}
@@ -253,7 +256,7 @@ public class HadoopCatalogOperations implements CatalogOperations, SupportsSchem
throws NoSuchFilesetException, IllegalArgumentException {
try {
if (!store.exists(ident, Entity.EntityType.FILESET)) {
- throw new NoSuchFilesetException("Fileset %s does not exist", ident);
+ throw new NoSuchFilesetException(FILESET_DOES_NOT_EXIST_MSG, ident);
}
} catch (IOException ioe) {
throw new RuntimeException("Failed to load fileset " + ident, ioe);
@@ -279,7 +282,7 @@ public class HadoopCatalogOperations implements CatalogOperations, SupportsSchem
} catch (IOException ioe) {
throw new RuntimeException("Failed to update fileset " + ident, ioe);
} catch (NoSuchEntityException nsee) {
- throw new NoSuchFilesetException(nsee, "Fileset %s does not exist", ident);
+ throw new NoSuchFilesetException(nsee, FILESET_DOES_NOT_EXIST_MSG, ident);
} catch (AlreadyExistsException aee) {
// This is happened when renaming a fileset to an existing fileset name.
throw new RuntimeException(
@@ -405,7 +408,7 @@ public class HadoopCatalogOperations implements CatalogOperations, SupportsSchem
.build();
} catch (NoSuchEntityException exception) {
- throw new NoSuchSchemaException(exception, "Schema %s does not exist", ident);
+ throw new NoSuchSchemaException(exception, SCHEMA_DOES_NOT_EXIST_MSG, ident);
} catch (IOException ioe) {
throw new RuntimeException("Failed to load schema " + ident, ioe);
}
@@ -416,7 +419,7 @@ public class HadoopCatalogOperations implements CatalogOperations, SupportsSchem
throws NoSuchSchemaException {
try {
if (!store.exists(ident, Entity.EntityType.SCHEMA)) {
- throw new NoSuchSchemaException("Schema %s does not exist", ident);
+ throw new NoSuchSchemaException(SCHEMA_DOES_NOT_EXIST_MSG, ident);
}
} catch (IOException ioe) {
throw new RuntimeException("Failed to check if schema " + ident + " exists", ioe);
@@ -440,7 +443,7 @@ public class HadoopCatalogOperations implements CatalogOperations, SupportsSchem
} catch (IOException ioe) {
throw new RuntimeException("Failed to update schema " + ident, ioe);
} catch (NoSuchEntityException nsee) {
- throw new NoSuchSchemaException(nsee, "Schema %s does not exist", ident);
+ throw new NoSuchSchemaException(nsee, SCHEMA_DOES_NOT_EXIST_MSG, ident);
} catch (AlreadyExistsException aee) {
throw new RuntimeException(
"Schema with the same name "
diff --git a/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/dyn/DynConstructors.java b/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/dyn/DynConstructors.java
index 593df47eb8..3e3558091e 100644
--- a/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/dyn/DynConstructors.java
+++ b/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/dyn/DynConstructors.java
@@ -29,6 +29,10 @@ import java.util.Map;
// common/src/main/java/org/apache/iceberg/common/DynConstructors.java
public class DynConstructors {
+
+ private static final String INVALID_CALL_TO_CONSTRUCTOR_MSG =
+ "Invalid call to constructor: target must be null";
+
private DynConstructors() {}
public static Builder builder() {
@@ -135,16 +139,14 @@ public class DynConstructors {
@Override
@SuppressWarnings("unchecked")
public <R> R invoke(Object target, Object... args) {
- Preconditions.checkArgument(
- target == null, "Invalid call to constructor: target must be null");
+ Preconditions.checkArgument(target == null, INVALID_CALL_TO_CONSTRUCTOR_MSG);
return (R) newInstance(args);
}
@Override
@SuppressWarnings("unchecked")
public <R> R invokeChecked(Object target, Object... args) throws Exception {
- Preconditions.checkArgument(
- target == null, "Invalid call to constructor: target must be null");
+ Preconditions.checkArgument(target == null, INVALID_CALL_TO_CONSTRUCTOR_MSG);
return (R) newInstanceChecked(args);
}
diff --git a/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/JdbcCatalogOperations.java b/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/JdbcCatalogOperations.java
index a83baf12a2..dd3d9d52fa 100644
--- a/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/JdbcCatalogOperations.java
+++ b/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/JdbcCatalogOperations.java
@@ -59,6 +59,9 @@ import org.slf4j.LoggerFactory;
/** Operations for interacting with the Jdbc catalog in Gravitino. */
public class JdbcCatalogOperations implements CatalogOperations, SupportsSchemas, TableCatalog {
+ private static final String GRAVITINO_ATTRIBUTE_DOES_NOT_EXIST_MSG =
+ "The gravitino id attribute does not exist in properties";
+
public static final Logger LOG = LoggerFactory.getLogger(JdbcCatalogOperations.class);
private JdbcCatalogPropertiesMetadata jdbcCatalogPropertiesMetadata;
@@ -171,8 +174,7 @@ public class JdbcCatalogOperations implements CatalogOperations, SupportsSchemas
throws NoSuchCatalogException, SchemaAlreadyExistsException {
StringIdentifier identifier =
Preconditions.checkNotNull(
- StringIdentifier.fromProperties(properties),
- "The gravitino id attribute does not exist in properties");
+ StringIdentifier.fromProperties(properties), GRAVITINO_ATTRIBUTE_DOES_NOT_EXIST_MSG);
String notAllowedKey =
properties.keySet().stream()
.filter(s -> !StringUtils.equals(s, StringIdentifier.ID_KEY))
@@ -377,8 +379,7 @@ public class JdbcCatalogOperations implements CatalogOperations, SupportsSchemas
StringIdentifier identifier =
Preconditions.checkNotNull(
- StringIdentifier.fromProperties(properties),
- "The gravitino id attribute does not exist in properties");
+ StringIdentifier.fromProperties(properties), GRAVITINO_ATTRIBUTE_DOES_NOT_EXIST_MSG);
// The properties we write to the database do not require the id field, so it needs to be
// removed.
HashMap<String, String> resultProperties =
diff --git a/catalogs/catalog-jdbc-mysql/src/main/java/com/datastrato/gravitino/catalog/mysql/operation/MysqlTableOperations.java b/catalogs/catalog-jdbc-mysql/src/main/java/com/datastrato/gravitino/catalog/mysql/operation/MysqlTableOperations.java
index 04e723de91..415061d61f 100644
--- a/catalogs/catalog-jdbc-mysql/src/main/java/com/datastrato/gravitino/catalog/mysql/operation/MysqlTableOperations.java
+++ b/catalogs/catalog-jdbc-mysql/src/main/java/com/datastrato/gravitino/catalog/mysql/operation/MysqlTableOperations.java
@@ -46,6 +46,8 @@ public class MysqlTableOperations extends JdbcTableOperations {
public static final String BACK_QUOTE = "`";
public static final String MYSQL_AUTO_INCREMENT = "AUTO_INCREMENT";
+ private static final String MYSQL_NOT_SUPPORT_NESTED_COLUMN_MSG =
+ "Mysql does not support nested column names.";
@Override
public List<String> listTables(String databaseName) throws NoSuchSchemaException {
@@ -391,7 +393,7 @@ public class MysqlTableOperations extends JdbcTableOperations {
TableChange.UpdateColumnComment updateColumnComment, JdbcTable jdbcTable) {
String newComment = updateColumnComment.getNewComment();
if (updateColumnComment.fieldName().length > 1) {
- throw new UnsupportedOperationException("Mysql does not support nested column names.");
+ throw new UnsupportedOperationException(MYSQL_NOT_SUPPORT_NESTED_COLUMN_MSG);
}
String col = updateColumnComment.fieldName()[0];
JdbcColumn column = getJdbcColumnFromTable(jdbcTable, col);
@@ -414,7 +416,7 @@ public class MysqlTableOperations extends JdbcTableOperations {
private String addColumnFieldDefinition(TableChange.AddColumn addColumn) {
String dataType = (String) typeConverter.fromGravitinoType(addColumn.getDataType());
if (addColumn.fieldName().length > 1) {
- throw new UnsupportedOperationException("Mysql does not support nested column names.");
+ throw new UnsupportedOperationException(MYSQL_NOT_SUPPORT_NESTED_COLUMN_MSG);
}
String col = addColumn.fieldName()[0];
@@ -457,7 +459,7 @@ public class MysqlTableOperations extends JdbcTableOperations {
private String renameColumnFieldDefinition(
TableChange.RenameColumn renameColumn, JdbcTable jdbcTable) {
if (renameColumn.fieldName().length > 1) {
- throw new UnsupportedOperationException("Mysql does not support nested column names.");
+ throw new UnsupportedOperationException(MYSQL_NOT_SUPPORT_NESTED_COLUMN_MSG);
}
String oldColumnName = renameColumn.fieldName()[0];
@@ -488,7 +490,7 @@ public class MysqlTableOperations extends JdbcTableOperations {
private String updateColumnPositionFieldDefinition(
TableChange.UpdateColumnPosition updateColumnPosition, JdbcTable jdbcTable) {
if (updateColumnPosition.fieldName().length > 1) {
- throw new UnsupportedOperationException("Mysql does not support nested column names.");
+ throw new UnsupportedOperationException(MYSQL_NOT_SUPPORT_NESTED_COLUMN_MSG);
}
String col = updateColumnPosition.fieldName()[0];
JdbcColumn column = getJdbcColumnFromTable(jdbcTable, col);
@@ -512,7 +514,7 @@ public class MysqlTableOperations extends JdbcTableOperations {
private String deleteColumnFieldDefinition(
TableChange.DeleteColumn deleteColumn, JdbcTable jdbcTable) {
if (deleteColumn.fieldName().length > 1) {
- throw new UnsupportedOperationException("Mysql does not support nested column names.");
+ throw new UnsupportedOperationException(MYSQL_NOT_SUPPORT_NESTED_COLUMN_MSG);
}
String col = deleteColumn.fieldName()[0];
boolean colExists = true;
@@ -534,7 +536,7 @@ public class MysqlTableOperations extends JdbcTableOperations {
private String updateColumnTypeFieldDefinition(
TableChange.UpdateColumnType updateColumnType, JdbcTable jdbcTable) {
if (updateColumnType.fieldName().length > 1) {
- throw new UnsupportedOperationException("Mysql does not support nested column names.");
+ throw new UnsupportedOperationException(MYSQL_NOT_SUPPORT_NESTED_COLUMN_MSG);
}
String col = updateColumnType.fieldName()[0];
JdbcColumn column = getJdbcColumnFromTable(jdbcTable, col);
diff --git a/catalogs/catalog-jdbc-postgresql/src/main/java/com/datastrato/gravitino/catalog/postgresql/operation/PostgreSqlTableOperations.java b/catalogs/catalog-jdbc-postgresql/src/main/java/com/datastrato/gravitino/catalog/postgresql/operation/PostgreSqlTableOperations.java
index 5ba5672e4e..b0462a68d7 100644
--- a/catalogs/catalog-jdbc-postgresql/src/main/java/com/datastrato/gravitino/catalog/postgresql/operation/PostgreSqlTableOperations.java
+++ b/catalogs/catalog-jdbc-postgresql/src/main/java/com/datastrato/gravitino/catalog/postgresql/operation/PostgreSqlTableOperations.java
@@ -47,6 +47,9 @@ public class PostgreSqlTableOperations extends JdbcTableOperations {
public static final String COLUMN_COMMENT = "COMMENT ON COLUMN ";
public static final String TABLE_COMMENT = "COMMENT ON TABLE ";
+ private static final String POSTGRESQL_NOT_SUPPORT_NESTED_COLUMN_MSG =
+ "PostgreSQL does not support nested column names.";
+
private String database;
@Override
@@ -287,7 +290,7 @@ public class PostgreSqlTableOperations extends JdbcTableOperations {
private String updateColumnNullabilityDefinition(
TableChange.UpdateColumnNullability updateColumnNullability, String tableName) {
if (updateColumnNullability.fieldName().length > 1) {
- throw new UnsupportedOperationException("PostgreSQL does not support nested column names.");
+ throw new UnsupportedOperationException(POSTGRESQL_NOT_SUPPORT_NESTED_COLUMN_MSG);
}
String col = updateColumnNullability.fieldName()[0];
if (updateColumnNullability.nullable()) {
@@ -333,7 +336,7 @@ public class PostgreSqlTableOperations extends JdbcTableOperations {
private String deleteColumnFieldDefinition(
TableChange.DeleteColumn deleteColumn, JdbcTable table) {
if (deleteColumn.fieldName().length > 1) {
- throw new UnsupportedOperationException("PostgreSQL does not support nested column names.");
+ throw new UnsupportedOperationException(POSTGRESQL_NOT_SUPPORT_NESTED_COLUMN_MSG);
}
String col = deleteColumn.fieldName()[0];
boolean colExists =
@@ -359,7 +362,7 @@ public class PostgreSqlTableOperations extends JdbcTableOperations {
private String updateColumnTypeFieldDefinition(
TableChange.UpdateColumnType updateColumnType, JdbcTable jdbcTable) {
if (updateColumnType.fieldName().length > 1) {
- throw new UnsupportedOperationException("PostgreSQL does not support nested column names.");
+ throw new UnsupportedOperationException(POSTGRESQL_NOT_SUPPORT_NESTED_COLUMN_MSG);
}
String col = updateColumnType.fieldName()[0];
JdbcColumn column =
@@ -395,7 +398,7 @@ public class PostgreSqlTableOperations extends JdbcTableOperations {
private String renameColumnFieldDefinition(
TableChange.RenameColumn renameColumn, String tableName) {
if (renameColumn.fieldName().length > 1) {
- throw new UnsupportedOperationException("PostgreSQL does not support nested column names.");
+ throw new UnsupportedOperationException(POSTGRESQL_NOT_SUPPORT_NESTED_COLUMN_MSG);
}
return ALTER_TABLE
+ tableName
@@ -423,7 +426,7 @@ public class PostgreSqlTableOperations extends JdbcTableOperations {
private List<String> addColumnFieldDefinition(
TableChange.AddColumn addColumn, JdbcTable lazyLoadTable) {
if (addColumn.fieldName().length > 1) {
- throw new UnsupportedOperationException("PostgreSQL does not support nested column names.");
+ throw new UnsupportedOperationException(POSTGRESQL_NOT_SUPPORT_NESTED_COLUMN_MSG);
}
List<String> result = new ArrayList<>();
String col = addColumn.fieldName()[0];
@@ -475,7 +478,7 @@ public class PostgreSqlTableOperations extends JdbcTableOperations {
TableChange.UpdateColumnComment updateColumnComment, String tableName) {
String newComment = updateColumnComment.getNewComment();
if (updateColumnComment.fieldName().length > 1) {
- throw new UnsupportedOperationException("PostgreSQL does not support nested column names.");
+ throw new UnsupportedOperationException(POSTGRESQL_NOT_SUPPORT_NESTED_COLUMN_MSG);
}
String col = updateColumnComment.fieldName()[0];
return COLUMN_COMMENT
diff --git a/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergCatalogOperations.java b/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergCatalogOperations.java
index 9c15794c87..cdd09b94bc 100644
--- a/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergCatalogOperations.java
+++ b/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergCatalogOperations.java
@@ -60,6 +60,8 @@ import org.slf4j.LoggerFactory;
/** Operations for interacting with the Iceberg catalog in Gravitino. */
public class IcebergCatalogOperations implements CatalogOperations, SupportsSchemas, TableCatalog {
+ private static final String ICEBERG_TABLE_DOES_NOT_EXIST_MSG = "Iceberg table does not exist: %s";
+
public static final Logger LOG = LoggerFactory.getLogger(IcebergCatalogOperations.class);
@VisibleForTesting IcebergTableOps icebergTableOps;
@@ -354,7 +356,7 @@ public class IcebergCatalogOperations implements CatalogOperations, SupportsSche
LOG.info("Loaded Iceberg table {}", tableIdent.name());
return icebergTable;
} catch (org.apache.iceberg.exceptions.NoSuchTableException e) {
- throw new NoSuchTableException(e, "Iceberg table does not exist: %s", tableIdent.name());
+ throw new NoSuchTableException(e, ICEBERG_TABLE_DOES_NOT_EXIST_MSG, tableIdent.name());
}
}
@@ -402,7 +404,7 @@ public class IcebergCatalogOperations implements CatalogOperations, SupportsSche
loadTableResponse.validate();
return IcebergTable.fromIcebergTable(loadTableResponse.tableMetadata(), tableIdent.name());
} catch (org.apache.iceberg.exceptions.NoSuchTableException e) {
- throw new NoSuchTableException(e, "Iceberg table does not exist: %s", tableIdent.name());
+ throw new NoSuchTableException(e, ICEBERG_TABLE_DOES_NOT_EXIST_MSG, tableIdent.name());
}
}
@@ -428,7 +430,7 @@ public class IcebergCatalogOperations implements CatalogOperations, SupportsSche
icebergTableOps.renameTable(renameTableRequest);
return loadTable(NameIdentifier.of(tableIdent.namespace(), renameTable.getNewName()));
} catch (org.apache.iceberg.exceptions.NoSuchTableException e) {
- throw new NoSuchTableException(e, "Iceberg table does not exist: %s", tableIdent.name());
+ throw new NoSuchTableException(e, ICEBERG_TABLE_DOES_NOT_EXIST_MSG, tableIdent.name());
}
}
diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoClient.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoClient.java
index 84ad1d8ff5..80a26793f5 100644
--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoClient.java
+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoClient.java
@@ -46,6 +46,9 @@ public class GravitinoClient implements SupportsMetalakes, Closeable {
private final RESTClient restClient;
+ private static final String API_METALAKES_LIST_PATH = "api/metalakes";
+ private static final String API_METALAKES_IDENTIFIER_PATH = "api/metalakes/";
+
/**
* Constructs a new GravitinoClient with the given URI, authenticator and AuthDataProvider.
*
@@ -69,7 +72,7 @@ public class GravitinoClient implements SupportsMetalakes, Closeable {
public GravitinoMetaLake[] listMetalakes() {
MetalakeListResponse resp =
restClient.get(
- "api/metalakes",
+ API_METALAKES_LIST_PATH,
MetalakeListResponse.class,
Collections.emptyMap(),
ErrorHandlers.metalakeErrorHandler());
@@ -93,7 +96,7 @@ public class GravitinoClient implements SupportsMetalakes, Closeable {
MetalakeResponse resp =
restClient.get(
- "api/metalakes/" + ident.name(),
+ API_METALAKES_IDENTIFIER_PATH + ident.name(),
MetalakeResponse.class,
Collections.emptyMap(),
ErrorHandlers.metalakeErrorHandler());
@@ -123,7 +126,7 @@ public class GravitinoClient implements SupportsMetalakes, Closeable {
MetalakeResponse resp =
restClient.post(
- "api/metalakes",
+ API_METALAKES_LIST_PATH,
req,
MetalakeResponse.class,
Collections.emptyMap(),
@@ -156,7 +159,7 @@ public class GravitinoClient implements SupportsMetalakes, Closeable {
MetalakeResponse resp =
restClient.put(
- "api/metalakes/" + ident.name(),
+ API_METALAKES_IDENTIFIER_PATH + ident.name(),
updatesRequest,
MetalakeResponse.class,
Collections.emptyMap(),
@@ -179,7 +182,7 @@ public class GravitinoClient implements SupportsMetalakes, Closeable {
try {
DropResponse resp =
restClient.delete(
- "api/metalakes/" + ident.name(),
+ API_METALAKES_IDENTIFIER_PATH + ident.name(),
DropResponse.class,
Collections.emptyMap(),
ErrorHandlers.metalakeErrorHandler());
diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoMetaLake.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoMetaLake.java
index 7a5e18ccf7..468818c9a3 100644
--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoMetaLake.java
+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoMetaLake.java
@@ -39,6 +39,8 @@ public class GravitinoMetaLake extends MetalakeDTO implements SupportsCatalogs {
private static final Logger LOG = LoggerFactory.getLogger(GravitinoMetaLake.class);
+ private static final String API_METALAKES_CATALOGS_PATH = "api/metalakes/%s/catalogs/%s";
+
private final RESTClient restClient;
GravitinoMetaLake(
@@ -86,7 +88,7 @@ public class GravitinoMetaLake extends MetalakeDTO implements SupportsCatalogs {
CatalogResponse resp =
restClient.get(
- String.format("api/metalakes/%s/catalogs/%s", ident.namespace().level(0), ident.name()),
+ String.format(API_METALAKES_CATALOGS_PATH, ident.namespace().level(0), ident.name()),
CatalogResponse.class,
Collections.emptyMap(),
ErrorHandlers.catalogErrorHandler());
@@ -156,7 +158,7 @@ public class GravitinoMetaLake extends MetalakeDTO implements SupportsCatalogs {
CatalogResponse resp =
restClient.put(
- String.format("api/metalakes/%s/catalogs/%s", ident.namespace().level(0), ident.name()),
+ String.format(API_METALAKES_CATALOGS_PATH, ident.namespace().level(0), ident.name()),
updatesRequest,
CatalogResponse.class,
Collections.emptyMap(),
@@ -179,8 +181,7 @@ public class GravitinoMetaLake extends MetalakeDTO implements SupportsCatalogs {
try {
DropResponse resp =
restClient.delete(
- String.format(
- "api/metalakes/%s/catalogs/%s", ident.namespace().level(0), ident.name()),
+ String.format(API_METALAKES_CATALOGS_PATH, ident.namespace().level(0), ident.name()),
DropResponse.class,
Collections.emptyMap(),
ErrorHandlers.catalogErrorHandler());
diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.java b/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.java
index 1deaa6112d..40fb74d80f 100644
--- a/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.java
+++ b/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.java
@@ -67,6 +67,9 @@ import org.slf4j.LoggerFactory;
/** Manages the catalog instances and operations. */
public class CatalogManager implements SupportsCatalogs, Closeable {
+ private static final String CATALOG_DOES_NOT_EXIST_MSG = "Catalog %s does not exist";
+ private static final String METALAKE_DOES_NOT_EXIST_MSG = "Metalake %s does not exist";
+
private static final Logger LOG = LoggerFactory.getLogger(CatalogManager.class);
/** Wrapper class for a catalog instance and its class loader. */
@@ -214,7 +217,7 @@ public class CatalogManager implements SupportsCatalogs, Closeable {
}
if (!metalakeExists) {
- throw new NoSuchMetalakeException("Metalake %s does not exist", metalakeIdent);
+ throw new NoSuchMetalakeException(METALAKE_DOES_NOT_EXIST_MSG, metalakeIdent);
}
try {
@@ -287,7 +290,7 @@ public class CatalogManager implements SupportsCatalogs, Closeable {
NameIdentifier metalakeIdent = NameIdentifier.of(ident.namespace().levels());
if (!store.exists(metalakeIdent, EntityType.METALAKE)) {
LOG.warn("Metalake {} does not exist", metalakeIdent);
- throw new NoSuchMetalakeException("Metalake %s does not exist", metalakeIdent);
+ throw new NoSuchMetalakeException(METALAKE_DOES_NOT_EXIST_MSG, metalakeIdent);
}
// TODO: should avoid a race condition here
@@ -343,7 +346,7 @@ public class CatalogManager implements SupportsCatalogs, Closeable {
CatalogWrapper catalogWrapper = loadCatalogAndWrap(ident);
if (catalogWrapper == null) {
- throw new NoSuchCatalogException("Catalog %s does not exist", ident);
+ throw new NoSuchCatalogException(CATALOG_DOES_NOT_EXIST_MSG, ident);
}
try {
@@ -402,7 +405,7 @@ public class CatalogManager implements SupportsCatalogs, Closeable {
} catch (NoSuchEntityException ne) {
LOG.warn("Catalog {} does not exist", ident, ne);
- throw new NoSuchCatalogException("Catalog %s does not exist", ident);
+ throw new NoSuchCatalogException(CATALOG_DOES_NOT_EXIST_MSG, ident);
} catch (IllegalArgumentException iae) {
LOG.warn("Failed to alter catalog {} with unknown change", ident, iae);
@@ -452,7 +455,7 @@ public class CatalogManager implements SupportsCatalogs, Closeable {
} catch (NoSuchEntityException ne) {
LOG.warn("Catalog {} does not exist", ident, ne);
- throw new NoSuchCatalogException("Catalog %s does not exist", ident);
+ throw new NoSuchCatalogException(CATALOG_DOES_NOT_EXIST_MSG, ident);
} catch (IOException ioe) {
LOG.error("Failed to load catalog {}", ident, ioe);
diff --git a/core/src/main/java/com/datastrato/gravitino/meta/MetalakeManager.java b/core/src/main/java/com/datastrato/gravitino/meta/MetalakeManager.java
index 59e72ebd3d..26db628757 100644
--- a/core/src/main/java/com/datastrato/gravitino/meta/MetalakeManager.java
+++ b/core/src/main/java/com/datastrato/gravitino/meta/MetalakeManager.java
@@ -27,6 +27,8 @@ import org.slf4j.LoggerFactory;
/** Manages Metalakes within the Gravitino system. */
public class MetalakeManager implements SupportsMetalakes {
+ private static final String METALAKE_DOES_NOT_EXIST_MSG = "Metalake %s does not exist";
+
private static final Logger LOG = LoggerFactory.getLogger(MetalakeManager.class);
private final EntityStore store;
@@ -75,7 +77,7 @@ public class MetalakeManager implements SupportsMetalakes {
return store.get(ident, EntityType.METALAKE, BaseMetalake.class);
} catch (NoSuchEntityException e) {
LOG.warn("Metalake {} does not exist", ident, e);
- throw new NoSuchMetalakeException("Metalake %s does not exist", ident);
+ throw new NoSuchMetalakeException(METALAKE_DOES_NOT_EXIST_MSG, ident);
} catch (IOException ioe) {
LOG.error("Loading Metalake {} failed due to storage issues", ident, ioe);
throw new RuntimeException(ioe);
@@ -173,7 +175,7 @@ public class MetalakeManager implements SupportsMetalakes {
} catch (NoSuchEntityException ne) {
LOG.warn("Metalake {} does not exist", ident, ne);
- throw new NoSuchMetalakeException("Metalake %s does not exist", ident);
+ throw new NoSuchMetalakeException(METALAKE_DOES_NOT_EXIST_MSG, ident);
} catch (IllegalArgumentException iae) {
LOG.warn("Altering Metalake {} failed due to invalid changes", ident, iae);
diff --git a/core/src/main/java/com/datastrato/gravitino/storage/kv/KvEntityStore.java b/core/src/main/java/com/datastrato/gravitino/storage/kv/KvEntityStore.java
index 3932d0b45e..8c27a2a83a 100644
--- a/core/src/main/java/com/datastrato/gravitino/storage/kv/KvEntityStore.java
+++ b/core/src/main/java/com/datastrato/gravitino/storage/kv/KvEntityStore.java
@@ -60,6 +60,9 @@ import org.slf4j.LoggerFactory;
* interface
*/
public class KvEntityStore implements EntityStore {
+
+ private static final String NO_SUCH_ENTITY_MSG = "No such entity:%s";
+
public static final Logger LOGGER = LoggerFactory.getLogger(KvEntityStore.class);
public static final ImmutableMap<String, String> KV_BACKENDS =
ImmutableMap.of("RocksDBKvBackend", RocksDBKvBackend.class.getCanonicalName());
@@ -176,7 +179,7 @@ public class KvEntityStore implements EntityStore {
byte[] key = entityKeyEncoder.encode(ident, entityType);
byte[] value = transactionalKvBackend.get(key);
if (value == null) {
- throw new NoSuchEntityException("No such entity:%s", ident.toString());
+ throw new NoSuchEntityException(NO_SUCH_ENTITY_MSG, ident.toString());
}
E e = serDe.deserialize(value, type);
@@ -271,12 +274,12 @@ public class KvEntityStore implements EntityStore {
() -> {
byte[] key = entityKeyEncoder.encode(ident, entityType, true);
if (key == null) {
- throw new NoSuchEntityException("No such entity:%s", ident.toString());
+ throw new NoSuchEntityException(NO_SUCH_ENTITY_MSG, ident.toString());
}
return transactionalKvBackend.get(key);
});
if (value == null) {
- throw new NoSuchEntityException("No such entity:%s", ident.toString());
+ throw new NoSuchEntityException(NO_SUCH_ENTITY_MSG, ident.toString());
}
return serDe.deserialize(value, e);
}
diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/mysql/MySQLBackend.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/mysql/MySQLBackend.java
index 4b793a02dd..06aa430a16 100644
--- a/core/src/main/java/com/datastrato/gravitino/storage/relational/mysql/MySQLBackend.java
+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/mysql/MySQLBackend.java
@@ -23,6 +23,8 @@ import java.util.function.Function;
*/
public class MySQLBackend implements RelationalBackend {
+ private static final String UNSUPPORTED_OPERATION_MSG = "Unsupported operation now.";
+
/** Initialize the MySQL backend instance. */
@Override
public void initialize(Config config) {}
@@ -30,36 +32,36 @@ public class MySQLBackend implements RelationalBackend {
@Override
public <E extends Entity & HasIdentifier> List<E> list(
Namespace namespace, Entity.EntityType entityType) throws NoSuchEntityException {
- throw new UnsupportedOperationException("Unsupported operation now.");
+ throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MSG);
}
@Override
public boolean exists(NameIdentifier ident, Entity.EntityType entityType) {
- throw new UnsupportedOperationException("Unsupported operation now.");
+ throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MSG);
}
@Override
public <E extends Entity & HasIdentifier> void insert(E e, boolean overwritten)
throws EntityAlreadyExistsException {
- throw new UnsupportedOperationException("Unsupported operation now.");
+ throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MSG);
}
@Override
public <E extends Entity & HasIdentifier> E update(
NameIdentifier ident, Entity.EntityType entityType, Function<E, E> updater)
throws NoSuchEntityException {
- throw new UnsupportedOperationException("Unsupported operation now.");
+ throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MSG);
}
@Override
public <E extends Entity & HasIdentifier> E get(
NameIdentifier ident, Entity.EntityType entityType) throws IOException {
- throw new UnsupportedOperationException("Unsupported operation now.");
+ throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MSG);
}
@Override
public boolean delete(NameIdentifier ident, Entity.EntityType entityType, boolean cascade) {
- throw new UnsupportedOperationException("Unsupported operation now.");
+ throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MSG);
}
@Override
diff --git a/server/src/main/java/com/datastrato/gravitino/server/GravitinoServer.java b/server/src/main/java/com/datastrato/gravitino/server/GravitinoServer.java
index 2007bed0b5..470099d7cc 100644
--- a/server/src/main/java/com/datastrato/gravitino/server/GravitinoServer.java
+++ b/server/src/main/java/com/datastrato/gravitino/server/GravitinoServer.java
@@ -32,6 +32,8 @@ public class GravitinoServer extends ResourceConfig {
private static final Logger LOG = LoggerFactory.getLogger(GravitinoServer.class);
+ private static final String API_ANY_PATH = "/api/*";
+
public static final String CONF_FILE = "gravitino.conf";
public static final String WEBSERVER_CONF_PREFIX = "gravitino.server.webserver.";
@@ -84,12 +86,12 @@ public class GravitinoServer extends ResourceConfig {
metricsSystem.register(httpServerMetricsSource);
Servlet servlet = new ServletContainer(this);
- server.addServlet(servlet, "/api/*");
+ server.addServlet(servlet, API_ANY_PATH);
Servlet configServlet = new ConfigServlet(serverConfig);
server.addServlet(configServlet, "/configs");
- server.addCustomFilters("/api/*");
- server.addFilter(new VersioningFilter(), "/api/*");
- server.addSystemFilters("/api/*");
+ server.addCustomFilters(API_ANY_PATH);
+ server.addFilter(new VersioningFilter(), API_ANY_PATH);
+ server.addSystemFilters(API_ANY_PATH);
server.addFilter(new WebUIFilter(), "/"); // Redirect to the /ui/index html page.
server.addFilter(new WebUIFilter(), "/ui/*"); // Redirect to the static html file.
}
diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorMetadata.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorMetadata.java
index 99e2e5aa1b..9fe690bb5f 100644
--- a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorMetadata.java
+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorMetadata.java
@@ -43,6 +43,9 @@ import org.apache.commons.lang3.NotImplementedException;
/** This class implements gravitino metadata operators. */
public class CatalogConnectorMetadata {
+ private static final String CATALOG_DOES_NOT_EXIST_MSG = "Catalog does not exist";
+ private static final String SCHEMA_DOES_NOT_EXIST_MSG = "Schema does not exist";
+
private final GravitinoMetaLake metalake;
private final String catalogName;
private final SupportsSchemas schemaCatalog;
@@ -57,7 +60,7 @@ public class CatalogConnectorMetadata {
this.schemaCatalog = catalog.asSchemas();
this.tableCatalog = catalog.asTableCatalog();
} catch (NoSuchCatalogException e) {
- throw new TrinoException(GRAVITINO_CATALOG_NOT_EXISTS, "Catalog does not exist", e);
+ throw new TrinoException(GRAVITINO_CATALOG_NOT_EXISTS, CATALOG_DOES_NOT_EXIST_MSG, e);
} catch (UnsupportedOperationException e) {
throw new TrinoException(
GRAVITINO_UNSUPPORTED_OPERATION,
@@ -73,7 +76,7 @@ public class CatalogConnectorMetadata {
.map(NameIdentifier::name)
.toList();
} catch (NoSuchCatalogException e) {
- throw new TrinoException(GRAVITINO_CATALOG_NOT_EXISTS, "Catalog does not exist", e);
+ throw new TrinoException(GRAVITINO_CATALOG_NOT_EXISTS, CATALOG_DOES_NOT_EXIST_MSG, e);
}
}
@@ -84,7 +87,7 @@ public class CatalogConnectorMetadata {
NameIdentifier.ofSchema(metalake.name(), catalogName, schemaName));
return new GravitinoSchema(schema);
} catch (NoSuchSchemaException e) {
- throw new TrinoException(GRAVITINO_SCHEMA_NOT_EXISTS, "Schema does not exist", e);
+ throw new TrinoException(GRAVITINO_SCHEMA_NOT_EXISTS, SCHEMA_DOES_NOT_EXIST_MSG, e);
}
}
@@ -105,7 +108,7 @@ public class CatalogConnectorMetadata {
tableCatalog.listTables(Namespace.ofTable(metalake.name(), catalogName, schemaName));
return Arrays.stream(tables).map(NameIdentifier::name).toList();
} catch (NoSuchSchemaException e) {
- throw new TrinoException(GRAVITINO_SCHEMA_NOT_EXISTS, "Schema does not exist", e);
+ throw new TrinoException(GRAVITINO_SCHEMA_NOT_EXISTS, SCHEMA_DOES_NOT_EXIST_MSG, e);
}
}
@@ -128,7 +131,7 @@ public class CatalogConnectorMetadata {
table.getDistribution(),
table.getSortOrders());
} catch (NoSuchSchemaException e) {
- throw new TrinoException(GRAVITINO_SCHEMA_NOT_EXISTS, "Schema does not exist", e);
+ throw new TrinoException(GRAVITINO_SCHEMA_NOT_EXISTS, SCHEMA_DOES_NOT_EXIST_MSG, e);
} catch (TableAlreadyExistsException e) {
throw new TrinoException(GRAVITINO_TABLE_ALREADY_EXISTS, "Table already exists", e);
}
@@ -141,7 +144,7 @@ public class CatalogConnectorMetadata {
schema.getComment(),
schema.getProperties());
} catch (NoSuchSchemaException e) {
- throw new TrinoException(GRAVITINO_CATALOG_NOT_EXISTS, "Catalog does not exist", e);
+ throw new TrinoException(GRAVITINO_CATALOG_NOT_EXISTS, CATALOG_DOES_NOT_EXIST_MSG, e);
} catch (TableAlreadyExistsException e) {
throw new TrinoException(GRAVITINO_SCHEMA_ALREADY_EXISTS, "Schema already exists", e);
}