Repository: prestodb/presto
Pull request #24179: Add a native type manager
Author: login: pdabre12
Labels: name: from:IBM
description: PR from IBM
Created: 2024-12-02T22:11:07Z | Merged: 2025-03-26T19:44:37Z

## Description
With the introduction of the presto-native-execution module, Presto now has forked the execution engine into a separate process. This allows for the execution engine to be written in C++ and to be more efficient than the Java execution engine. However, this also means that the execution engine code is now entirely separate from the coordinator code, and that the types supported by the coordinator might not necessarily be supported by the execution engine.

This change adds a new native type manager which allows the types supported by the C++ engine to be known to the Java coordinator. 

For more context: [RFC-0003](https://github.com/prestodb/rfcs/blob/main/RFC-0003-native-spi.md)

## Test Plan
Unit and end-to-end tests. More comprehensive end-to-end tests will be written in the future.

## Contributor checklist

- [x] Please make sure your submission complies with our [contributing guide](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md), in particular [code style](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#code-style) and [commit standards](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#commit-standards).
- [x] PR description addresses the issue accurately and concisely.  If the change is non-trivial, a GitHub Issue is referenced.
- [x] Documented new properties (with its default value), SQL syntax, functions, or other functionality.
- [x] If release notes are required, they follow the [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines).
- [x] Adequate tests were added if applicable.
- [x] CI passed.

## Release Notes
Please follow [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines) and fill in the release notes below.

```
== RELEASE NOTES ==

Prestissimo (Native Execution) Changes
* Add a native type manager
```




Diff:
diff --git a/presto-common/src/main/java/com/facebook/presto/common/type/StandardTypes.java b/presto-common/src/main/java/com/facebook/presto/common/type/StandardTypes.java
index e00e2241a76d0..2291fd8dc80e4 100644
--- a/presto-common/src/main/java/com/facebook/presto/common/type/StandardTypes.java
+++ b/presto-common/src/main/java/com/facebook/presto/common/type/StandardTypes.java
@@ -58,6 +58,7 @@ public final class StandardTypes
     public static final String VARCHAR_ENUM = "VarcharEnum";
     public static final String DISTINCT_TYPE = "DistinctType";
     public static final String UUID = "uuid";
+    public static final String UNKNOWN = "unknown";
 
     private StandardTypes() {}
 
diff --git a/presto-common/src/main/java/com/facebook/presto/common/type/TypeManager.java b/presto-common/src/main/java/com/facebook/presto/common/type/TypeManager.java
index 4eafde00c4d34..277ef86ffb881 100644
--- a/presto-common/src/main/java/com/facebook/presto/common/type/TypeManager.java
+++ b/presto-common/src/main/java/com/facebook/presto/common/type/TypeManager.java
@@ -13,6 +13,7 @@
  */
 package com.facebook.presto.common.type;
 
+import java.util.Collection;
 import java.util.List;
 
 public interface TypeManager
@@ -28,4 +29,19 @@ public interface TypeManager
     Type getParameterizedType(String baseTypeName, List<TypeSignatureParameter> typeParameters);
 
     boolean canCoerce(Type actualType, Type expectedType);
+
+    default Type instantiateParametricType(TypeSignature typeSignature)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    List<Type> getTypes();
+
+    /**
+     * Gets all registered parametric types.
+     */
+    default Collection<ParametricType> getParametricTypes()
+    {
+        throw new UnsupportedOperationException();
+    }
 }
diff --git a/presto-common/src/test/java/com/facebook/presto/common/type/TestingTypeManager.java b/presto-common/src/test/java/com/facebook/presto/common/type/TestingTypeManager.java
index 5e5042e87be3b..f2e6f847a48a5 100644
--- a/presto-common/src/test/java/com/facebook/presto/common/type/TestingTypeManager.java
+++ b/presto-common/src/test/java/com/facebook/presto/common/type/TestingTypeManager.java
@@ -54,7 +54,8 @@ public boolean canCoerce(Type actualType, Type expectedType)
         throw new UnsupportedOperationException();
     }
 
-    private List<Type> getTypes()
+    @Override
+    public List<Type> getTypes()
     {
         return ImmutableList.of(BOOLEAN, INTEGER, BIGINT, DOUBLE, VARCHAR, VARBINARY, TIMESTAMP, DATE, ID, HYPER_LOG_LOG);
     }
diff --git a/presto-hudi/src/test/java/com/facebook/presto/hudi/TestingTypeManager.java b/presto-hudi/src/test/java/com/facebook/presto/hudi/TestingTypeManager.java
index 516f1805b40d8..8b9f9fb7a747a 100644
--- a/presto-hudi/src/test/java/com/facebook/presto/hudi/TestingTypeManager.java
+++ b/presto-hudi/src/test/java/com/facebook/presto/hudi/TestingTypeManager.java
@@ -58,7 +58,8 @@ public boolean canCoerce(Type actualType, Type expectedType)
         throw new UnsupportedOperationException();
     }
 
-    private List<Type> getTypes()
+    @Override
+    public List<Type> getTypes()
     {
         return ImmutableList.of(BOOLEAN, INTEGER, BIGINT, DOUBLE, VARCHAR, VARBINARY, TIMESTAMP, DATE, HYPER_LOG_LOG);
     }
diff --git a/presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergFileWriter.java b/presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergFileWriter.java
index 3deaf5a828efd..b87e793547de7 100644
--- a/presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergFileWriter.java
+++ b/presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergFileWriter.java
@@ -184,7 +184,8 @@ public boolean canCoerce(Type actualType, Type expectedType)
             throw new UnsupportedOperationException();
         }
 
-        private List<Type> getTypes()
+        @Override
+        public List<Type> getTypes()
         {
             return ImmutableList.of(BooleanType.BOOLEAN, INTEGER, BIGINT, DoubleType.DOUBLE, VARCHAR, VARBINARY, TIMESTAMP, DATE, HYPER_LOG_LOG);
         }
diff --git a/presto-main/src/main/java/com/facebook/presto/UnknownTypeException.java b/presto-main/src/main/java/com/facebook/presto/UnknownTypeException.java
new file mode 100644
index 0000000000000..984f953cbc0ee
--- /dev/null
+++ b/presto-main/src/main/java/com/facebook/presto/UnknownTypeException.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto;
+
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.spi.PrestoException;
+
+import static com.facebook.presto.spi.StandardErrorCode.UNKNOWN_TYPE;
+
+public class UnknownTypeException
+        extends PrestoException
+{
+    public UnknownTypeException(TypeSignature signature)
+    {
+        super(UNKNOWN_TYPE, "Unknown type " + signature);
+    }
+}
diff --git a/presto-main/src/main/java/com/facebook/presto/execution/AddColumnTask.java b/presto-main/src/main/java/com/facebook/presto/execution/AddColumnTask.java
index 0b233ef2ef8f6..261764cfd809e 100644
--- a/presto-main/src/main/java/com/facebook/presto/execution/AddColumnTask.java
+++ b/presto-main/src/main/java/com/facebook/presto/execution/AddColumnTask.java
@@ -14,6 +14,7 @@
 package com.facebook.presto.execution;
 
 import com.facebook.presto.Session;
+import com.facebook.presto.UnknownTypeException;
 import com.facebook.presto.common.QualifiedObjectName;
 import com.facebook.presto.common.type.Type;
 import com.facebook.presto.metadata.Metadata;
