Skip to content

Commit

Permalink
Add support for case-insensitive object names in Iceberg REST catalog
Browse files Browse the repository at this point in the history
Certain Rest catalog implementation(eg. Polaris) supports
case-sensitive object(namespace, table, view etc.) names. This
change allows querying mixed/upper case letter objects in rest
catalog from Trino.
`iceberg.rest-catalog.case-insensitive-name-matching` controls
whether to match lowercase object names in Trino with different case
object names in rest catalog with the limitations that only single
object name with the same name is supported.
  • Loading branch information
mayankvadariya committed Oct 29, 2024
1 parent 75fa7cb commit 02f3279
Show file tree
Hide file tree
Showing 7 changed files with 533 additions and 28 deletions.
7 changes: 6 additions & 1 deletion docs/src/main/sphinx/object-storage/metastores.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,12 @@ following properties:
* - `iceberg.rest-catalog.vended-credentials-enabled`
- Use credentials provided by the REST backend for file system access.
Defaults to `false`.
:::
* - `iceberg.rest-catalog.case-insensitive-name-matching`
- Match namespace, table, and view names case insensitively. Defaults to `false`.
* - `iceberg.rest-catalog.case-insensitive-name-matching.cache-ttl`
- [Duration](prop-type-duration) for which case-insensitive namespace, table, and view
names are cached. Defaults to `1m`.
:::

The following example shows a minimal catalog configuration using an Iceberg
REST metadata catalog:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@

import io.airlift.configuration.Config;
import io.airlift.configuration.ConfigDescription;
import io.airlift.units.Duration;
import io.airlift.units.MinDuration;
import jakarta.validation.constraints.NotNull;
import org.apache.iceberg.catalog.Namespace;

import java.net.URI;
import java.util.Optional;

import static java.util.concurrent.TimeUnit.MINUTES;

public class IcebergRestCatalogConfig
{
public enum Security
Expand All @@ -42,6 +46,8 @@ public enum SessionType
private Security security = Security.NONE;
private SessionType sessionType = SessionType.NONE;
private boolean vendedCredentialsEnabled;
private boolean caseInsensitiveNameMatching;
private Duration caseInsensitiveNameMatchingCacheTtl = new Duration(1, MINUTES);

@NotNull
public URI getBaseUri()
Expand Down Expand Up @@ -138,4 +144,32 @@ public IcebergRestCatalogConfig setVendedCredentialsEnabled(boolean vendedCreden
this.vendedCredentialsEnabled = vendedCredentialsEnabled;
return this;
}

public boolean isCaseInsensitiveNameMatching()
{
return caseInsensitiveNameMatching;
}

@Config("iceberg.rest-catalog.case-insensitive-name-matching")
@ConfigDescription("Match object names case-insensitively")
public IcebergRestCatalogConfig setCaseInsensitiveNameMatching(boolean caseInsensitiveNameMatching)
{
this.caseInsensitiveNameMatching = caseInsensitiveNameMatching;
return this;
}

@NotNull
@MinDuration("0ms")
public Duration getCaseInsensitiveNameMatchingCacheTtl()
{
return caseInsensitiveNameMatchingCacheTtl;
}

@Config("iceberg.rest-catalog.case-insensitive-name-matching.cache-ttl")
@ConfigDescription("Duration to keep case insensitive object mapping prior to eviction")
public IcebergRestCatalogConfig setCaseInsensitiveNameMatchingCacheTtl(Duration caseInsensitiveNameMatchingCacheTtl)
{
this.caseInsensitiveNameMatchingCacheTtl = caseInsensitiveNameMatchingCacheTtl;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
*/
package io.trino.plugin.iceberg.catalog.rest;

import com.google.common.cache.Cache;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.errorprone.annotations.concurrent.GuardedBy;
import com.google.inject.Inject;
import io.trino.cache.EvictableCacheBuilder;
import io.trino.plugin.hive.NodeVersion;
import io.trino.plugin.iceberg.IcebergConfig;
import io.trino.plugin.iceberg.IcebergFileSystemFactory;
Expand All @@ -29,6 +31,7 @@
import io.trino.spi.type.TypeManager;
import org.apache.iceberg.CatalogProperties;
import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.rest.HTTPClient;
import org.apache.iceberg.rest.RESTSessionCatalog;

Expand All @@ -38,6 +41,7 @@
import java.util.Set;

import static java.util.Objects.requireNonNull;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.apache.iceberg.rest.auth.OAuth2Properties.CREDENTIAL;
import static org.apache.iceberg.rest.auth.OAuth2Properties.TOKEN;

Expand All @@ -56,6 +60,10 @@ public class TrinoIcebergRestCatalogFactory
private final SecurityProperties securityProperties;
private final boolean uniqueTableLocation;
private final TypeManager typeManager;
private final boolean caseInsensitiveNameMatching;
private final Cache<Namespace, Namespace> remoteNamespaceMappingCache;
private final Cache<TableIdentifier, TableIdentifier> remoteTableMappingCache;
private final Cache<TableIdentifier, TableIdentifier> remoteViewMappingCache;

@GuardedBy("this")
private RESTSessionCatalog icebergCatalog;
Expand Down Expand Up @@ -84,6 +92,19 @@ public TrinoIcebergRestCatalogFactory(
requireNonNull(icebergConfig, "icebergConfig is null");
this.uniqueTableLocation = icebergConfig.isUniqueTableLocation();
this.typeManager = requireNonNull(typeManager, "typeManager is null");
this.caseInsensitiveNameMatching = restConfig.isCaseInsensitiveNameMatching();
this.remoteNamespaceMappingCache = EvictableCacheBuilder.newBuilder()
.expireAfterWrite(restConfig.getCaseInsensitiveNameMatchingCacheTtl().toMillis(), MILLISECONDS)
.shareNothingWhenDisabled()
.build();
this.remoteTableMappingCache = EvictableCacheBuilder.newBuilder()
.expireAfterWrite(restConfig.getCaseInsensitiveNameMatchingCacheTtl().toMillis(), MILLISECONDS)
.shareNothingWhenDisabled()
.build();
this.remoteViewMappingCache = EvictableCacheBuilder.newBuilder()
.expireAfterWrite(restConfig.getCaseInsensitiveNameMatchingCacheTtl().toMillis(), MILLISECONDS)
.shareNothingWhenDisabled()
.build();
}

@Override
Expand Down Expand Up @@ -128,6 +149,10 @@ public synchronized TrinoCatalog create(ConnectorIdentity identity)
parentNamespace,
trinoVersion,
typeManager,
uniqueTableLocation);
uniqueTableLocation,
caseInsensitiveNameMatching,
remoteNamespaceMappingCache,
remoteTableMappingCache,
remoteViewMappingCache);
}
}
Loading

0 comments on commit 02f3279

Please sign in to comment.