Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import static org.apache.amoro.properties.CatalogMetaProperties.CATALOG_TYPE_AMS;
import static org.apache.amoro.properties.CatalogMetaProperties.CATALOG_TYPE_CUSTOM;
import static org.apache.amoro.properties.CatalogMetaProperties.CATALOG_TYPE_FILESYSTEM;
import static org.apache.amoro.properties.CatalogMetaProperties.CATALOG_TYPE_GLUE;
import static org.apache.amoro.properties.CatalogMetaProperties.CATALOG_TYPE_HADOOP;
import static org.apache.amoro.properties.CatalogMetaProperties.CATALOG_TYPE_HIVE;
Expand All @@ -42,6 +43,9 @@ public class CatalogBuilder {
private static final Map<String, Set<TableFormat>> formatSupportedMatrix =
ImmutableMap.of(
CATALOG_TYPE_HADOOP,
Sets.newHashSet(
TableFormat.ICEBERG, TableFormat.MIXED_ICEBERG, TableFormat.PAIMON, TableFormat.HUDI),
CATALOG_TYPE_FILESYSTEM,
Sets.newHashSet(
TableFormat.ICEBERG, TableFormat.MIXED_ICEBERG, TableFormat.PAIMON, TableFormat.HUDI),
CATALOG_TYPE_GLUE,
Expand Down Expand Up @@ -77,6 +81,7 @@ public static ServerCatalog buildServerCatalog(

switch (type) {
case CATALOG_TYPE_HADOOP:
case CATALOG_TYPE_FILESYSTEM:
case CATALOG_TYPE_GLUE:
case CATALOG_TYPE_REST:
case CATALOG_TYPE_CUSTOM:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.amoro.shade.guava32.com.google.common.cache.LoadingCache;
import org.apache.amoro.shade.guava32.com.google.common.collect.Maps;
import org.apache.amoro.table.TableIdentifier;
import org.apache.amoro.utils.CatalogUtil;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -230,7 +231,9 @@ public AmoroTable<?> loadTable(TableIdentifier identifier) {
}

private void validateCatalogUpdate(CatalogMeta oldMeta, CatalogMeta newMeta) {
if (!oldMeta.getCatalogType().equals(newMeta.getCatalogType())) {
String oldType = CatalogUtil.normalizeMetastoreType(oldMeta.getCatalogType());
String newType = CatalogUtil.normalizeMetastoreType(newMeta.getCatalogType());
if (!oldType.equals(newType)) {
throw new IllegalMetadataException("Cannot update catalog type");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ private EndpointGroup apiGroup() {
get("", tableController::getCatalogs);
post("", catalogController::createCatalog);
get("metastore/types", catalogController::getCatalogTypeList);
get("metastore/{type}/table-formats", catalogController::getMetastoreTableFormats);
get("metastore/{type}/storage-types", catalogController::getMetastoreStorageTypes);
get("/{catalogName}", catalogController::getCatalogDetail);
delete("/{catalogName}", catalogController::deleteCatalog);
put("/{catalogName}", catalogController::updateCatalog);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static org.apache.amoro.properties.CatalogMetaProperties.AUTH_CONFIGS_VALUE_TYPE_SIMPLE;
import static org.apache.amoro.properties.CatalogMetaProperties.CATALOG_TYPE_AMS;
import static org.apache.amoro.properties.CatalogMetaProperties.CATALOG_TYPE_CUSTOM;
import static org.apache.amoro.properties.CatalogMetaProperties.CATALOG_TYPE_FILESYSTEM;
import static org.apache.amoro.properties.CatalogMetaProperties.CATALOG_TYPE_GLUE;
import static org.apache.amoro.properties.CatalogMetaProperties.CATALOG_TYPE_HADOOP;
import static org.apache.amoro.properties.CatalogMetaProperties.CATALOG_TYPE_HIVE;
Expand All @@ -48,6 +49,7 @@
import static org.apache.amoro.properties.CatalogMetaProperties.STORAGE_CONFIGS_KEY_S3_ENDPOINT;
import static org.apache.amoro.properties.CatalogMetaProperties.STORAGE_CONFIGS_KEY_TYPE;
import static org.apache.amoro.properties.CatalogMetaProperties.STORAGE_CONFIGS_VALUE_TYPE_HADOOP;
import static org.apache.amoro.properties.CatalogMetaProperties.STORAGE_CONFIGS_VALUE_TYPE_LOCAL;
import static org.apache.amoro.properties.CatalogMetaProperties.STORAGE_CONFIGS_VALUE_TYPE_OSS;
import static org.apache.amoro.properties.CatalogMetaProperties.STORAGE_CONFIGS_VALUE_TYPE_S3;
import static org.apache.amoro.properties.CatalogMetaProperties.TABLE_FORMATS;
Expand Down Expand Up @@ -106,6 +108,8 @@ public class CatalogController {
CATALOG_REQUIRED_PROPERTIES.put(CATALOG_TYPE_AMS, Lists.newArrayList(KEY_WAREHOUSE));
CATALOG_REQUIRED_PROPERTIES.put(
CATALOG_TYPE_HADOOP, Lists.newArrayList(CatalogProperties.WAREHOUSE_LOCATION));
CATALOG_REQUIRED_PROPERTIES.put(
CATALOG_TYPE_FILESYSTEM, Lists.newArrayList(CatalogProperties.WAREHOUSE_LOCATION));
CATALOG_REQUIRED_PROPERTIES.put(
CATALOG_TYPE_GLUE, Lists.newArrayList(CatalogProperties.WAREHOUSE_LOCATION));
CATALOG_REQUIRED_PROPERTIES.put(
Expand Down Expand Up @@ -146,6 +150,17 @@ public class CatalogController {
CatalogDescriptor.of(CATALOG_TYPE_HADOOP, STORAGE_CONFIGS_VALUE_TYPE_HADOOP, PAIMON));
VALIDATE_CATALOGS.add(
CatalogDescriptor.of(CATALOG_TYPE_HADOOP, STORAGE_CONFIGS_VALUE_TYPE_S3, PAIMON));
VALIDATE_CATALOGS.add(
CatalogDescriptor.of(
CATALOG_TYPE_FILESYSTEM, STORAGE_CONFIGS_VALUE_TYPE_HADOOP, MIXED_ICEBERG));
VALIDATE_CATALOGS.add(
CatalogDescriptor.of(CATALOG_TYPE_FILESYSTEM, STORAGE_CONFIGS_VALUE_TYPE_HADOOP, ICEBERG));
VALIDATE_CATALOGS.add(
CatalogDescriptor.of(CATALOG_TYPE_FILESYSTEM, STORAGE_CONFIGS_VALUE_TYPE_LOCAL, ICEBERG));
VALIDATE_CATALOGS.add(
CatalogDescriptor.of(CATALOG_TYPE_FILESYSTEM, STORAGE_CONFIGS_VALUE_TYPE_HADOOP, PAIMON));
VALIDATE_CATALOGS.add(
CatalogDescriptor.of(CATALOG_TYPE_FILESYSTEM, STORAGE_CONFIGS_VALUE_TYPE_S3, PAIMON));
VALIDATE_CATALOGS.add(
CatalogDescriptor.of(CATALOG_TYPE_GLUE, STORAGE_CONFIGS_VALUE_TYPE_S3, ICEBERG));
VALIDATE_CATALOGS.add(
Expand All @@ -156,6 +171,8 @@ public class CatalogController {
CatalogDescriptor.of(CATALOG_TYPE_CUSTOM, STORAGE_CONFIGS_VALUE_TYPE_HADOOP, ICEBERG));
VALIDATE_CATALOGS.add(
CatalogDescriptor.of(CATALOG_TYPE_HADOOP, STORAGE_CONFIGS_VALUE_TYPE_OSS, PAIMON));
VALIDATE_CATALOGS.add(
CatalogDescriptor.of(CATALOG_TYPE_FILESYSTEM, STORAGE_CONFIGS_VALUE_TYPE_OSS, PAIMON));
VALIDATE_CATALOGS.add(
CatalogDescriptor.of(CATALOG_TYPE_GLUE, STORAGE_CONFIGS_VALUE_TYPE_OSS, ICEBERG));
VALIDATE_CATALOGS.add(
Expand Down Expand Up @@ -232,9 +249,9 @@ public void getCatalogTypeList(Context ctx) {
List<ImmutableMap<String, String>> catalogTypes = new ArrayList<>();
String valueKey = "value";
String displayKey = "display";
catalogTypes.add(ImmutableMap.of(valueKey, CATALOG_TYPE_AMS, displayKey, "Amoro Metastore"));
catalogTypes.add(ImmutableMap.of(valueKey, CATALOG_TYPE_HIVE, displayKey, "Hive Metastore"));
catalogTypes.add(ImmutableMap.of(valueKey, CATALOG_TYPE_HADOOP, displayKey, "Filesystem"));
catalogTypes.add(ImmutableMap.of(valueKey, CATALOG_TYPE_AMS, displayKey, "Internal"));
catalogTypes.add(ImmutableMap.of(valueKey, CATALOG_TYPE_HIVE, displayKey, "Hive"));
catalogTypes.add(ImmutableMap.of(valueKey, CATALOG_TYPE_FILESYSTEM, displayKey, "FileSystem"));
catalogTypes.add(ImmutableMap.of(valueKey, CATALOG_TYPE_GLUE, displayKey, "Glue"));
catalogTypes.add(ImmutableMap.of(valueKey, CATALOG_TYPE_REST, displayKey, "REST"));
catalogTypes.add(ImmutableMap.of(valueKey, CATALOG_TYPE_CUSTOM, displayKey, "Custom"));
Expand Down Expand Up @@ -432,14 +449,15 @@ private Map<String, Object> extractStorageConfigsFromCatalogMeta(
private CatalogMeta constructCatalogMeta(CatalogRegisterInfo info, CatalogMeta oldCatalogMeta) {
CatalogMeta catalogMeta = new CatalogMeta();
catalogMeta.setCatalogName(info.getName());
catalogMeta.setCatalogType(info.getType());
String metastoreType = CatalogUtil.normalizeMetastoreType(info.getType());
catalogMeta.setCatalogType(metastoreType);
catalogMeta.setCatalogProperties(
PropertiesUtil.unionCatalogProperties(info.getTableProperties(), info.getProperties()));
// fill catalog impl when catalog type is glue or rest
if (CatalogMetaProperties.CATALOG_TYPE_GLUE.equals(info.getType())) {
if (CatalogMetaProperties.CATALOG_TYPE_GLUE.equals(metastoreType)) {
catalogMeta.putToCatalogProperties(
CatalogProperties.CATALOG_IMPL, GlueCatalog.class.getName());
} else if (CatalogMetaProperties.CATALOG_TYPE_REST.equals(info.getType())) {
} else if (CatalogMetaProperties.CATALOG_TYPE_REST.equals(metastoreType)) {
catalogMeta.putToCatalogProperties(
CatalogProperties.CATALOG_IMPL, RESTCatalog.class.getName());
}
Expand Down Expand Up @@ -519,6 +537,8 @@ private CatalogMeta constructCatalogMeta(CatalogRegisterInfo info, CatalogMeta o
STORAGE_CONFIGS_KEY_OSS_ENDPOINT,
"fs.oss.endpoint");
}
} else if (storageType.equals(STORAGE_CONFIGS_VALUE_TYPE_LOCAL)) {
// Local storage type does not require additional storage configs.
} else {
throw new RuntimeException("Invalid storage type " + storageType);
}
Expand Down Expand Up @@ -622,12 +642,11 @@ public void getCatalogDetail(Context ctx) {

if (catalogService.catalogExist(catalogName)) {
info.setName(catalogMeta.getCatalogName());
// We create ams catalog with type hadoop in v0.3, we should be compatible with it.
if (CATALOG_TYPE_HADOOP.equals(catalogMeta.getCatalogType())
&& !catalogMeta.getCatalogProperties().containsKey(TABLE_FORMATS)) {
info.setType(CATALOG_TYPE_AMS);
} else {
info.setType(catalogMeta.getCatalogType());
info.setType(CatalogUtil.normalizeMetastoreType(catalogMeta.getCatalogType()));
}

// we put the table format single
Expand Down Expand Up @@ -732,6 +751,30 @@ public void getCatalogConfFileContent(Context ctx) {
}
}

public void getMetastoreTableFormats(Context ctx) {
String metastoreType = ctx.pathParam("type");
String normalizedType = CatalogUtil.normalizeMetastoreType(metastoreType);
List<String> tableFormats =
VALIDATE_CATALOGS.stream()
.filter(d -> d.catalogType.equalsIgnoreCase(normalizedType))
.map(d -> d.tableFormat.name())
.distinct()
.collect(Collectors.toList());
ctx.json(OkResponse.of(tableFormats));
}

public void getMetastoreStorageTypes(Context ctx) {
String metastoreType = ctx.pathParam("type");
String normalizedType = CatalogUtil.normalizeMetastoreType(metastoreType);
List<String> storageTypes =
VALIDATE_CATALOGS.stream()
.filter(d -> d.catalogType.equalsIgnoreCase(normalizedType))
.map(d -> d.storageType)
.distinct()
.collect(Collectors.toList());
ctx.json(OkResponse.of(storageTypes));
}

private static class CatalogDescriptor {
private final String catalogType;
private final String storageType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.amoro.shade.guava32.com.google.common.collect.Maps;
import org.apache.amoro.table.TableMetaStore;
import org.apache.amoro.utils.CatalogUtil;
import org.apache.hadoop.conf.Configuration;
import org.apache.iceberg.CatalogProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -250,7 +251,7 @@ public void dispose() {
// ========================== private method =========================

private String catalogConnectorType(CatalogMeta catalogMeta) {
String catalogType = catalogMeta.getCatalogType();
String catalogType = CatalogUtil.normalizeCatalogType(catalogMeta.getCatalogType());
Set<TableFormat> tableFormatSet = CatalogUtil.tableFormats(catalogMeta);
if (catalogType.equalsIgnoreCase(CatalogType.AMS.name())) {
if (tableFormatSet.size() > 1) {
Expand Down Expand Up @@ -301,8 +302,12 @@ private TableMetaStore getCatalogTableMetaStore(CatalogMeta catalogMeta) {
TableMetaStore.Builder builder = TableMetaStore.builder();
if (catalogMeta.getStorageConfigs() != null) {
Map<String, String> storageConfigs = catalogMeta.getStorageConfigs();
if (CatalogMetaProperties.STORAGE_CONFIGS_VALUE_TYPE_HADOOP.equalsIgnoreCase(
CatalogUtil.getCompatibleStorageType(storageConfigs))) {
String storageType = CatalogUtil.getCompatibleStorageType(storageConfigs);
if (CatalogMetaProperties.STORAGE_CONFIGS_VALUE_TYPE_LOCAL.equalsIgnoreCase(storageType)) {
builder.withConfiguration(new Configuration());
return builder.build();
}
if (CatalogMetaProperties.STORAGE_CONFIGS_VALUE_TYPE_HADOOP.equalsIgnoreCase(storageType)) {
builder
.withBase64MetaStoreSite(
catalogMeta
Expand Down Expand Up @@ -388,7 +393,7 @@ private TerminalSessionFactory loadTerminalSessionFactory(Configurations conf) {

private void applyClientProperties(CatalogMeta catalogMeta) {
Set<TableFormat> formats = CatalogUtil.tableFormats(catalogMeta);
String catalogType = catalogMeta.getCatalogType();
String catalogType = CatalogUtil.normalizeCatalogType(catalogMeta.getCatalogType());
if (formats.contains(TableFormat.ICEBERG)) {
if (CatalogMetaProperties.CATALOG_TYPE_AMS.equalsIgnoreCase(catalogType)) {
catalogMeta.putToCatalogProperties(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,17 @@ public Map<String, String> properties() {

protected void initializeFormatCatalogs() {
ServiceLoader<FormatCatalogFactory> loader = ServiceLoader.load(FormatCatalogFactory.class);
Set<TableFormat> formats = CatalogUtil.tableFormats(metaStoreType, catalogProperties);
String normalizedMetastoreType = CatalogUtil.normalizeMetastoreType(metaStoreType);
Set<TableFormat> formats = CatalogUtil.tableFormats(normalizedMetastoreType, catalogProperties);
Map<TableFormat, FormatCatalog> formatCatalogs = Maps.newConcurrentMap();
for (FormatCatalogFactory factory : loader) {
if (formats.contains(factory.format())) {
Map<String, String> formatCatalogProperties =
factory.convertCatalogProperties(name(), metaStoreType, this.catalogProperties);
factory.convertCatalogProperties(
name(), normalizedMetastoreType, this.catalogProperties);
FormatCatalog catalog =
factory.create(name(), metaStoreType, formatCatalogProperties, tableMetaStore);
factory.create(
name(), normalizedMetastoreType, formatCatalogProperties, tableMetaStore);
formatCatalogs.put(factory.format(), catalog);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class CatalogMetaProperties {
public static final String STORAGE_CONFIGS_VALUE_TYPE_HADOOP = "Hadoop";
public static final String STORAGE_CONFIGS_VALUE_TYPE_S3 = "S3";
public static final String STORAGE_CONFIGS_VALUE_TYPE_OSS = "OSS";
public static final String STORAGE_CONFIGS_VALUE_TYPE_LOCAL = "Local";

public static final String AUTH_CONFIGS_KEY_TYPE = "auth.type";
public static final String AUTH_CONFIGS_KEY_PRINCIPAL = "auth.kerberos.principal";
Expand All @@ -53,7 +54,13 @@ public class CatalogMetaProperties {

public static final String KEY_TABLE_FILTER = "table-filter";

public static final String CATALOG_TYPE_HADOOP = "hadoop";
/**
* Use {@link #CATALOG_TYPE_FILESYSTEM} instead for front But we can't remove this until we could
* use filesystem and storage to determine the right catalog-impl
*/
@Deprecated public static final String CATALOG_TYPE_HADOOP = "hadoop";

public static final String CATALOG_TYPE_FILESYSTEM = "filesystem";
public static final String CATALOG_TYPE_HIVE = "hive";
public static final String CATALOG_TYPE_AMS = "ams";
public static final String CATALOG_TYPE_GLUE = "glue";
Expand Down
Loading