@@ -88,7 +89,7 @@ public ListenableFuture<?> execute(AddColumn statement, TransactionManager trans
         try {
             type = metadata.getType(parseTypeSignature(element.getType()));
         }
-        catch (IllegalArgumentException e) {
+        catch (UnknownTypeException e) {
             throw new SemanticException(TYPE_MISMATCH, element, "Unknown type '%s' for column '%s'", element.getType(), element.getName());
         }
         if (type.equals(UNKNOWN)) {
diff --git a/presto-main/src/main/java/com/facebook/presto/execution/CreateTableTask.java b/presto-main/src/main/java/com/facebook/presto/execution/CreateTableTask.java
index 131ca3ae62237..7bf67508063f5 100644
--- a/presto-main/src/main/java/com/facebook/presto/execution/CreateTableTask.java
+++ b/presto-main/src/main/java/com/facebook/presto/execution/CreateTableTask.java
@@ -14,6 +14,7 @@
 package com.facebook.presto.execution;
 
 import com.facebook.presto.Session;
+import com.facebook.presto.UnknownTypeException;
 import com.facebook.presto.common.QualifiedObjectName;
 import com.facebook.presto.common.type.Type;
 import com.facebook.presto.metadata.Metadata;
@@ -125,7 +126,7 @@ public ListenableFuture<?> internalExecute(CreateTable statement, Metadata metad
                 try {
                     type = metadata.getType(parseTypeSignature(column.getType()));
                 }
-                catch (IllegalArgumentException e) {
+                catch (UnknownTypeException e) {
                     throw new SemanticException(TYPE_MISMATCH, element, "Unknown type '%s' for column '%s'", column.getType(), column.getName());
                 }
                 if (type.equals(UNKNOWN)) {
diff --git a/presto-main/src/main/java/com/facebook/presto/metadata/BuiltInTypeAndFunctionNamespaceManager.java b/presto-main/src/main/java/com/facebook/presto/metadata/BuiltInTypeAndFunctionNamespaceManager.java
index c419822e91405..897f6657f4f3a 100644
--- a/presto-main/src/main/java/com/facebook/presto/metadata/BuiltInTypeAndFunctionNamespaceManager.java
+++ b/presto-main/src/main/java/com/facebook/presto/metadata/BuiltInTypeAndFunctionNamespaceManager.java
@@ -13,6 +13,7 @@
  */
 package com.facebook.presto.metadata;
 
+import com.facebook.presto.UnknownTypeException;
 import com.facebook.presto.common.CatalogSchemaName;
 import com.facebook.presto.common.Page;
 import com.facebook.presto.common.QualifiedObjectName;
@@ -531,7 +532,7 @@
 
 @ThreadSafe
 public class BuiltInTypeAndFunctionNamespaceManager
-        implements FunctionNamespaceManager<SqlFunction>
+        implements FunctionNamespaceManager<SqlFunction>, TypeManager
 {
     public static final CatalogSchemaName JAVA_BUILTIN_NAMESPACE = new CatalogSchemaName("presto", "default");
     public static final String ID = "builtin";
@@ -1261,14 +1262,15 @@ public ScalarFunctionImplementation getScalarFunctionImplementation(Signature si
         }
     }
 
-    public Optional<Type> getType(TypeSignature typeSignature)
+    @Override
+    public Type getType(TypeSignature typeSignature)
     {
         Type type = types.get(typeSignature);
         if (type != null) {
-            return Optional.of(type);
+            return type;
         }
         try {
-            return Optional.ofNullable(parametricTypeCache.getUnchecked(new ExactTypeSignature(typeSignature)));
+            return parametricTypeCache.getUnchecked(new ExactTypeSignature(typeSignature));
         }
         catch (UncheckedExecutionException e) {
             throwIfUnchecked(e.getCause());
@@ -1276,6 +1278,18 @@ public Optional<Type> getType(TypeSignature typeSignature)
         }
     }
 
+    @Override
+    public Type getParameterizedType(String baseTypeName, List<TypeSignatureParameter> typeParameters)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean canCoerce(Type actualType, Type expectedType)
+    {
+        throw new UnsupportedOperationException();
+    }
+
     public List<Type> getTypes()
     {
         return ImmutableList.copyOf(types.values());
@@ -1295,14 +1309,22 @@ public void addParametricType(ParametricType parametricType)
         parametricTypes.putIfAbsent(name, parametricType);
     }
 
+    @Override
     public Collection<ParametricType> getParametricTypes()
     {
         return parametricTypes.values();
     }
 
-    private Type instantiateParametricType(ExactTypeSignature exactSignature)
+    private Type instantiateParametricType(ExactTypeSignature exactTypeSignature)
+    {
+        return instantiateParametricType(exactTypeSignature.getTypeSignature(), functionAndTypeManager, parametricTypes);
+    }
+
+    public Type instantiateParametricType(
+            TypeSignature signature,
+            FunctionAndTypeManager functionAndTypeManager,
+            Map<String, ParametricType> parametricTypes)
     {
-        TypeSignature signature = exactSignature.getTypeSignature();
         List<TypeParameter> parameters = new ArrayList<>();
 
         for (TypeSignatureParameter parameter : signature.getParameters()) {
@@ -1312,7 +1334,7 @@ private Type instantiateParametricType(ExactTypeSignature exactSignature)
 
         ParametricType parametricType = parametricTypes.get(signature.getBase().toLowerCase(Locale.ENGLISH));
         if (parametricType == null) {
-            throw new IllegalArgumentException("Unknown type " + signature);
+            throw new UnknownTypeException(signature);
         }
 
         if (parametricType instanceof MapParametricType) {
diff --git a/presto-main/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java b/presto-main/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java
index 456bdef5dba80..4ea19e25698cd 100644
--- a/presto-main/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java
+++ b/presto-main/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java
@@ -52,6 +52,8 @@
 import com.facebook.presto.spi.function.SqlFunctionId;
 import com.facebook.presto.spi.function.SqlFunctionSupplier;
 import com.facebook.presto.spi.function.SqlInvokedFunction;
+import com.facebook.presto.spi.type.TypeManagerContext;
+import com.facebook.presto.spi.type.TypeManagerFactory;
 import com.facebook.presto.sql.analyzer.FeaturesConfig;
 import com.facebook.presto.sql.analyzer.FunctionAndTypeResolver;
 import com.facebook.presto.sql.analyzer.FunctionsConfig;
@@ -61,6 +63,7 @@
 import com.facebook.presto.transaction.TransactionManager;
 import com.facebook.presto.type.TypeCoercer;
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Supplier;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
@@ -82,6 +85,7 @@
 import java.util.Set;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.regex.Pattern;
 
 import static com.facebook.presto.SystemSessionProperties.isExperimentalFunctionsEnabled;
@@ -107,6 +111,7 @@
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.collect.ImmutableList.toImmutableList;
+import static com.google.common.collect.ImmutableMap.toImmutableMap;
 import static com.google.common.collect.ImmutableSet.toImmutableSet;
 import static java.lang.String.format;
 import static java.util.Collections.emptyList;
@@ -128,14 +133,18 @@ public class FunctionAndTypeManager
     private final BuiltInTypeAndFunctionNamespaceManager builtInTypeAndFunctionNamespaceManager;
     private final FunctionInvokerProvider functionInvokerProvider;
     private final Map<String, FunctionNamespaceManagerFactory> functionNamespaceManagerFactories = new ConcurrentHashMap<>();
+    private final Map<String, TypeManagerFactory> typeManagerFactories = new ConcurrentHashMap<>();
     private final HandleResolver handleResolver;
     private final Map<String, FunctionNamespaceManager<? extends SqlFunction>> functionNamespaceManagers = new ConcurrentHashMap<>();
+    private final Map<String, TypeManager> typeManagers = new ConcurrentHashMap<>();
     private final FunctionSignatureMatcher functionSignatureMatcher;
     private final TypeCoercer typeCoercer;
     private final LoadingCache<FunctionResolutionCacheKey, FunctionHandle> functionCache;
     private final CacheStatsMBean cacheStatsMBean;
     private final boolean nativeExecution;
     private final CatalogSchemaName defaultNamespace;
+    private final AtomicReference<TypeManager> servingTypeManager;
+    private final AtomicReference<Supplier<Map<String, ParametricType>>> servingTypeManagerParametricTypesSupplier;
 
     @Inject
     public FunctionAndTypeManager(
@@ -151,6 +160,7 @@ public FunctionAndTypeManager(
         this.builtInTypeAndFunctionNamespaceManager = new BuiltInTypeAndFunctionNamespaceManager(blockEncodingSerde, functionsConfig, types, this);
         this.functionNamespaceManagers.put(JAVA_BUILTIN_NAMESPACE.getCatalogName(), builtInTypeAndFunctionNamespaceManager);
         this.functionInvokerProvider = new FunctionInvokerProvider(this);
+        this.typeManagers.put(JAVA_BUILTIN_NAMESPACE.getCatalogName(), builtInTypeAndFunctionNamespaceManager);
         this.handleResolver = requireNonNull(handleResolver, "handleResolver is null");
         // TODO: Provide a more encapsulated way for TransactionManager to register FunctionNamespaceManager
         transactionManager.registerFunctionNamespaceManager(JAVA_BUILTIN_NAMESPACE.getCatalogName(), builtInTypeAndFunctionNamespaceManager);
@@ -164,6 +174,8 @@ public FunctionAndTypeManager(
         this.typeCoercer = new TypeCoercer(functionsConfig, this);
         this.nativeExecution = featuresConfig.isNativeExecutionEnabled();
         this.defaultNamespace = configureDefaultNamespace(functionsConfig.getDefaultNamespacePrefix());
+        this.servingTypeManager = new AtomicReference<>(builtInTypeAndFunctionNamespaceManager);
+        this.servingTypeManagerParametricTypesSupplier = new AtomicReference<>(this::getServingTypeManagerParametricTypes);
     }
 
     public static FunctionAndTypeManager createTestFunctionAndTypeManager()
@@ -234,6 +246,24 @@ public SqlFunctionSupplier getSpecializedFunctionKey(Signature signature)
                 return FunctionAndTypeManager.this.getSpecializedFunctionKey(signature);
             }
 
+            @Override
+            public Type instantiateParametricType(TypeSignature typeSignature)
+            {
+                return FunctionAndTypeManager.this.instantiateParametricType(typeSignature);
+            }
+
+            @Override
+            public List<Type> getTypes()
+            {
+                return FunctionAndTypeManager.this.getTypes();
+            }
+
+            @Override
+            public Collection<ParametricType> getParametricTypes()
+            {
+                return FunctionAndTypeManager.this.getParametricTypes();
+            }
+
             @Override
             public Collection<SqlFunction> listBuiltInFunctions()
             {
@@ -319,6 +349,15 @@ public FunctionMetadata getFunctionMetadata(FunctionHandle functionHandle)
         return functionNamespaceManager.get().getFunctionMetadata(functionHandle);
     }
 
+    @Override
+    public Type instantiateParametricType(TypeSignature typeSignature)
+    {
+        return builtInTypeAndFunctionNamespaceManager.instantiateParametricType(
+                typeSignature,
+                this,
+                servingTypeManagerParametricTypesSupplier.get().get());
+    }
+
     @Override
     public Type getType(TypeSignature signature)
     {
@@ -327,12 +366,12 @@ public Type getType(TypeSignature signature)
             if (signature.isDistinctType()) {
                 return getDistinctType(signature.getParameters().get(0).getDistinctTypeInfo());
             }
-            Optional<Type> type = builtInTypeAndFunctionNamespaceManager.getType(signature.getStandardTypeSignature());
-            if (type.isPresent()) {
+            Type type = servingTypeManager.get().getType(signature.getStandardTypeSignature());
+            if (type != null) {
                 if (signature.getTypeSignatureBase().hasTypeName()) {
-                    return new TypeWithName(signature.getTypeSignatureBase().getTypeName(), type.get());
+                    return new TypeWithName(signature.getTypeSignatureBase().getTypeName(), type);
                 }
-                return type.get();
+                return type;
             }
         }
 
@@ -364,6 +403,35 @@ public void addFunctionNamespaceFactory(FunctionNamespaceManagerFactory factory)
         handleResolver.addFunctionNamespace(factory.getName(), factory.getHandleResolver());
     }
 
+    public void loadTypeManager(String typeManagerName)
+    {
+        requireNonNull(typeManagerName, "typeManagerName is null");
+        TypeManagerFactory factory = typeManagerFactories.get(typeManagerName);
+        checkState(factory != null, "No factory for type manager %s", typeManagerName);
+        TypeManager typeManager = factory.create(new TypeManagerContext(this));
+
+        if (typeManagers.putIfAbsent(typeManagerName, typeManager) != null) {
+            throw new IllegalArgumentException(format("Type manager [%s] is already registered", typeManager));
+        }
+        servingTypeManager.compareAndSet(servingTypeManager.get(), typeManager);
+        // Reset the parametric types cache
+        servingTypeManagerParametricTypesSupplier.set(this::getServingTypeManagerParametricTypes);
+    }
+
+    public void loadTypeManagers()
+    {
+        for (String typeManagerName : typeManagerFactories.keySet()) {
+            loadTypeManager(typeManagerName);
+        }
+    }
+
+    public void addTypeManagerFactory(TypeManagerFactory factory)
+    {
+        if (typeManagerFactories.putIfAbsent(factory.getName(), factory) != null) {
+            throw new IllegalArgumentException(format("Type manager '%s' is already registered", factory.getName()));
+        }
+    }
+
     public void registerBuiltInFunctions(List<? extends SqlFunction> functions)
     {
         builtInTypeAndFunctionNamespaceManager.registerBuiltInFunctions(functions);
@@ -511,7 +579,7 @@ public List<Type> getTypes()
 
     public Collection<ParametricType> getParametricTypes()
     {
-        return ImmutableList.copyOf(builtInTypeAndFunctionNamespaceManager.getParametricTypes());
+        return builtInTypeAndFunctionNamespaceManager.getParametricTypes();
     }
 
     public Optional<Type> getCommonSuperType(Type firstType, Type secondType)
@@ -835,6 +903,12 @@ public CatalogSchemaName configureDefaultNamespace(String defaultNamespacePrefix
         return new CatalogSchemaName(catalogSchemaNameString[0], catalogSchemaNameString[1]);
     }
 
+    private Map<String, ParametricType> getServingTypeManagerParametricTypes()
+    {
+        return servingTypeManager.get().getParametricTypes().stream()
+                .collect(toImmutableMap(ParametricType::getName, parametricType -> parametricType));
+    }
+
     private static class FunctionResolutionCacheKey
     {
         private final QualifiedObjectName functionName;
diff --git a/presto-main/src/main/java/com/facebook/presto/metadata/SignatureBinder.java b/presto-main/src/main/java/com/facebook/presto/metadata/SignatureBinder.java
index 42fdb77c3bdb5..a71844c54b7d4 100644
--- a/presto-main/src/main/java/com/facebook/presto/metadata/SignatureBinder.java
+++ b/presto-main/src/main/java/com/facebook/presto/metadata/SignatureBinder.java
@@ -13,6 +13,7 @@
  */
 package com.facebook.presto.metadata;
 
+import com.facebook.presto.UnknownTypeException;
 import com.facebook.presto.common.type.FunctionType;
 import com.facebook.presto.common.type.NamedTypeSignature;
 import com.facebook.presto.common.type.ParameterKind;
@@ -532,7 +533,12 @@ private static List<TypeSignature> expandVarargFormalTypeSignature(List<TypeSign
     private boolean satisfiesCoercion(boolean allowCoercion, Type fromType, TypeSignature toTypeSignature)
     {
         if (allowCoercion) {
-            return functionAndTypeManager.canCoerce(fromType, functionAndTypeManager.getType(toTypeSignature));
+            try {
+                return functionAndTypeManager.canCoerce(fromType, functionAndTypeManager.getType(toTypeSignature));
+            }
+            catch (UnknownTypeException e) {
+                return false;
+            }
         }
         else if (fromType.getTypeSignature().equals(toTypeSignature)) {
             return true;
@@ -686,9 +692,15 @@ public SolverReturnStatus update(BoundVariables.Builder bindings)
                     originalTypeTypeParametersBuilder.add(typeSignatureParameter);
                 }
             }
-            Type originalType = functionAndTypeManager.getType(new TypeSignature(formalTypeSignature.getBase(), originalTypeTypeParametersBuilder.build()));
-            Optional<Type> commonSuperType = functionAndTypeManager.getCommonSuperType(originalType, actualType);
-            if (!commonSuperType.isPresent()) {
+            Optional<Type> commonSuperType;
+            try {
+                Type originalType = functionAndTypeManager.getType(new TypeSignature(formalTypeSignature.getBase(), originalTypeTypeParametersBuilder.build()));
+                commonSuperType = functionAndTypeManager.getCommonSuperType(originalType, actualType);
+                if (!commonSuperType.isPresent()) {
+                    return SolverReturnStatus.UNSOLVABLE;
+                }
+            }
+            catch (UnknownTypeException e) {
                 return SolverReturnStatus.UNSOLVABLE;
             }
             TypeSignature commonSuperTypeSignature = commonSuperType.get().getTypeSignature();
diff --git a/presto-main/src/main/java/com/facebook/presto/server/PluginManager.java b/presto-main/src/main/java/com/facebook/presto/server/PluginManager.java
index 274f90bed1204..af0f0f3bee089 100644
--- a/presto-main/src/main/java/com/facebook/presto/server/PluginManager.java
+++ b/presto-main/src/main/java/com/facebook/presto/server/PluginManager.java
@@ -53,6 +53,7 @@
 import com.facebook.presto.spi.tracing.TracerProvider;
 import com.facebook.presto.spi.ttl.ClusterTtlProviderFactory;
 import com.facebook.presto.spi.ttl.NodeTtlFetcherFactory;
+import com.facebook.presto.spi.type.TypeManagerFactory;
 import com.facebook.presto.sql.analyzer.AnalyzerProviderManager;
 import com.facebook.presto.sql.analyzer.QueryPreparerProviderManager;
 import com.facebook.presto.sql.expressions.ExpressionOptimizerManager;
@@ -402,6 +403,11 @@ public void installCoordinatorPlugin(CoordinatorPlugin plugin)
             log.info("Registering expression optimizer factory %s", expressionOptimizerFactory.getName());
             expressionOptimizerManager.addExpressionOptimizerFactory(expressionOptimizerFactory);
         }
+
+        for (TypeManagerFactory typeManagerFactory : plugin.getTypeManagerFactories()) {
+            log.info("Registering type manager factory %s", typeManagerFactory.getName());
+            metadata.getFunctionAndTypeManager().addTypeManagerFactory(typeManagerFactory);
+        }
     }
 
     private URLClassLoader buildClassLoader(String plugin)
diff --git a/presto-main/src/main/java/com/facebook/presto/server/PrestoServer.java b/presto-main/src/main/java/com/facebook/presto/server/PrestoServer.java
index 3b2e9fd11e322..fac8bc79e06b5 100644
--- a/presto-main/src/main/java/com/facebook/presto/server/PrestoServer.java
+++ b/presto-main/src/main/java/com/facebook/presto/server/PrestoServer.java
@@ -43,6 +43,7 @@
 import com.facebook.presto.metadata.Catalog;
 import com.facebook.presto.metadata.CatalogManager;
 import com.facebook.presto.metadata.DiscoveryNodeManager;
+import com.facebook.presto.metadata.FunctionAndTypeManager;
 import com.facebook.presto.metadata.InternalNodeManager;
 import com.facebook.presto.metadata.SessionPropertyManager;
 import com.facebook.presto.metadata.StaticCatalogStore;
@@ -190,6 +191,7 @@ public void run()
             injector.getInstance(NodeStatusNotificationManager.class).loadNodeStatusNotificationProvider();
             injector.getInstance(GracefulShutdownHandler.class).loadNodeStatusNotification();
             injector.getInstance(SessionPropertyManager.class).loadSessionPropertyProviders();
+            injector.getInstance(FunctionAndTypeManager.class).loadTypeManagers();
             PlanCheckerProviderManager planCheckerProviderManager = injector.getInstance(PlanCheckerProviderManager.class);
             InternalNodeManager nodeManager = injector.getInstance(DiscoveryNodeManager.class);
             NodeInfo nodeInfo = injector.getInstance(NodeInfo.class);
diff --git a/presto-main/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java b/presto-main/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java
index 3dcc4bce7597a..002b667eb68d9 100644
--- a/presto-main/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java
+++ b/presto-main/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java
@@ -14,6 +14,7 @@
 package com.facebook.presto.sql.analyzer;
 
 import com.facebook.presto.Session;
+import com.facebook.presto.UnknownTypeException;
 import com.facebook.presto.common.ErrorCode;
 import com.facebook.presto.common.QualifiedObjectName;
 import com.facebook.presto.common.Subfield;
@@ -889,7 +890,7 @@ protected Type visitGenericLiteral(GenericLiteral node, StackableAstVisitorConte
             try {
                 type = functionAndTypeResolver.getType(parseTypeSignature(node.getType()));
             }
-            catch (IllegalArgumentException e) {
+            catch (UnknownTypeException e) {
                 throw new SemanticException(TYPE_MISMATCH, node, "Unknown type: " + node.getType());
             }
 
@@ -912,7 +913,7 @@ protected Type visitEnumLiteral(EnumLiteral node, StackableAstVisitorContext<Con
             try {
                 type = functionAndTypeResolver.getType(parseTypeSignature(node.getType()));
             }
-            catch (IllegalArgumentException e) {
+            catch (UnknownTypeException e) {
                 throw new SemanticException(TYPE_MISMATCH, node, "Unknown type: " + node.getType());
             }
 
@@ -1339,7 +1340,7 @@ public Type visitCast(Cast node, StackableAstVisitorContext<Context> context)
             try {
                 type = functionAndTypeResolver.getType(parseTypeSignature(node.getType()));
             }
-            catch (IllegalArgumentException e) {
+            catch (IllegalArgumentException | UnknownTypeException e) {
                 throw new SemanticException(TYPE_MISMATCH, node, "Unknown type: " + node.getType());
             }
 
diff --git a/presto-main/src/main/java/com/facebook/presto/sql/analyzer/ExpressionTreeUtils.java b/presto-main/src/main/java/com/facebook/presto/sql/analyzer/ExpressionTreeUtils.java
index c1c5b6765e34c..ffe7a7a7c8d5e 100644
--- a/presto-main/src/main/java/com/facebook/presto/sql/analyzer/ExpressionTreeUtils.java
+++ b/presto-main/src/main/java/com/facebook/presto/sql/analyzer/ExpressionTreeUtils.java
@@ -13,6 +13,7 @@
  */
 package com.facebook.presto.sql.analyzer;
 
+import com.facebook.presto.UnknownTypeException;
 import com.facebook.presto.common.type.EnumType;
 import com.facebook.presto.common.type.Type;
 import com.facebook.presto.common.type.TypeWithName;
@@ -152,7 +153,7 @@ public static Optional<TypeWithName> tryResolveEnumLiteralType(QualifiedName qua
                 return Optional.of((TypeWithName) baseType);
             }
         }
-        catch (IllegalArgumentException e) {
+        catch (UnknownTypeException e) {
             return Optional.empty();
         }
         return Optional.empty();
diff --git a/presto-main/src/main/java/com/facebook/presto/testing/QueryRunner.java b/presto-main/src/main/java/com/facebook/presto/testing/QueryRunner.java
index e62447a403e94..cb302fd134bc6 100644
--- a/presto-main/src/main/java/com/facebook/presto/testing/QueryRunner.java
+++ b/presto-main/src/main/java/com/facebook/presto/testing/QueryRunner.java
@@ -107,6 +107,11 @@ default void loadSessionPropertyProvider(String sessionPropertyProviderName)
 
     Lock getExclusiveLock();
 
+    default void loadTypeManager(String typeManagerName)
+    {
+        throw new UnsupportedOperationException();
+    }
+
     class MaterializedResultWithPlan
     {
         private final MaterializedResult materializedResult;
diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestBuiltInTypeRegistry.java b/presto-main/src/test/java/com/facebook/presto/type/TestBuiltInTypeRegistry.java
index a4f14a3b74095..b5a4b8f49f3d5 100644
--- a/presto-main/src/test/java/com/facebook/presto/type/TestBuiltInTypeRegistry.java
+++ b/presto-main/src/test/java/com/facebook/presto/type/TestBuiltInTypeRegistry.java
@@ -13,6 +13,7 @@
  */
 package com.facebook.presto.type;
 
+import com.facebook.presto.UnknownTypeException;
 import com.facebook.presto.common.type.Type;
 import com.facebook.presto.common.type.TypeSignature;
 import com.facebook.presto.metadata.FunctionAndTypeManager;
@@ -73,13 +74,13 @@ public void testNonexistentType()
     {
         try {
             functionAndTypeManager.getType(parseTypeSignature("not a real type"));
-            fail("Expect to throw IllegalArgumentException");
+            fail("Expect to throw UnknownTypeException");
         }
-        catch (IllegalArgumentException e) {
+        catch (UnknownTypeException e) {
             assertTrue(e.getMessage().matches("Unknown type.*"));
         }
         catch (Throwable t) {
-            fail("Expect to throw IllegalArgumentException, got " + t.getClass());
+            fail("Expect to throw UnknownTypeException, got " + t.getClass());
         }
     }
 
diff --git a/presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/NativeSidecarPlugin.java b/presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/NativeSidecarPlugin.java
index 7da7ba4d4fbb9..7ad15da8201ba 100644
--- a/presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/NativeSidecarPlugin.java
+++ b/presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/NativeSidecarPlugin.java
@@ -16,10 +16,12 @@
 import com.facebook.presto.sidecar.functionNamespace.NativeFunctionNamespaceManagerFactory;
 import com.facebook.presto.sidecar.nativechecker.NativePlanCheckerProviderFactory;
 import com.facebook.presto.sidecar.sessionpropertyproviders.NativeSystemSessionPropertyProviderFactory;
+import com.facebook.presto.sidecar.typemanager.NativeTypeManagerFactory;
 import com.facebook.presto.spi.CoordinatorPlugin;
 import com.facebook.presto.spi.function.FunctionNamespaceManagerFactory;
 import com.facebook.presto.spi.plan.PlanCheckerProviderFactory;
 import com.facebook.presto.spi.session.WorkerSessionPropertyProviderFactory;
+import com.facebook.presto.spi.type.TypeManagerFactory;
 import com.google.common.collect.ImmutableList;
 
 public class NativeSidecarPlugin
@@ -31,6 +33,12 @@ public Iterable<WorkerSessionPropertyProviderFactory> getWorkerSessionPropertyPr
         return ImmutableList.of(new NativeSystemSessionPropertyProviderFactory());
     }
 
+    @Override
+    public Iterable<TypeManagerFactory> getTypeManagerFactories()
+    {
+        return ImmutableList.of(new NativeTypeManagerFactory());
+    }
+
     @Override
     public Iterable<PlanCheckerProviderFactory> getPlanCheckerProviderFactories()
     {
diff --git a/presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java b/presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
new file mode 100644
index 0000000000000..51c46370c46f3
--- /dev/null
+++ b/presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
@@ -0,0 +1,298 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.FunctionType;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR,
+                    UNKNOWN);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FunctionType.NAME);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
+    private final ConcurrentMap<TypeSignature, Type> types = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, ParametricType> parametricTypes = new ConcurrentHashMap<>();
+
+    @Inject
+    public NativeTypeManager(TypeManager typeManager)
+    {
+        this.typeManager = requireNonNull(typeManager, "typeManager is null");
+        parametricTypeCache = CacheBuilder.newBuilder()
+                .maximumSize(1000)
+                .build(CacheLoader.from(this::instantiateParametricType));
+        addAllTypes(
+                filterSupportedTypes(NATIVE_ENGINE_SUPPORTED_TYPES, typeManager.getTypes(), Type::getDisplayName),
+                filterSupportedTypes(
+                        NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES,
+                        new ArrayList<>(typeManager.getParametricTypes()),
+                        ParametricType::getName));
+    }
+
+    @Override
+    public Type getType(TypeSignature typeSignature)
+    {
+        // Todo: Fix this hack, native execution does not support parameterized varchar type signatures.
+        if (typeSignature.getBase().equals(VARCHAR)) {
+            typeSignature = createUnboundedVarcharType().getTypeSignature();
+        }
+        Type type = types.get(typeSignature);
+        if (type != null) {
+            return type;
+        }
+        try {
+            return parametricTypeCache.getUnchecked(new ExactTypeSignature(typeSignature));
+        }
+        catch (UncheckedExecutionException e) {
+            throwIfUnchecked(e.getCause());
+            throw new RuntimeException(e.getCause());
+        }
+    }
+
+    @Override
+    public Collection<ParametricType> getParametricTypes()
+    {
+        return parametricTypes.values();
+    }
+
+    @Override
+    public List<Type> getTypes()
+    {
+        return ImmutableList.copyOf(types.values());
+    }
+
+    @Override
+    public Type getParameterizedType(String baseTypeName, List<TypeSignatureParameter> typeParameters)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean canCoerce(Type actualType, Type expectedType)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    private void addAllTypes(List<Type> typesList, List<ParametricType> parametricTypesList)
+    {
+        typesList.forEach(this::addType);
+        // todo: Fix this hack
+        // Native engine does not support parameterized varchar, and varchar isn't in the lists of types returned from the engine
+        addType(VarcharType.VARCHAR);
+
+        parametricTypesList.forEach(this::addParametricType);
+    }
+
+    private Type instantiateParametricType(ExactTypeSignature exactTypeSignature)
+    {
+        return typeManager.instantiateParametricType(exactTypeSignature.getTypeSignature());
+    }
+
+    private void addType(Type type)
+    {
+        requireNonNull(type, "type is null");
+        Type existingType = types.putIfAbsent(type.getTypeSignature(), type);
+        checkState(existingType == null || existingType.equals(type), "Type %s is already registered", type);
+    }
+
+    private void addParametricType(ParametricType parametricType)
+    {
+        String name = parametricType.getName().toLowerCase(Locale.ENGLISH);
+        checkArgument(!parametricTypes.containsKey(name), "Parametric type already registered: %s", name);
+        parametricTypes.putIfAbsent(name, parametricType);
+    }
+
+    private static <T> List<T> filterSupportedTypes(
+            Set<String> actualTypes,
+            List<T> types,
+            Function<T, String> typeSignatureExtractor)
+    {
+        return types.stream()
+                .filter(type -> actualTypes.contains(typeSignatureExtractor.apply(type)))
+                .collect(toImmutableList());
+    }
+
+    /**
+     * TypeSignature has overridden equals(). Here, we compare exact signature of any underlying distinct
+     * types. Some distinct types may have extra information on their lazily loaded parents, and same parent
+     * information is compared in equals(). This is needed to cache types in parametricTypesCache.
+     */
+    private static class ExactTypeSignature
+    {
+        private final TypeSignature typeSignature;
+
+        public ExactTypeSignature(TypeSignature typeSignature)
+        {
+            this.typeSignature = typeSignature;
+        }
+
+        public TypeSignature getTypeSignature()
+        {
+            return typeSignature;
+        }
+
+        @Override
+        public int hashCode()
+        {
+            return Objects.hash(typeSignature);
+        }
+
+        @Override
+        public boolean equals(Object o)
+        {
+            if (this == o) {
+                return true;
+            }
+            if (o == null || getClass() != o.getClass()) {
+                return false;
+            }
+
+            ExactTypeSignature other = (ExactTypeSignature) o;
+            return equals(typeSignature, other.typeSignature);
+        }
+
+        private static boolean equals(TypeSignature left, TypeSignature right)
+        {
+            if (!left.equals(right)) {
+                return false;
+            }
+
+            if (left.isDistinctType() && right.isDistinctType()) {
+                return equals(left.getDistinctTypeInfo(), right.getDistinctTypeInfo());
+            }
+            int index = 0;
+            for (TypeSignatureParameter leftParameter : left.getParameters()) {
+                TypeSignatureParameter rightParameter = right.getParameters().get(index++);
+                if (!leftParameter.getKind().equals(rightParameter.getKind())) {
+                    return false;
+                }
+
+                switch (leftParameter.getKind()) {
+                    case TYPE:
+                        if (!equals(leftParameter.getTypeSignature(), rightParameter.getTypeSignature())) {
+                            return false;
+                        }
+                        break;
+                    case NAMED_TYPE:
+                        if (!equals(leftParameter.getNamedTypeSignature().getTypeSignature(), rightParameter.getNamedTypeSignature().getTypeSignature())) {
+                            return false;
+                        }
+                        break;
+                    case DISTINCT_TYPE:
+                        if (!equals(leftParameter.getDistinctTypeInfo(), rightParameter.getDistinctTypeInfo())) {
+                            return false;
+                        }
+                        break;
+                }
+            }
+            return true;
+        }
+
+        private static boolean equals(DistinctTypeInfo left, DistinctTypeInfo right)
+        {
+            return Objects.equals(left.getName(), right.getName()) &&
+                    Objects.equals(left.getBaseType(), right.getBaseType()) &&
+                    Objects.equals(left.isOrderable(), right.isOrderable()) &&
+                    Objects.equals(left.getTopMostAncestor(), right.getTopMostAncestor()) &&
+                    Objects.equals(left.getOtherAncestors(), right.getOtherAncestors());
+        }
+    }
+}
diff --git a/presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManagerFactory.java b/presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManagerFactory.java
new file mode 100644
index 0000000000000..7a76d8500ef5c
--- /dev/null
+++ b/presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManagerFactory.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.bootstrap.Bootstrap;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.spi.type.TypeManagerContext;
+import com.facebook.presto.spi.type.TypeManagerFactory;
+import com.google.inject.Injector;
+
+public class NativeTypeManagerFactory
+        implements TypeManagerFactory
+{
+    public static final String NAME = "native";
+
+    @Override
+    public String getName()
+    {
+        return NAME;
+    }
+
+    @Override
+    public TypeManager create(TypeManagerContext context)
+    {
+        Bootstrap app = new Bootstrap(
+                new NativeTypeManagerModule(context.getTypeManager()));
+
+        Injector injector = app
+                .doNotInitializeLogging()
+                .noStrictConfig()
+                .initialize();
+        return injector.getInstance(NativeTypeManager.class);
+    }
+}
diff --git a/presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManagerModule.java b/presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManagerModule.java
new file mode 100644
index 0000000000000..7af6127c681d9
--- /dev/null
+++ b/presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManagerModule.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.presto.common.type.TypeManager;
+import com.google.inject.Binder;
+import com.google.inject.Module;
+import com.google.inject.Scopes;
+
+import static java.util.Objects.requireNonNull;
+
+public class NativeTypeManagerModule
+        implements Module
+{
+    private final TypeManager typeManager;
+
+    public NativeTypeManagerModule(TypeManager typeManager)
+    {
+        this.typeManager = requireNonNull(typeManager, "typeManager is null");
+    }
+
+    @Override
+    public void configure(Binder binder)
+    {
+        binder.bind(TypeManager.class).toInstance(typeManager);
+        binder.bind(NativeTypeManager.class).in(Scopes.SINGLETON);
+    }
+}
diff --git a/presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/NativeSidecarPluginQueryRunnerUtils.java b/presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/NativeSidecarPluginQueryRunnerUtils.java
index 994d824195600..28a82820d394a 100644
--- a/presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/NativeSidecarPluginQueryRunnerUtils.java
+++ b/presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/NativeSidecarPluginQueryRunnerUtils.java
@@ -15,6 +15,7 @@
 
 import com.facebook.presto.sidecar.functionNamespace.NativeFunctionNamespaceManagerFactory;
 import com.facebook.presto.sidecar.sessionpropertyproviders.NativeSystemSessionPropertyProviderFactory;
+import com.facebook.presto.sidecar.typemanager.NativeTypeManagerFactory;
 import com.facebook.presto.testing.QueryRunner;
 import com.google.common.collect.ImmutableMap;
 
@@ -32,5 +33,6 @@ public static void setupNativeSidecarPlugin(QueryRunner queryRunner)
                 ImmutableMap.of(
                         "supported-function-languages", "CPP",
                         "function-implementation-type", "CPP"));
+        queryRunner.loadTypeManager(NativeTypeManagerFactory.NAME);
     }
 }
diff --git a/presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/TestNativeSystemSessionPropertyProviderConfig.java b/presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/sessionpropertyproviders/TestNativeSystemSessionPropertyProviderConfig.java
similarity index 92%
rename from presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/TestNativeSystemSessionPropertyProviderConfig.java
rename to presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/sessionpropertyproviders/TestNativeSystemSessionPropertyProviderConfig.java
index 6784928044478..7cb12c8480699 100644
--- a/presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/TestNativeSystemSessionPropertyProviderConfig.java
+++ b/presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/sessionpropertyproviders/TestNativeSystemSessionPropertyProviderConfig.java
@@ -11,9 +11,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.facebook.presto.sidecar;
+package com.facebook.presto.sidecar.sessionpropertyproviders;
 
-import com.facebook.presto.sidecar.sessionpropertyproviders.NativeSystemSessionPropertyProviderConfig;
 import com.google.common.collect.ImmutableMap;
 import io.airlift.units.Duration;
 import org.testng.annotations.Test;
diff --git a/presto-spi/src/main/java/com/facebook/presto/spi/CoordinatorPlugin.java b/presto-spi/src/main/java/com/facebook/presto/spi/CoordinatorPlugin.java
index ca8ea46d58aa6..6b82a6ae2b64e 100644
--- a/presto-spi/src/main/java/com/facebook/presto/spi/CoordinatorPlugin.java
+++ b/presto-spi/src/main/java/com/facebook/presto/spi/CoordinatorPlugin.java
@@ -17,6 +17,7 @@
 import com.facebook.presto.spi.plan.PlanCheckerProviderFactory;
 import com.facebook.presto.spi.session.WorkerSessionPropertyProviderFactory;
 import com.facebook.presto.spi.sql.planner.ExpressionOptimizerFactory;
+import com.facebook.presto.spi.type.TypeManagerFactory;
 
 import static java.util.Collections.emptyList;
 
@@ -46,4 +47,9 @@ default Iterable<ExpressionOptimizerFactory> getExpressionOptimizerFactories()
     {
         return emptyList();
     }
+
+    default Iterable<TypeManagerFactory> getTypeManagerFactories()
+    {
+        return emptyList();
+    }
 }
diff --git a/presto-spi/src/main/java/com/facebook/presto/spi/StandardErrorCode.java b/presto-spi/src/main/java/com/facebook/presto/spi/StandardErrorCode.java
index 90856f013d874..07be6b8d2b186 100644
--- a/presto-spi/src/main/java/com/facebook/presto/spi/StandardErrorCode.java
+++ b/presto-spi/src/main/java/com/facebook/presto/spi/StandardErrorCode.java
@@ -74,6 +74,7 @@ public enum StandardErrorCode
     VIEW_NOT_FOUND(0x0000_0030, USER_ERROR),
     INVALID_LIMIT_CLAUSE(0x0000_0031, USER_ERROR),
     COLUMN_NOT_FOUND(0x0000_0032, USER_ERROR),
+    UNKNOWN_TYPE(0x0000_0033, USER_ERROR),
 
     GENERIC_INTERNAL_ERROR(0x0001_0000, INTERNAL_ERROR),
     TOO_MANY_REQUESTS_FAILED(0x0001_0001, INTERNAL_ERROR, true),
diff --git a/presto-spi/src/main/java/com/facebook/presto/spi/type/TypeManagerContext.java b/presto-spi/src/main/java/com/facebook/presto/spi/type/TypeManagerContext.java
new file mode 100644
index 0000000000000..075c3ba2414d6
--- /dev/null
+++ b/presto-spi/src/main/java/com/facebook/presto/spi/type/TypeManagerContext.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.spi.type;
+
+import com.facebook.presto.common.type.TypeManager;
+
+import static java.util.Objects.requireNonNull;
+
+public class TypeManagerContext
+{
+    private final TypeManager typeManager;
+
+    public TypeManagerContext(TypeManager typeManager)
+    {
+        this.typeManager = requireNonNull(typeManager, "typeManager is null");
+    }
+
+    public TypeManager getTypeManager()
+    {
+        return typeManager;
+    }
+}
diff --git a/presto-spi/src/main/java/com/facebook/presto/spi/type/TypeManagerFactory.java b/presto-spi/src/main/java/com/facebook/presto/spi/type/TypeManagerFactory.java
new file mode 100644
index 0000000000000..7f82a527ea864
--- /dev/null
+++ b/presto-spi/src/main/java/com/facebook/presto/spi/type/TypeManagerFactory.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.spi.type;
+
+import com.facebook.presto.common.type.TypeManager;
+
+public interface TypeManagerFactory
+{
+    String getName();
+
+    TypeManager create(TypeManagerContext context);
+}
diff --git a/presto-tests/src/main/java/com/facebook/presto/tests/DistributedQueryRunner.java b/presto-tests/src/main/java/com/facebook/presto/tests/DistributedQueryRunner.java
index b3f25630cb078..e8006ee02268c 100644
--- a/presto-tests/src/main/java/com/facebook/presto/tests/DistributedQueryRunner.java
+++ b/presto-tests/src/main/java/com/facebook/presto/tests/DistributedQueryRunner.java
@@ -994,6 +994,14 @@ public void loadSessionPropertyProvider(String sessionPropertyProviderName)
         }
     }
 
+    @Override
+    public void loadTypeManager(String typeManagerName)
+    {
+        for (TestingPrestoServer server : servers) {
+            server.getMetadata().getFunctionAndTypeManager().loadTypeManager(typeManagerName);
+        }
+    }
+
     private static void closeUnchecked(AutoCloseable closeable)
     {
         try {


Reviews:
user: login: tdcmeehan
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2024-12-10T17:00:12Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2024-12-10T18:36:33Z
user: login: tdcmeehan
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2024-12-10T18:55:13Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2024-12-10T19:58:53Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2024-12-10T20:34:42Z
user: login: auden-woolfson
body: LGTM
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2024-12-10T20:41:58Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2024-12-10T22:54:14Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2024-12-10T22:54:33Z
user: login: tdcmeehan
state: DISMISSED
author_association: CONTRIBUTOR
submitted_at: 2025-02-06T20:01:32Z
user: login: auden-woolfson
body: LGTM, just a few best practices/nits.
state: CHANGES_REQUESTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-07T00:08:35Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-07T22:10:11Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-07T22:13:51Z
user: login: auden-woolfson
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-08T00:16:23Z
user: login: auden-woolfson
state: DISMISSED
author_association: CONTRIBUTOR
submitted_at: 2025-02-08T00:18:54Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-08T00:34:00Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-08T00:34:19Z
user: login: ZacBlanco
body: Overall, looks good. I am concerned about the exception handling aspect though.

Also, please also update the release note section header to `Prestissimo (Native Execution) Changes`


state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-12T17:44:01Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-12T21:04:24Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-12T21:17:49Z
user: login: ZacBlanco
body: Two minors things, otherwise LGTM
state: CHANGES_REQUESTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-17T20:28:33Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-17T20:36:31Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-17T20:36:40Z
user: login: ZacBlanco
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-17T21:12:50Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-17T21:37:25Z
user: login: ZacBlanco
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-17T21:42:55Z
user: login: ZacBlanco
state: DISMISSED
author_association: CONTRIBUTOR
submitted_at: 2025-02-17T21:43:08Z
user: login: majetideepak
body: I have one question. 
I cannot sign off on this since I do not have enough context on the changes made to the Java API.
We will need an approval from a Java committer.
CC: @jaystarshot 
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-02-19T17:06:47Z
user: login: rschlussel
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-19T17:47:45Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-19T17:52:26Z
user: login: majetideepak
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-02-19T18:36:12Z
user: login: aditi-pandit
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-20T00:24:37Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-27T22:13:46Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-27T22:14:37Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-27T22:17:04Z
user: login: ZacBlanco
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-28T05:45:20Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-28T17:53:41Z
user: login: ZacBlanco
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-28T17:56:46Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-28T20:43:12Z
user: login: rschlussel
state: DISMISSED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T14:52:02Z
user: login: aditi-pandit
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-19T17:13:41Z
user: login: ZacBlanco
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-19T17:44:04Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-19T20:02:32Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-19T23:41:41Z
user: login: pdabre12
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-19T23:43:32Z
user: login: ZacBlanco
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-26T15:30:55Z
user: login: rschlussel
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-26T19:31:48Z
user: login: aditi-pandit
body: Thanks @pdabre12 
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-26T19:43:07Z

Review comments:
diff_hunk: @@ -0,0 +1,195 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.ExactTypeSignature;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.VarcharType;
+import com.facebook.presto.spi.type.TypesProvider;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.TypeSignature.parseTypeSignature;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.HOURS;
+
+public class NativeTypeManager
+        implements TypesProvider
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FUNCTION);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: tdcmeehan
body: Just copy the `ExactTypeSignature` here as well.  It's a bit too specific to be useful as a general API in common.
created_at: 2024-12-10T16:55:24Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,28 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.spi.type;
+
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeSignature;
+
+import java.util.Map;
+import java.util.Optional;
+
+public interface TypesProvider
path: presto-spi/src/main/java/com/facebook/presto/spi/type/TypesProvider.java
user: login: tdcmeehan
body: I'm wondering if we can avoid this new interface and instead use the existing `TypeManager` interface.
created_at: 2024-12-10T17:00:09Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,195 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.ExactTypeSignature;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.VarcharType;
+import com.facebook.presto.spi.type.TypesProvider;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.TypeSignature.parseTypeSignature;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.HOURS;
+
+public class NativeTypeManager
+        implements TypesProvider
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FUNCTION);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: pdabre12
body: The problem is `ExactTypeSignature` is used in `FunctionAndTypeManager` too.
created_at: 2024-12-10T18:36:33Z
author_association: CONTRIBUTOR
diff_hunk: @@ -301,6 +325,17 @@ public FunctionMetadata getFunctionMetadata(FunctionHandle functionHandle)
         return functionNamespaceManager.get().getFunctionMetadata(functionHandle);
     }
 
+    @Override
+    public Type instantiateParametricType(ExactTypeSignature exactSignature)
path: presto-main/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java
user: login: tdcmeehan
body: Can this take in a `TypeSignature`, and we manually create an `ExactTypeSignature` inside this method, so we can avoiding moving `ExactTypeSignature` into the SPI?
created_at: 2024-12-10T18:55:13Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,28 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.spi.type;
+
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeSignature;
+
+import java.util.Map;
+import java.util.Optional;
+
+public interface TypesProvider
path: presto-spi/src/main/java/com/facebook/presto/spi/type/TypesProvider.java
user: login: pdabre12
body: Done.
created_at: 2024-12-10T19:58:53Z
author_association: CONTRIBUTOR
diff_hunk: @@ -301,6 +325,17 @@ public FunctionMetadata getFunctionMetadata(FunctionHandle functionHandle)
         return functionNamespaceManager.get().getFunctionMetadata(functionHandle);
     }
 
+    @Override
+    public Type instantiateParametricType(ExactTypeSignature exactSignature)
path: presto-main/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java
user: login: pdabre12
body: That would mean not using the `ExactTypeSignature` here: https://github.com/prestodb/presto/blob/fa3a49b8d6df5625865506df8d176cb457de2796/presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java#L142,  which makes the usage of `ExactTypeSignature` redundant.
created_at: 2024-12-10T20:34:42Z
author_association: CONTRIBUTOR
diff_hunk: @@ -301,6 +325,17 @@ public FunctionMetadata getFunctionMetadata(FunctionHandle functionHandle)
         return functionNamespaceManager.get().getFunctionMetadata(functionHandle);
     }
 
+    @Override
+    public Type instantiateParametricType(ExactTypeSignature exactSignature)
path: presto-main/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java
user: login: pdabre12
body: Done.
created_at: 2024-12-10T22:54:14Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,195 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.ExactTypeSignature;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.VarcharType;
+import com.facebook.presto.spi.type.TypesProvider;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.TypeSignature.parseTypeSignature;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.HOURS;
+
+public class NativeTypeManager
+        implements TypesProvider
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FUNCTION);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: pdabre12
body: Done.
created_at: 2024-12-10T22:54:33Z
author_association: CONTRIBUTOR
diff_hunk: @@ -28,4 +29,13 @@ public interface TypeManager
     Type getParameterizedType(String baseTypeName, List<TypeSignatureParameter> typeParameters);
 
     boolean canCoerce(Type actualType, Type expectedType);
+
+    default Type instantiateParametricType(TypeSignature typeSignature)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    List<Type> getTypes();
+
+    Map<String, ParametricType> getParametricTypes();
path: presto-common/src/main/java/com/facebook/presto/common/type/TypeManager.java
user: login: tdcmeehan
body: There actually used to be this signature in this interface:

```
    /**
     * Gets all registered parametric types.
     */
    Collection<ParametricType> getParametricTypes();
```

I think you have the key of this map as the base type signature.  Can that be inferred from the values, i.e. `ParametricType#getTypeSignatureBase()`?
created_at: 2025-02-06T19:34:14Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,303 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR,
+                    UNKNOWN);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FUNCTION);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
+    private final ConcurrentMap<TypeSignature, Type> types = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, ParametricType> parametricTypes = new ConcurrentHashMap<>();
+
+    @Inject
+    public NativeTypeManager(TypeManager typeManager, NativeTypeManagerConfig config)
+    {
+        this.typeManager = requireNonNull(typeManager, "typeManager is null");
+        parametricTypeCache = CacheBuilder.newBuilder()
+                .maximumSize(1000)
+                .expireAfterWrite(config.getTypesCacheExpiration().toMillis(), MILLISECONDS)
+                .build(CacheLoader.from(this::instantiateParametricType));
+        addAllTypes(
+                filterSupportedTypes(NATIVE_ENGINE_SUPPORTED_TYPES, typeManager.getTypes(), Type::getDisplayName),
+                filterSupportedTypes(
+                        NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES,
+                        new ArrayList<>(typeManager.getParametricTypes().values()),
+                        ParametricType::getName));
+    }
+
+    @Override
+    public Type getType(TypeSignature typeSignature)
+    {
+        // Todo: Fix this hack, native execution does not support parameterized char/varchar type signatures.
+        if (typeSignature.getBase().equals("char") || typeSignature.getBase().equals("varchar")) {
+            typeSignature = createUnboundedVarcharType().getTypeSignature();
+        }
+        Type type = types.get(typeSignature);
+        if (type != null) {
+            return type;
+        }
+        try {
+            return parametricTypeCache.getUnchecked(new ExactTypeSignature(typeSignature));
+        }
+        catch (UncheckedExecutionException e) {
+            throwIfUnchecked(e.getCause());
+            throw new RuntimeException(e.getCause());
+        }
+    }
+
+    @Override
+    public Map<String, ParametricType> getParametricTypes()
+    {
+        return parametricTypes;
+    }
+
+    @Override
+    public List<Type> getTypes()
+    {
+        return new ArrayList<>(types.values());
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: tdcmeehan
body: ```suggestion
        return ImmutableList.copyOf(types.values());
```
created_at: 2025-02-06T19:57:48Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,303 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR,
+                    UNKNOWN);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FUNCTION);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
+    private final ConcurrentMap<TypeSignature, Type> types = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, ParametricType> parametricTypes = new ConcurrentHashMap<>();
+
+    @Inject
+    public NativeTypeManager(TypeManager typeManager, NativeTypeManagerConfig config)
+    {
+        this.typeManager = requireNonNull(typeManager, "typeManager is null");
+        parametricTypeCache = CacheBuilder.newBuilder()
+                .maximumSize(1000)
+                .expireAfterWrite(config.getTypesCacheExpiration().toMillis(), MILLISECONDS)
+                .build(CacheLoader.from(this::instantiateParametricType));
+        addAllTypes(
+                filterSupportedTypes(NATIVE_ENGINE_SUPPORTED_TYPES, typeManager.getTypes(), Type::getDisplayName),
+                filterSupportedTypes(
+                        NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES,
+                        new ArrayList<>(typeManager.getParametricTypes().values()),
+                        ParametricType::getName));
+    }
+
+    @Override
+    public Type getType(TypeSignature typeSignature)
+    {
+        // Todo: Fix this hack, native execution does not support parameterized char/varchar type signatures.
+        if (typeSignature.getBase().equals("char") || typeSignature.getBase().equals("varchar")) {
+            typeSignature = createUnboundedVarcharType().getTypeSignature();
+        }
+        Type type = types.get(typeSignature);
+        if (type != null) {
+            return type;
+        }
+        try {
+            return parametricTypeCache.getUnchecked(new ExactTypeSignature(typeSignature));
+        }
+        catch (UncheckedExecutionException e) {
+            throwIfUnchecked(e.getCause());
+            throw new RuntimeException(e.getCause());
+        }
+    }
+
+    @Override
+    public Map<String, ParametricType> getParametricTypes()
+    {
+        return parametricTypes;
+    }
+
+    @Override
+    public List<Type> getTypes()
+    {
+        return new ArrayList<>(types.values());
+    }
+
+    @Override
+    public Type getParameterizedType(String baseTypeName, List<TypeSignatureParameter> typeParameters)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean canCoerce(Type actualType, Type expectedType)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    private void addAllTypes(List<Type> typesList, List<ParametricType> parametricTypesList)
+    {
+        for (Type type : typesList) {
+            addType(type);
+        }
+        // todo: Fix this hack
+        // Native engine does not support parameterized varchar, and varchar isn't in the lists of types returned from the engine
+        addType(VarcharType.VARCHAR);
+
+        for (ParametricType type : parametricTypesList) {
+            addParametricType(type);
+        }
+    }
+
+    private Type instantiateParametricType(ExactTypeSignature exactTypeSignature)
+    {
+        return typeManager.instantiateParametricType(exactTypeSignature.getTypeSignature());
+    }
+
+    private void addType(Type type)
+    {
+        requireNonNull(type, "type is null");
+        Type existingType = types.putIfAbsent(type.getTypeSignature(), type);
+        checkState(existingType == null || existingType.equals(type), "Type %s is already registered", type);
+    }
+
+    private void addParametricType(ParametricType parametricType)
+    {
+        String name = parametricType.getName().toLowerCase(Locale.ENGLISH);
+        checkArgument(!parametricTypes.containsKey(name), "Parametric type already registered: %s", name);
+        parametricTypes.putIfAbsent(name, parametricType);
+    }
+
+    private static <T> List<T> filterSupportedTypes(
+            Set<String> actualTypes,
+            List<T> types,
+            Function<T, String> typeSignatureExtractor)
+    {
+        return types.stream()
+                .filter(type -> actualTypes.contains(typeSignatureExtractor.apply(type)))
+                .collect(toImmutableList());
+    }
+
+    /**
+     * TypeSignature but has overridden equals(). Here, we compare exact signature of any underlying distinct
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: tdcmeehan
body: ```suggestion
     * TypeSignature has overridden equals(). Here, we compare exact signature of any underlying distinct
```
created_at: 2025-02-06T19:58:18Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,38 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.configuration.Config;
+import io.airlift.units.Duration;
+import io.airlift.units.MinDuration;
+
+import static java.util.concurrent.TimeUnit.MINUTES;
+
+public class NativeTypeManagerConfig
+{
+    private Duration typesCacheExpiration = new Duration(5, MINUTES);
+
+    @MinDuration("0ns")
+    public Duration getTypesCacheExpiration()
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManagerConfig.java
user: login: tdcmeehan
body: I think this is all in-memory.  So why do we need a time-based cache expiration policy?
created_at: 2025-02-06T19:59:33Z
author_association: CONTRIBUTOR
diff_hunk: @@ -835,6 +893,19 @@ public CatalogSchemaName configureDefaultNamespace(String defaultNamespacePrefix
         return new CatalogSchemaName(catalogSchemaNameString[0], catalogSchemaNameString[1]);
     }
 
+    private TypeManager getServingTypeManager()
+    {
+        // If the NativeSidecarPlugin is loaded, typeManagerFactories is non-empty and holds an instance of NativeTypeManagerFactory.
+        // Check if the nativeTypeManager exists in typeManagers else use BuiltInTypeAndFunctionNamespaceManager.
path: presto-main/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java
user: login: tdcmeehan
body: ```suggestion
        // Check if a custom TypeManager has been registered, otherwise use BuiltInTypeAndFunctionNamespaceManager.
```
created_at: 2025-02-06T20:01:17Z
author_association: CONTRIBUTOR
diff_hunk: @@ -28,4 +29,13 @@ public interface TypeManager
     Type getParameterizedType(String baseTypeName, List<TypeSignatureParameter> typeParameters);
 
     boolean canCoerce(Type actualType, Type expectedType);
+
+    default Type instantiateParametricType(TypeSignature typeSignature)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    List<Type> getTypes();
+
+    Map<String, ParametricType> getParametricTypes();
path: presto-common/src/main/java/com/facebook/presto/common/type/TypeManager.java
user: login: auden-woolfson
body: Should we change this to a default, and have it throw an `UnsupportedOperationException`? Would reduce duplicate code.
created_at: 2025-02-06T23:49:02Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1261,21 +1262,34 @@ public ScalarFunctionImplementation getScalarFunctionImplementation(Signature si
         }
     }
 
-    public Optional<Type> getType(TypeSignature typeSignature)
+    @Override
+    public Type getType(TypeSignature typeSignature)
     {
         Type type = types.get(typeSignature);
         if (type != null) {
-            return Optional.of(type);
+            return type;
         }
         try {
-            return Optional.ofNullable(parametricTypeCache.getUnchecked(new ExactTypeSignature(typeSignature)));
+            return parametricTypeCache.getUnchecked(new ExactTypeSignature(typeSignature));
         }
         catch (UncheckedExecutionException e) {
             throwIfUnchecked(e.getCause());
             throw new RuntimeException(e.getCause());
         }
     }
path: presto-main/src/main/java/com/facebook/presto/metadata/BuiltInTypeAndFunctionNamespaceManager.java
user: login: auden-woolfson
body: ```
try {
	return types.getOrDefault(typeSignature, parametricTypeCache.getUnchecked(new ExactTypeSignature(typeSignature)))
}
```

Would be more concise
created_at: 2025-02-06T23:55:33Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,303 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR,
+                    UNKNOWN);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FUNCTION);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
+    private final ConcurrentMap<TypeSignature, Type> types = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, ParametricType> parametricTypes = new ConcurrentHashMap<>();
+
+    @Inject
+    public NativeTypeManager(TypeManager typeManager, NativeTypeManagerConfig config)
+    {
+        this.typeManager = requireNonNull(typeManager, "typeManager is null");
+        parametricTypeCache = CacheBuilder.newBuilder()
+                .maximumSize(1000)
+                .expireAfterWrite(config.getTypesCacheExpiration().toMillis(), MILLISECONDS)
+                .build(CacheLoader.from(this::instantiateParametricType));
+        addAllTypes(
+                filterSupportedTypes(NATIVE_ENGINE_SUPPORTED_TYPES, typeManager.getTypes(), Type::getDisplayName),
+                filterSupportedTypes(
+                        NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES,
+                        new ArrayList<>(typeManager.getParametricTypes().values()),
+                        ParametricType::getName));
+    }
+
+    @Override
+    public Type getType(TypeSignature typeSignature)
+    {
+        // Todo: Fix this hack, native execution does not support parameterized char/varchar type signatures.
+        if (typeSignature.getBase().equals("char") || typeSignature.getBase().equals("varchar")) {
+            typeSignature = createUnboundedVarcharType().getTypeSignature();
+        }
+        Type type = types.get(typeSignature);
+        if (type != null) {
+            return type;
+        }
+        try {
+            return parametricTypeCache.getUnchecked(new ExactTypeSignature(typeSignature));
+        }
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: auden-woolfson
body: Can also make this more concise the same way
created_at: 2025-02-07T00:01:20Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,303 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR,
+                    UNKNOWN);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FUNCTION);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
+    private final ConcurrentMap<TypeSignature, Type> types = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, ParametricType> parametricTypes = new ConcurrentHashMap<>();
+
+    @Inject
+    public NativeTypeManager(TypeManager typeManager, NativeTypeManagerConfig config)
+    {
+        this.typeManager = requireNonNull(typeManager, "typeManager is null");
+        parametricTypeCache = CacheBuilder.newBuilder()
+                .maximumSize(1000)
+                .expireAfterWrite(config.getTypesCacheExpiration().toMillis(), MILLISECONDS)
+                .build(CacheLoader.from(this::instantiateParametricType));
+        addAllTypes(
+                filterSupportedTypes(NATIVE_ENGINE_SUPPORTED_TYPES, typeManager.getTypes(), Type::getDisplayName),
+                filterSupportedTypes(
+                        NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES,
+                        new ArrayList<>(typeManager.getParametricTypes().values()),
+                        ParametricType::getName));
+    }
+
+    @Override
+    public Type getType(TypeSignature typeSignature)
+    {
+        // Todo: Fix this hack, native execution does not support parameterized char/varchar type signatures.
+        if (typeSignature.getBase().equals("char") || typeSignature.getBase().equals("varchar")) {
+            typeSignature = createUnboundedVarcharType().getTypeSignature();
+        }
+        Type type = types.get(typeSignature);
+        if (type != null) {
+            return type;
+        }
+        try {
+            return parametricTypeCache.getUnchecked(new ExactTypeSignature(typeSignature));
+        }
+        catch (UncheckedExecutionException e) {
+            throwIfUnchecked(e.getCause());
+            throw new RuntimeException(e.getCause());
+        }
+    }
+
+    @Override
+    public Map<String, ParametricType> getParametricTypes()
+    {
+        return parametricTypes;
+    }
+
+    @Override
+    public List<Type> getTypes()
+    {
+        return new ArrayList<>(types.values());
+    }
+
+    @Override
+    public Type getParameterizedType(String baseTypeName, List<TypeSignatureParameter> typeParameters)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean canCoerce(Type actualType, Type expectedType)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    private void addAllTypes(List<Type> typesList, List<ParametricType> parametricTypesList)
+    {
+        for (Type type : typesList) {
+            addType(type);
+        }
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: auden-woolfson
body: ```
typesList.stream().forEach(type -> addType(type));
```
created_at: 2025-02-07T00:06:41Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,303 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR,
+                    UNKNOWN);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FUNCTION);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
+    private final ConcurrentMap<TypeSignature, Type> types = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, ParametricType> parametricTypes = new ConcurrentHashMap<>();
+
+    @Inject
+    public NativeTypeManager(TypeManager typeManager, NativeTypeManagerConfig config)
+    {
+        this.typeManager = requireNonNull(typeManager, "typeManager is null");
+        parametricTypeCache = CacheBuilder.newBuilder()
+                .maximumSize(1000)
+                .expireAfterWrite(config.getTypesCacheExpiration().toMillis(), MILLISECONDS)
+                .build(CacheLoader.from(this::instantiateParametricType));
+        addAllTypes(
+                filterSupportedTypes(NATIVE_ENGINE_SUPPORTED_TYPES, typeManager.getTypes(), Type::getDisplayName),
+                filterSupportedTypes(
+                        NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES,
+                        new ArrayList<>(typeManager.getParametricTypes().values()),
+                        ParametricType::getName));
+    }
+
+    @Override
+    public Type getType(TypeSignature typeSignature)
+    {
+        // Todo: Fix this hack, native execution does not support parameterized char/varchar type signatures.
+        if (typeSignature.getBase().equals("char") || typeSignature.getBase().equals("varchar")) {
+            typeSignature = createUnboundedVarcharType().getTypeSignature();
+        }
+        Type type = types.get(typeSignature);
+        if (type != null) {
+            return type;
+        }
+        try {
+            return parametricTypeCache.getUnchecked(new ExactTypeSignature(typeSignature));
+        }
+        catch (UncheckedExecutionException e) {
+            throwIfUnchecked(e.getCause());
+            throw new RuntimeException(e.getCause());
+        }
+    }
+
+    @Override
+    public Map<String, ParametricType> getParametricTypes()
+    {
+        return parametricTypes;
+    }
+
+    @Override
+    public List<Type> getTypes()
+    {
+        return new ArrayList<>(types.values());
+    }
+
+    @Override
+    public Type getParameterizedType(String baseTypeName, List<TypeSignatureParameter> typeParameters)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean canCoerce(Type actualType, Type expectedType)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    private void addAllTypes(List<Type> typesList, List<ParametricType> parametricTypesList)
+    {
+        for (Type type : typesList) {
+            addType(type);
+        }
+        // todo: Fix this hack
+        // Native engine does not support parameterized varchar, and varchar isn't in the lists of types returned from the engine
+        addType(VarcharType.VARCHAR);
+
+        for (ParametricType type : parametricTypesList) {
+            addParametricType(type);
+        }
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: auden-woolfson
body: Can use same functional pattern
created_at: 2025-02-07T00:07:11Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1261,21 +1262,34 @@ public ScalarFunctionImplementation getScalarFunctionImplementation(Signature si
         }
     }
 
-    public Optional<Type> getType(TypeSignature typeSignature)
+    @Override
+    public Type getType(TypeSignature typeSignature)
     {
         Type type = types.get(typeSignature);
         if (type != null) {
-            return Optional.of(type);
+            return type;
         }
         try {
-            return Optional.ofNullable(parametricTypeCache.getUnchecked(new ExactTypeSignature(typeSignature)));
+            return parametricTypeCache.getUnchecked(new ExactTypeSignature(typeSignature));
         }
         catch (UncheckedExecutionException e) {
             throwIfUnchecked(e.getCause());
             throw new RuntimeException(e.getCause());
         }
     }
path: presto-main/src/main/java/com/facebook/presto/metadata/BuiltInTypeAndFunctionNamespaceManager.java
user: login: pdabre12
body: Yes, it will be more concise, but I think the current code is much easier to read. What do you think?
created_at: 2025-02-07T22:10:11Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,303 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR,
+                    UNKNOWN);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FUNCTION);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
+    private final ConcurrentMap<TypeSignature, Type> types = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, ParametricType> parametricTypes = new ConcurrentHashMap<>();
+
+    @Inject
+    public NativeTypeManager(TypeManager typeManager, NativeTypeManagerConfig config)
+    {
+        this.typeManager = requireNonNull(typeManager, "typeManager is null");
+        parametricTypeCache = CacheBuilder.newBuilder()
+                .maximumSize(1000)
+                .expireAfterWrite(config.getTypesCacheExpiration().toMillis(), MILLISECONDS)
+                .build(CacheLoader.from(this::instantiateParametricType));
+        addAllTypes(
+                filterSupportedTypes(NATIVE_ENGINE_SUPPORTED_TYPES, typeManager.getTypes(), Type::getDisplayName),
+                filterSupportedTypes(
+                        NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES,
+                        new ArrayList<>(typeManager.getParametricTypes().values()),
+                        ParametricType::getName));
+    }
+
+    @Override
+    public Type getType(TypeSignature typeSignature)
+    {
+        // Todo: Fix this hack, native execution does not support parameterized char/varchar type signatures.
+        if (typeSignature.getBase().equals("char") || typeSignature.getBase().equals("varchar")) {
+            typeSignature = createUnboundedVarcharType().getTypeSignature();
+        }
+        Type type = types.get(typeSignature);
+        if (type != null) {
+            return type;
+        }
+        try {
+            return parametricTypeCache.getUnchecked(new ExactTypeSignature(typeSignature));
+        }
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: pdabre12
body: Same as above
created_at: 2025-02-07T22:13:51Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1261,21 +1262,34 @@ public ScalarFunctionImplementation getScalarFunctionImplementation(Signature si
         }
     }
 
-    public Optional<Type> getType(TypeSignature typeSignature)
+    @Override
+    public Type getType(TypeSignature typeSignature)
     {
         Type type = types.get(typeSignature);
         if (type != null) {
-            return Optional.of(type);
+            return type;
         }
         try {
-            return Optional.ofNullable(parametricTypeCache.getUnchecked(new ExactTypeSignature(typeSignature)));
+            return parametricTypeCache.getUnchecked(new ExactTypeSignature(typeSignature));
         }
         catch (UncheckedExecutionException e) {
             throwIfUnchecked(e.getCause());
             throw new RuntimeException(e.getCause());
         }
     }
path: presto-main/src/main/java/com/facebook/presto/metadata/BuiltInTypeAndFunctionNamespaceManager.java
user: login: auden-woolfson
body: Ok, either way works
created_at: 2025-02-08T00:16:23Z
author_association: CONTRIBUTOR
diff_hunk: @@ -28,4 +29,13 @@ public interface TypeManager
     Type getParameterizedType(String baseTypeName, List<TypeSignatureParameter> typeParameters);
 
     boolean canCoerce(Type actualType, Type expectedType);
+
+    default Type instantiateParametricType(TypeSignature typeSignature)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    List<Type> getTypes();
+
+    Map<String, ParametricType> getParametricTypes();
path: presto-common/src/main/java/com/facebook/presto/common/type/TypeManager.java
user: login: pdabre12
body: Made the change, thanks.
created_at: 2025-02-08T00:33:59Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,38 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.configuration.Config;
+import io.airlift.units.Duration;
+import io.airlift.units.MinDuration;
+
+import static java.util.concurrent.TimeUnit.MINUTES;
+
+public class NativeTypeManagerConfig
+{
+    private Duration typesCacheExpiration = new Duration(5, MINUTES);
+
+    @MinDuration("0ns")
+    public Duration getTypesCacheExpiration()
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManagerConfig.java
user: login: pdabre12
body: Removed this.
created_at: 2025-02-08T00:34:19Z
author_association: CONTRIBUTOR
diff_hunk: @@ -835,6 +896,18 @@ public CatalogSchemaName configureDefaultNamespace(String defaultNamespacePrefix
         return new CatalogSchemaName(catalogSchemaNameString[0], catalogSchemaNameString[1]);
     }
 
+    private TypeManager getServingTypeManager()
+    {
+        // Check if a custom TypeManager has been registered, otherwise use BuiltInTypeAndFunctionNamespaceManager.
+        for (Map.Entry<String, TypeManagerFactory> entry : typeManagerFactories.entrySet()) {
+            if (!typeManagers.containsKey(entry.getKey())) {
+                throw new PrestoException(GENERIC_USER_ERROR, format("Type manager not loaded for factory: %s", entry.getKey()));
+            }
+            return typeManagers.get(entry.getKey());
+        }
+        return builtInTypeAndFunctionNamespaceManager;
path: presto-main/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java
user: login: ZacBlanco
body: Is this something we could use with `Suppliers.memoize`?
created_at: 2025-02-12T17:34:16Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1342,6 +1349,12 @@ public Type visitCast(Cast node, StackableAstVisitorContext<Context> context)
             catch (IllegalArgumentException e) {
                 throw new SemanticException(TYPE_MISMATCH, node, "Unknown type: " + node.getType());
             }
+            catch (PrestoException e) {
+                if (e.getErrorCode() == UNKNOWN_TYPE.toErrorCode()) {
+                    throw new SemanticException(TYPE_MISMATCH, node, "Unknown type: " + node.getType());
+                }
path: presto-main/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java
user: login: ZacBlanco
body: Were you supposed to delete the `IllegalArgumentException` block here?

Also The fact that this is pattern (catch PrestoException, check error code) is so common makes me think we might want to create something like `UnknownTypeException` as subclass of `PrestoException` that always has the `UNKNOWN_TYPE` error code. Then all these catch blocks can just check for `UnknownTypeException` instead. It seems like forgetting this conditional could be something we miss in the future.

Another option could be to just throw SemanticException directly from the type manager? It would prevent having to modify the catch/re-throw blocks in a lot of locations
created_at: 2025-02-12T17:41:25Z
author_association: CONTRIBUTOR
diff_hunk: @@ -835,6 +896,18 @@ public CatalogSchemaName configureDefaultNamespace(String defaultNamespacePrefix
         return new CatalogSchemaName(catalogSchemaNameString[0], catalogSchemaNameString[1]);
     }
 
+    private TypeManager getServingTypeManager()
+    {
+        // Check if a custom TypeManager has been registered, otherwise use BuiltInTypeAndFunctionNamespaceManager.
+        for (Map.Entry<String, TypeManagerFactory> entry : typeManagerFactories.entrySet()) {
+            if (!typeManagers.containsKey(entry.getKey())) {
+                throw new PrestoException(GENERIC_USER_ERROR, format("Type manager not loaded for factory: %s", entry.getKey()));
+            }
+            return typeManagers.get(entry.getKey());
+        }
+        return builtInTypeAndFunctionNamespaceManager;
path: presto-main/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java
user: login: pdabre12
body: Done, thanks.
created_at: 2025-02-12T21:04:24Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1342,6 +1349,12 @@ public Type visitCast(Cast node, StackableAstVisitorContext<Context> context)
             catch (IllegalArgumentException e) {
                 throw new SemanticException(TYPE_MISMATCH, node, "Unknown type: " + node.getType());
             }
+            catch (PrestoException e) {
+                if (e.getErrorCode() == UNKNOWN_TYPE.toErrorCode()) {
+                    throw new SemanticException(TYPE_MISMATCH, node, "Unknown type: " + node.getType());
+                }
path: presto-main/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java
user: login: pdabre12
body: Added a new `UnknownTypeException`, subclass of `PrestoException`.

No, the `IllegalArgumentException`  block is still required. 
This block catches `IllegalArgumentExceptions` from classes like https://github.com/prestodb/presto/blob/master/presto-main/src/main/java/com/facebook/presto/type/MapParametricType.java#L52
created_at: 2025-02-12T21:17:49Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,298 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR,
+                    UNKNOWN);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FUNCTION);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
+    private final ConcurrentMap<TypeSignature, Type> types = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, ParametricType> parametricTypes = new ConcurrentHashMap<>();
+
+    @Inject
+    public NativeTypeManager(TypeManager typeManager)
+    {
+        this.typeManager = requireNonNull(typeManager, "typeManager is null");
+        parametricTypeCache = CacheBuilder.newBuilder()
+                .maximumSize(1000)
+                .build(CacheLoader.from(this::instantiateParametricType));
+        addAllTypes(
+                filterSupportedTypes(NATIVE_ENGINE_SUPPORTED_TYPES, typeManager.getTypes(), Type::getDisplayName),
+                filterSupportedTypes(
+                        NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES,
+                        new ArrayList<>(typeManager.getParametricTypes()),
+                        ParametricType::getName));
+    }
+
+    @Override
+    public Type getType(TypeSignature typeSignature)
+    {
+        // Todo: Fix this hack, native execution does not support parameterized char/varchar type signatures.
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: ZacBlanco
body: Do we have an open ticket for this so that we can track when the code needs to be removed?
created_at: 2025-02-17T20:15:07Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,298 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR,
+                    UNKNOWN);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FUNCTION);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
+    private final ConcurrentMap<TypeSignature, Type> types = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, ParametricType> parametricTypes = new ConcurrentHashMap<>();
+
+    @Inject
+    public NativeTypeManager(TypeManager typeManager)
+    {
+        this.typeManager = requireNonNull(typeManager, "typeManager is null");
+        parametricTypeCache = CacheBuilder.newBuilder()
+                .maximumSize(1000)
+                .build(CacheLoader.from(this::instantiateParametricType));
+        addAllTypes(
+                filterSupportedTypes(NATIVE_ENGINE_SUPPORTED_TYPES, typeManager.getTypes(), Type::getDisplayName),
+                filterSupportedTypes(
+                        NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES,
+                        new ArrayList<>(typeManager.getParametricTypes()),
+                        ParametricType::getName));
+    }
+
+    @Override
+    public Type getType(TypeSignature typeSignature)
+    {
+        // Todo: Fix this hack, native execution does not support parameterized char/varchar type signatures.
+        if (typeSignature.getBase().equals("char") || typeSignature.getBase().equals("varchar")) {
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: ZacBlanco
body: nit: use the type name from the StandardTypes class
```suggestion
        if (typeSignature.getBase().equals(CHAR) || typeSignature.getBase().equals(VARCHAR)) {
```
created_at: 2025-02-17T20:16:11Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,298 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR,
+                    UNKNOWN);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FUNCTION);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
+    private final ConcurrentMap<TypeSignature, Type> types = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, ParametricType> parametricTypes = new ConcurrentHashMap<>();
+
+    @Inject
+    public NativeTypeManager(TypeManager typeManager)
+    {
+        this.typeManager = requireNonNull(typeManager, "typeManager is null");
+        parametricTypeCache = CacheBuilder.newBuilder()
+                .maximumSize(1000)
+                .build(CacheLoader.from(this::instantiateParametricType));
+        addAllTypes(
+                filterSupportedTypes(NATIVE_ENGINE_SUPPORTED_TYPES, typeManager.getTypes(), Type::getDisplayName),
+                filterSupportedTypes(
+                        NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES,
+                        new ArrayList<>(typeManager.getParametricTypes()),
+                        ParametricType::getName));
+    }
+
+    @Override
+    public Type getType(TypeSignature typeSignature)
+    {
+        // Todo: Fix this hack, native execution does not support parameterized char/varchar type signatures.
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: pdabre12
body: I was not able to find an open ticket, but this is the PR where support will be added : https://github.com/facebookincubator/velox/pull/10727, its still a WIP.
created_at: 2025-02-17T20:36:31Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,298 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR,
+                    UNKNOWN);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FUNCTION);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
+    private final ConcurrentMap<TypeSignature, Type> types = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, ParametricType> parametricTypes = new ConcurrentHashMap<>();
+
+    @Inject
+    public NativeTypeManager(TypeManager typeManager)
+    {
+        this.typeManager = requireNonNull(typeManager, "typeManager is null");
+        parametricTypeCache = CacheBuilder.newBuilder()
+                .maximumSize(1000)
+                .build(CacheLoader.from(this::instantiateParametricType));
+        addAllTypes(
+                filterSupportedTypes(NATIVE_ENGINE_SUPPORTED_TYPES, typeManager.getTypes(), Type::getDisplayName),
+                filterSupportedTypes(
+                        NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES,
+                        new ArrayList<>(typeManager.getParametricTypes()),
+                        ParametricType::getName));
+    }
+
+    @Override
+    public Type getType(TypeSignature typeSignature)
+    {
+        // Todo: Fix this hack, native execution does not support parameterized char/varchar type signatures.
+        if (typeSignature.getBase().equals("char") || typeSignature.getBase().equals("varchar")) {
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: pdabre12
body: Done, thanks !
created_at: 2025-02-17T20:36:40Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,298 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR,
+                    UNKNOWN);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FUNCTION);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
+    private final ConcurrentMap<TypeSignature, Type> types = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, ParametricType> parametricTypes = new ConcurrentHashMap<>();
+
+    @Inject
+    public NativeTypeManager(TypeManager typeManager)
+    {
+        this.typeManager = requireNonNull(typeManager, "typeManager is null");
+        parametricTypeCache = CacheBuilder.newBuilder()
+                .maximumSize(1000)
+                .build(CacheLoader.from(this::instantiateParametricType));
+        addAllTypes(
+                filterSupportedTypes(NATIVE_ENGINE_SUPPORTED_TYPES, typeManager.getTypes(), Type::getDisplayName),
+                filterSupportedTypes(
+                        NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES,
+                        new ArrayList<>(typeManager.getParametricTypes()),
+                        ParametricType::getName));
+    }
+
+    @Override
+    public Type getType(TypeSignature typeSignature)
+    {
+        // Todo: Fix this hack, native execution does not support parameterized char/varchar type signatures.
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: ZacBlanco
body: Let's create an issue in presto so we can track it. The ticket should include the relevant parts which need to be removed once varchar(N) support lands and also a link to the velox PR above. You can leave the presto issue link in the comment so it will be easier to refer back to in the future
created_at: 2025-02-17T21:12:50Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,298 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR,
+                    UNKNOWN);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FUNCTION);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
+    private final ConcurrentMap<TypeSignature, Type> types = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, ParametricType> parametricTypes = new ConcurrentHashMap<>();
+
+    @Inject
+    public NativeTypeManager(TypeManager typeManager)
+    {
+        this.typeManager = requireNonNull(typeManager, "typeManager is null");
+        parametricTypeCache = CacheBuilder.newBuilder()
+                .maximumSize(1000)
+                .build(CacheLoader.from(this::instantiateParametricType));
+        addAllTypes(
+                filterSupportedTypes(NATIVE_ENGINE_SUPPORTED_TYPES, typeManager.getTypes(), Type::getDisplayName),
+                filterSupportedTypes(
+                        NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES,
+                        new ArrayList<>(typeManager.getParametricTypes()),
+                        ParametricType::getName));
+    }
+
+    @Override
+    public Type getType(TypeSignature typeSignature)
+    {
+        // Todo: Fix this hack, native execution does not support parameterized char/varchar type signatures.
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: pdabre12
body: I found an issue: https://github.com/prestodb/presto/issues/21332. I mentioned there that the char to varchar mapping in this PR needs to be removed when the varchar(N) support lands. Will that work?
created_at: 2025-02-17T21:37:24Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,298 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR,
+                    UNKNOWN);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FUNCTION);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
+    private final ConcurrentMap<TypeSignature, Type> types = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, ParametricType> parametricTypes = new ConcurrentHashMap<>();
+
+    @Inject
+    public NativeTypeManager(TypeManager typeManager)
+    {
+        this.typeManager = requireNonNull(typeManager, "typeManager is null");
+        parametricTypeCache = CacheBuilder.newBuilder()
+                .maximumSize(1000)
+                .build(CacheLoader.from(this::instantiateParametricType));
+        addAllTypes(
+                filterSupportedTypes(NATIVE_ENGINE_SUPPORTED_TYPES, typeManager.getTypes(), Type::getDisplayName),
+                filterSupportedTypes(
+                        NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES,
+                        new ArrayList<>(typeManager.getParametricTypes()),
+                        ParametricType::getName));
+    }
+
+    @Override
+    public Type getType(TypeSignature typeSignature)
+    {
+        // Todo: Fix this hack, native execution does not support parameterized char/varchar type signatures.
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: ZacBlanco
body: Yeah, that works
created_at: 2025-02-17T21:42:54Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,299 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.CHAR;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: majetideepak
body: Should we not be querying the native engine for these?
created_at: 2025-02-19T16:59:46Z
author_association: COLLABORATOR
diff_hunk: @@ -70,6 +72,7 @@ private StandardTypes() {}
             ROW,
             ARRAY,
             MAP,
+            FUNCTION,
path: presto-common/src/main/java/com/facebook/presto/common/type/StandardTypes.java
user: login: rschlussel
body: what is a function type?
created_at: 2025-02-19T17:11:14Z
author_association: CONTRIBUTOR
diff_hunk: @@ -28,4 +29,19 @@ public interface TypeManager
     Type getParameterizedType(String baseTypeName, List<TypeSignatureParameter> typeParameters);
 
     boolean canCoerce(Type actualType, Type expectedType);
+
+    default Type instantiateParametricType(TypeSignature typeSignature)
path: presto-common/src/main/java/com/facebook/presto/common/type/TypeManager.java
user: login: rschlussel
body: can we extract a separate interface to split out the TypeManager from a TypeNamespaceManager. Currently the responsibilities of FunctionAndTypeManager and BuiltinTypeAndFunctionNamespaceManager are distinct, but the methods for both are all in one interface, and we throw unsupportedoperationexceptions for the things that we don't expect to be under the responsibility for the particular class, which is not very safe.
created_at: 2025-02-19T17:47:29Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,299 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.CHAR;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: pdabre12
body: Ideally yes, but since types is a very slow moving thing, it makes sense to just add a newly added type to this list as the updates are not going to be very often. What do you think?
created_at: 2025-02-19T17:52:26Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,299 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.CHAR;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: majetideepak
body: This is okay as a first step. But user-defined types would require querying the native engine.
created_at: 2025-02-19T18:36:12Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,299 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.CHAR;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.FUNCTION;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: aditi-pandit
body: @majetideepak : This came up in a conversation with @pdabre12.

For user defined types, in addition to the worker type, any functions it participates in, the java co-ordinator also needs to know how to serialize/deserialize the objects of the type in java... Unless we are always going to pass-through opaque/binary serialized versions of the user defined type from the co-ordinator to the client. This is still an open-ended issue to resolve before making the types available from the native engine.

Once we have a good design for it, we can make the types list more dynamically retrieved from the workers.
created_at: 2025-02-20T00:24:37Z
author_association: CONTRIBUTOR
diff_hunk: @@ -70,6 +72,7 @@ private StandardTypes() {}
             ROW,
             ARRAY,
             MAP,
+            FUNCTION,
path: presto-common/src/main/java/com/facebook/presto/common/type/StandardTypes.java
user: login: pdabre12
body: It's used for lambda expressions. `FunctionType` is defined here: https://github.com/prestodb/presto/blob/f7103fe0c052460c38328f0708a1127aeccbf0c3/presto-common/src/main/java/com/facebook/presto/common/type/FunctionType.java#L30.
I do not think it should be added to `StandardTypes.java` , so I just added it to the supported parametric types list in `NativeTypeManager`.
created_at: 2025-02-27T22:13:46Z
author_association: CONTRIBUTOR
diff_hunk: @@ -28,4 +29,19 @@ public interface TypeManager
     Type getParameterizedType(String baseTypeName, List<TypeSignatureParameter> typeParameters);
 
     boolean canCoerce(Type actualType, Type expectedType);
+
+    default Type instantiateParametricType(TypeSignature typeSignature)
path: presto-common/src/main/java/com/facebook/presto/common/type/TypeManager.java
user: login: pdabre12
body: This was a huge refactor, I have a WIP PR for it: https://github.com/prestodb/presto/pull/24640. 
Is it okay if we let this one pass and handle in the PR described above?
created_at: 2025-02-27T22:14:37Z
author_association: CONTRIBUTOR
diff_hunk: @@ -835,6 +896,18 @@ public CatalogSchemaName configureDefaultNamespace(String defaultNamespacePrefix
         return new CatalogSchemaName(catalogSchemaNameString[0], catalogSchemaNameString[1]);
     }
 
+    private TypeManager getServingTypeManager()
+    {
+        // Check if a custom TypeManager has been registered, otherwise use BuiltInTypeAndFunctionNamespaceManager.
+        for (Map.Entry<String, TypeManagerFactory> entry : typeManagerFactories.entrySet()) {
+            if (!typeManagers.containsKey(entry.getKey())) {
+                throw new PrestoException(GENERIC_USER_ERROR, format("Type manager not loaded for factory: %s", entry.getKey()));
+            }
+            return typeManagers.get(entry.getKey());
+        }
+        return builtInTypeAndFunctionNamespaceManager;
path: presto-main/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java
user: login: pdabre12
body: @ZacBlanco I had to revert the changes. We cannot use `Suppliers.memoize` here because the call to `getServingTypeManager()` happens before the plugins are loaded meaning the `typeManager` used will always be `BuiltInTypeAndFunctionNamespaceManager` even if the `NativeTypeManager` is loaded.
created_at: 2025-02-27T22:17:04Z
author_association: CONTRIBUTOR
diff_hunk: @@ -835,6 +896,18 @@ public CatalogSchemaName configureDefaultNamespace(String defaultNamespacePrefix
         return new CatalogSchemaName(catalogSchemaNameString[0], catalogSchemaNameString[1]);
     }
 
+    private TypeManager getServingTypeManager()
+    {
+        // Check if a custom TypeManager has been registered, otherwise use BuiltInTypeAndFunctionNamespaceManager.
+        for (Map.Entry<String, TypeManagerFactory> entry : typeManagerFactories.entrySet()) {
+            if (!typeManagers.containsKey(entry.getKey())) {
+                throw new PrestoException(GENERIC_USER_ERROR, format("Type manager not loaded for factory: %s", entry.getKey()));
+            }
+            return typeManagers.get(entry.getKey());
+        }
+        return builtInTypeAndFunctionNamespaceManager;
path: presto-main/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java
user: login: ZacBlanco
body: Since getting a reference to the type manager is done quite frequently, it would be nice if we could just have a single reference so we don't have to do this iteration so often. I know that `typeManagerFactories` is likely going to just be 1 or 2 entries, but it seems inefficient to have to do this for every access. Do you think there's any other way we could cache this since it should be the same for the lifetime of the coordinator?
created_at: 2025-02-28T05:45:20Z
author_association: CONTRIBUTOR
diff_hunk: @@ -835,6 +896,18 @@ public CatalogSchemaName configureDefaultNamespace(String defaultNamespacePrefix
         return new CatalogSchemaName(catalogSchemaNameString[0], catalogSchemaNameString[1]);
     }
 
+    private TypeManager getServingTypeManager()
+    {
+        // Check if a custom TypeManager has been registered, otherwise use BuiltInTypeAndFunctionNamespaceManager.
+        for (Map.Entry<String, TypeManagerFactory> entry : typeManagerFactories.entrySet()) {
+            if (!typeManagers.containsKey(entry.getKey())) {
+                throw new PrestoException(GENERIC_USER_ERROR, format("Type manager not loaded for factory: %s", entry.getKey()));
+            }
+            return typeManagers.get(entry.getKey());
+        }
+        return builtInTypeAndFunctionNamespaceManager;
path: presto-main/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java
user: login: pdabre12
body: Maybe using an `AtomicReference` would work here.
`private final AtomicReference<TypeManager> servingTypeManager;`
 
 In the constructor call, 
 // initialize it with the built-in type manager.
` servingTypeManager = new AtomicReference<>(builtInTypeANdFunctionNamespaceManager);
` 
 As soon as the `nativeTypeManager` is loaded, update the `servingTypeManager` to be the `nativeTypeManager`.
 
 ```
public void loadTypeManager(String typeManagerName)
    {
        requireNonNull(typeManagerName, "typeManagerName is null");
        TypeManagerFactory factory = typeManagerFactories.get(typeManagerName);
        checkState(factory != null, "No factory for type manager %s", typeManagerName);
        TypeManager typeManager = factory.create(new TypeManagerContext(this));

        if (typeManagers.putIfAbsent(typeManagerName, typeManager) != null) {
            throw new IllegalArgumentException(format("Type manager [%s] is already registered", typeManager));
        }
        servingTypeManager.compareAndSet(servingTypeManager.get(), typeManager):
    }
```
In this way, we can just use `servingTypeManager` directly, which should solve the inefficiency described above.
What do you think? 

created_at: 2025-02-28T17:53:41Z
author_association: CONTRIBUTOR
diff_hunk: @@ -835,6 +896,18 @@ public CatalogSchemaName configureDefaultNamespace(String defaultNamespacePrefix
         return new CatalogSchemaName(catalogSchemaNameString[0], catalogSchemaNameString[1]);
     }
 
+    private TypeManager getServingTypeManager()
+    {
+        // Check if a custom TypeManager has been registered, otherwise use BuiltInTypeAndFunctionNamespaceManager.
+        for (Map.Entry<String, TypeManagerFactory> entry : typeManagerFactories.entrySet()) {
+            if (!typeManagers.containsKey(entry.getKey())) {
+                throw new PrestoException(GENERIC_USER_ERROR, format("Type manager not loaded for factory: %s", entry.getKey()));
+            }
+            return typeManagers.get(entry.getKey());
+        }
+        return builtInTypeAndFunctionNamespaceManager;
path: presto-main/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java
user: login: ZacBlanco
body: I think this approach sounds good
created_at: 2025-02-28T17:56:46Z
author_association: CONTRIBUTOR
diff_hunk: @@ -835,6 +896,18 @@ public CatalogSchemaName configureDefaultNamespace(String defaultNamespacePrefix
         return new CatalogSchemaName(catalogSchemaNameString[0], catalogSchemaNameString[1]);
     }
 
+    private TypeManager getServingTypeManager()
+    {
+        // Check if a custom TypeManager has been registered, otherwise use BuiltInTypeAndFunctionNamespaceManager.
+        for (Map.Entry<String, TypeManagerFactory> entry : typeManagerFactories.entrySet()) {
+            if (!typeManagers.containsKey(entry.getKey())) {
+                throw new PrestoException(GENERIC_USER_ERROR, format("Type manager not loaded for factory: %s", entry.getKey()));
+            }
+            return typeManagers.get(entry.getKey());
+        }
+        return builtInTypeAndFunctionNamespaceManager;
path: presto-main/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java
user: login: pdabre12
body: Made the changes, thanks.
created_at: 2025-02-28T20:43:12Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,299 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.FunctionType;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.CHAR;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR,
+                    UNKNOWN);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FunctionType.NAME);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
+    private final ConcurrentMap<TypeSignature, Type> types = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, ParametricType> parametricTypes = new ConcurrentHashMap<>();
+
+    @Inject
+    public NativeTypeManager(TypeManager typeManager)
+    {
+        this.typeManager = requireNonNull(typeManager, "typeManager is null");
+        parametricTypeCache = CacheBuilder.newBuilder()
+                .maximumSize(1000)
+                .build(CacheLoader.from(this::instantiateParametricType));
+        addAllTypes(
+                filterSupportedTypes(NATIVE_ENGINE_SUPPORTED_TYPES, typeManager.getTypes(), Type::getDisplayName),
+                filterSupportedTypes(
+                        NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES,
+                        new ArrayList<>(typeManager.getParametricTypes()),
+                        ParametricType::getName));
+    }
+
+    @Override
+    public Type getType(TypeSignature typeSignature)
+    {
+        // Todo: Fix this hack, native execution does not support parameterized char/varchar type signatures.
+        if (typeSignature.getBase().equals(CHAR) || typeSignature.getBase().equals(VARCHAR)) {
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: aditi-pandit
body: Trying to reduce the impact of this hack. What happens if we remove CHAR from this condition and fail all the queries with it ?
created_at: 2025-03-19T17:12:25Z
author_association: CONTRIBUTOR
diff_hunk: @@ -319,6 +346,17 @@ public FunctionMetadata getFunctionMetadata(FunctionHandle functionHandle)
         return functionNamespaceManager.get().getFunctionMetadata(functionHandle);
     }
 
+    @Override
+    public Type instantiateParametricType(TypeSignature typeSignature)
+    {
+        Map<String, ParametricType> parametricTypes = servingTypeManager.get().getParametricTypes().stream()
path: presto-main/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java
user: login: ZacBlanco
body: This seems a little expensive every time we instantiate a parametric type. Can we do anything to avoid the loop+copy here?
created_at: 2025-03-19T17:38:07Z
author_association: CONTRIBUTOR
diff_hunk: @@ -319,6 +346,17 @@ public FunctionMetadata getFunctionMetadata(FunctionHandle functionHandle)
         return functionNamespaceManager.get().getFunctionMetadata(functionHandle);
     }
 
+    @Override
+    public Type instantiateParametricType(TypeSignature typeSignature)
+    {
+        Map<String, ParametricType> parametricTypes = servingTypeManager.get().getParametricTypes().stream()
path: presto-main/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java
user: login: pdabre12
body: Maybe we can use `Suppliers.cache()`.
The only problem seems to be that the `servingTypeManager` can change so we need to update the cache based on whether `servingTypeManager` has changed.
created_at: 2025-03-19T20:02:32Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,299 @@
+/*
+ * Licensed 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.
+ */
+package com.facebook.presto.sidecar.typemanager;
+
+import com.facebook.airlift.log.Logger;
+import com.facebook.presto.common.type.DistinctTypeInfo;
+import com.facebook.presto.common.type.FunctionType;
+import com.facebook.presto.common.type.ParametricType;
+import com.facebook.presto.common.type.Type;
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.common.type.TypeSignature;
+import com.facebook.presto.common.type.TypeSignatureParameter;
+import com.facebook.presto.common.type.VarcharType;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static com.facebook.presto.common.type.StandardTypes.ARRAY;
+import static com.facebook.presto.common.type.StandardTypes.BIGINT;
+import static com.facebook.presto.common.type.StandardTypes.BOOLEAN;
+import static com.facebook.presto.common.type.StandardTypes.CHAR;
+import static com.facebook.presto.common.type.StandardTypes.DATE;
+import static com.facebook.presto.common.type.StandardTypes.DECIMAL;
+import static com.facebook.presto.common.type.StandardTypes.DOUBLE;
+import static com.facebook.presto.common.type.StandardTypes.HYPER_LOG_LOG;
+import static com.facebook.presto.common.type.StandardTypes.INTEGER;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
+import static com.facebook.presto.common.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
+import static com.facebook.presto.common.type.StandardTypes.IPADDRESS;
+import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
+import static com.facebook.presto.common.type.StandardTypes.JSON;
+import static com.facebook.presto.common.type.StandardTypes.MAP;
+import static com.facebook.presto.common.type.StandardTypes.REAL;
+import static com.facebook.presto.common.type.StandardTypes.ROW;
+import static com.facebook.presto.common.type.StandardTypes.SMALLINT;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP;
+import static com.facebook.presto.common.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
+import static com.facebook.presto.common.type.StandardTypes.TINYINT;
+import static com.facebook.presto.common.type.StandardTypes.UNKNOWN;
+import static com.facebook.presto.common.type.StandardTypes.UUID;
+import static com.facebook.presto.common.type.StandardTypes.VARBINARY;
+import static com.facebook.presto.common.type.StandardTypes.VARCHAR;
+import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Throwables.throwIfUnchecked;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.Objects.requireNonNull;
+
+public class NativeTypeManager
+        implements TypeManager
+{
+    private static final Logger log = Logger.get(NativeTypeManager.class);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_TYPES =
+            ImmutableSet.of(
+                    BIGINT,
+                    REAL,
+                    VARBINARY,
+                    TIMESTAMP,
+                    TINYINT,
+                    BOOLEAN,
+                    DATE,
+                    INTEGER,
+                    DOUBLE,
+                    SMALLINT,
+                    HYPER_LOG_LOG,
+                    JSON,
+                    TIMESTAMP_WITH_TIME_ZONE,
+                    UUID,
+                    IPADDRESS,
+                    IPPREFIX,
+                    INTERVAL_DAY_TO_SECOND,
+                    INTERVAL_YEAR_TO_MONTH,
+                    VARCHAR,
+                    UNKNOWN);
+
+    private static final Set<String> NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES =
+            ImmutableSet.of(
+                    ARRAY,
+                    DECIMAL,
+                    MAP,
+                    ROW,
+                    FunctionType.NAME);
+
+    private final TypeManager typeManager;
+    private final LoadingCache<ExactTypeSignature, Type> parametricTypeCache;
+    private final ConcurrentMap<TypeSignature, Type> types = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, ParametricType> parametricTypes = new ConcurrentHashMap<>();
+
+    @Inject
+    public NativeTypeManager(TypeManager typeManager)
+    {
+        this.typeManager = requireNonNull(typeManager, "typeManager is null");
+        parametricTypeCache = CacheBuilder.newBuilder()
+                .maximumSize(1000)
+                .build(CacheLoader.from(this::instantiateParametricType));
+        addAllTypes(
+                filterSupportedTypes(NATIVE_ENGINE_SUPPORTED_TYPES, typeManager.getTypes(), Type::getDisplayName),
+                filterSupportedTypes(
+                        NATIVE_ENGINE_SUPPORTED_PARAMETRIC_TYPES,
+                        new ArrayList<>(typeManager.getParametricTypes()),
+                        ParametricType::getName));
+    }
+
+    @Override
+    public Type getType(TypeSignature typeSignature)
+    {
+        // Todo: Fix this hack, native execution does not support parameterized char/varchar type signatures.
+        if (typeSignature.getBase().equals(CHAR) || typeSignature.getBase().equals(VARCHAR)) {
path: presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java
user: login: pdabre12
body: Done, removed `CHAR`.
created_at: 2025-03-19T23:41:41Z
author_association: CONTRIBUTOR
diff_hunk: @@ -319,6 +346,17 @@ public FunctionMetadata getFunctionMetadata(FunctionHandle functionHandle)
         return functionNamespaceManager.get().getFunctionMetadata(functionHandle);
     }
 
+    @Override
+    public Type instantiateParametricType(TypeSignature typeSignature)
+    {
+        Map<String, ParametricType> parametricTypes = servingTypeManager.get().getParametricTypes().stream()
path: presto-main/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java
user: login: pdabre12
body: Figured out a way , 
using 
`private final AtomicReference<Supplier<Map<String, ParametricType>>> servingTypeManagerParametricTypesSupplier;`

Updating the cache when we load the native type manager.

```
public void loadTypeManager(String typeManagerName)
    {
        requireNonNull(typeManagerName, "typeManagerName is null");
        TypeManagerFactory factory = typeManagerFactories.get(typeManagerName);
        checkState(factory != null, "No factory for type manager %s", typeManagerName);
        TypeManager typeManager = factory.create(new TypeManagerContext(this));

        if (typeManagers.putIfAbsent(typeManagerName, typeManager) != null) {
            throw new IllegalArgumentException(format("Type manager [%s] is already registered", typeManager));
        }
        servingTypeManager.compareAndSet(servingTypeManager.get(), typeManager);
        // Reset the parametric types cache
        servingTypeManagerParametricTypesSupplier.set(this::getServingTypeManagerParametricTypes);
    }
```

created_at: 2025-03-19T23:43:32Z
author_association: CONTRIBUTOR

PR comments:
user: login: steveburnett
created_at: 2025-02-04T22:43:31Z
body: New release note guidelines. Please remove the manual PR link in the following format from the release note entries for this PR.

```

:pr:`12345`

```

I have updated the [Release Notes Guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines) to remove the examples of manually adding the PR link.
author_association: CONTRIBUTOR
user: login: pdabre12
created_at: 2025-02-04T22:45:33Z
body: @steveburnett Thank you. Made the change.
author_association: CONTRIBUTOR
user: login: pdabre12
created_at: 2025-02-06T19:23:11Z
body: @tdcmeehan @rschlussel This PR is now ready for review, PTAL. Thanks.
author_association: CONTRIBUTOR
user: login: steveburnett
created_at: 2025-02-06T19:40:20Z
body: Thanks for the release note entry! Minor change to follow the [Order of sections](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines#order-of-sections) in the Release Notes Guidelines: 

```
== RELEASE NOTES ==

Prestissimo (Native Execution) Changes
* Add a native type manager
```
author_association: CONTRIBUTOR
user: login: pdabre12
created_at: 2025-02-12T21:19:18Z
body: @ZacBlanco Thanks for the quick review.
 Addressed your comments, can you please have another look?
author_association: CONTRIBUTOR
user: login: pdabre12
created_at: 2025-02-18T16:24:45Z
body: @rschlussel gentle ping, can you please have a look?
author_association: CONTRIBUTOR
user: login: jaystarshot
created_at: 2025-02-19T17:39:06Z
body: I think both commits can be squashed into one, also please add some info in the commit message [guidelines](https://github.com/prestodb/presto/wiki/Review-and-Commit-guidelines#example-commit-message)
author_association: MEMBER
user: login: rschlussel
created_at: 2025-02-19T17:50:02Z
body: > I think both commits can be squashed into one, also please add some info in the commit message [guidelines](https://github.com/prestodb/presto/wiki/Review-and-Commit-guidelines#example-commit-message)

either way is okay, but I like having the smaller commits
author_association: CONTRIBUTOR
user: login: pdabre12
created_at: 2025-02-27T22:18:07Z
body: @rschlussel Please have another look, thanks.
author_association: CONTRIBUTOR
user: login: pdabre12
created_at: 2025-03-05T22:05:26Z
body: @rschlussel 
Do you have any more comments on this? 
I addressed the previous comments. Thanks.
author_association: CONTRIBUTOR
user: login: pdabre12
created_at: 2025-03-12T19:36:05Z
body: @ZacBlanco Do you wanna take a look?
author_association: CONTRIBUTOR
user: login: pdabre12
created_at: 2025-03-20T18:57:33Z
body: @rschlussel 
Can you please have another look?
Native engine shouldn't allow creating tables with char column.
Whenever the sidecar plugin is enabled, any queries on the older tables constructed with char column will fail.
Is it safe to do so in your production environment? 
author_association: CONTRIBUTOR
user: login: libianoss
created_at: 2025-03-26T15:15:44Z
body:  @rschlussel can you help to review this PR?Thanks.
author_association: NONE
user: login: rschlussel
created_at: 2025-03-26T15:56:54Z
body: > @rschlussel Can you please have another look? Native engine shouldn't allow creating tables with char column. Whenever the sidecar plugin is enabled, any queries on the older tables constructed with char column will fail. Is it safe to do so in your production environment?

i don't think i understand what this means. Why doesn't native engine allow creating tables with char column?  Currently without sidecar, what happens if someone runs a query on a table with a char column?  
author_association: CONTRIBUTOR
user: login: pdabre12
created_at: 2025-03-26T16:02:53Z
body: > > @rschlussel Can you please have another look? Native engine shouldn't allow creating tables with char column. Whenever the sidecar plugin is enabled, any queries on the older tables constructed with char column will fail. Is it safe to do so in your production environment?
> 
> i don't think i understand what this means. Why doesn't native engine allow creating tables with char column? Currently without sidecar, what happens if someone runs a query on a table with a char column?

As of now, the native engine allows creating tables with char column and queries on a table with a char column should succeed. But with sidecar enabled, we are getting a list of supported types by the native engine and `CHAR` is not a part of it. As a result, if you have old tables created with the underlying column type as char and enable the sidecar, the queries on that table will fail.
author_association: CONTRIBUTOR
user: login: rschlussel
created_at: 2025-03-26T19:06:17Z
body: > > > @rschlussel Can you please have another look? Native engine shouldn't allow creating tables with char column. Whenever the sidecar plugin is enabled, any queries on the older tables constructed with char column will fail. Is it safe to do so in your production environment?
> > 
> > 
> > i don't think i understand what this means. Why doesn't native engine allow creating tables with char column? Currently without sidecar, what happens if someone runs a query on a table with a char column?
> 
> As of now, the native engine allows creating tables with char column and queries on a table with a char column should succeed. But with sidecar enabled, we are getting a list of supported types by the native engine and `CHAR` is not a part of it. As a result, if you have old tables created with the underlying column type as char and enable the sidecar, the queries on that table will fail.

if currently we can run queries on char columns, then why is it not supported? 
author_association: CONTRIBUTOR
user: login: pdabre12
created_at: 2025-03-26T19:17:22Z
body: > > > > @rschlussel Can you please have another look? Native engine shouldn't allow creating tables with char column. Whenever the sidecar plugin is enabled, any queries on the older tables constructed with char column will fail. Is it safe to do so in your production environment?
> > > 
> > > 
> > > i don't think i understand what this means. Why doesn't native engine allow creating tables with char column? Currently without sidecar, what happens if someone runs a query on a table with a char column?
> > 
> > 
> > As of now, the native engine allows creating tables with char column and queries on a table with a char column should succeed. But with sidecar enabled, we are getting a list of supported types by the native engine and `CHAR` is not a part of it. As a result, if you have old tables created with the underlying column type as char and enable the sidecar, the queries on that table will fail.
> 
> if currently we can run queries on char columns, then why is it not supported?

I am not really sure what happens under the hood right now when you create a table with char columns in a native cluster. The native engine does not understand char type, maybe it gets casted to a varchar( not sure) ? cc: @aditi-pandit.
But with this change, we only report the types supported by the native engine to the coordinator and as of now char is not one of them, so the queries would fail. This isn't an exclusive case for the char type but all the older and newer tables/queries with types not supported by the native engine would fail.

author_association: CONTRIBUTOR
user: login: rschlussel
created_at: 2025-03-26T19:31:03Z
body: @gggrace14 showed me that we actually are failing now in the workers when you try to query a char column, so this change should be okay.
author_association: CONTRIBUTOR
user: login: aditi-pandit
created_at: 2025-03-26T21:03:14Z
body: > > > > > @rschlussel Can you please have another look? Native engine shouldn't allow creating tables with char column. Whenever the sidecar plugin is enabled, any queries on the older tables constructed with char column will fail. Is it safe to do so in your production environment?
> > > > 
> > > > 
> > > > i don't think i understand what this means. Why doesn't native engine allow creating tables with char column? Currently without sidecar, what happens if someone runs a query on a table with a char column?
> > > 
> > > 
> > > As of now, the native engine allows creating tables with char column and queries on a table with a char column should succeed. But with sidecar enabled, we are getting a list of supported types by the native engine and `CHAR` is not a part of it. As a result, if you have old tables created with the underlying column type as char and enable the sidecar, the queries on that table will fail.
> > 
> > 
> > if currently we can run queries on char columns, then why is it not supported?
> 
> I am not really sure what happens under the hood right now when you create a table with char columns in a native cluster. The native engine does not understand char type, maybe it gets casted to a varchar( not sure) ? cc: @aditi-pandit. But with this change, we only report the types supported by the native engine to the coordinator and as of now char is not one of them, so the queries would fail. This isn't an exclusive case for the char type but all the older and newer tables/queries with types not supported by the native engine would fail.

@rschlussel : Today C++ clusters would support CREATE TABLE with char columns (as that is purely at the co-ordinator), but SELECT from them would fail at the workers since the PrestoToVelox conversions would reject the CHAR column. With this change, CHAR would not be exposed as a type, so even CREATE TABLE with char columns would fail.
author_association: CONTRIBUTOR