# Catalogs

> Trino catalogs as TrinoCatalog resources, covering how catalogs are created, added to clusters, overridden and used with generic connectors.

Trino does not have a built-in catalog and instead provides connectors to external data sources. This allows Trino to connect to, read from and join a wide variety of data sources.

## Using catalogs

Catalogs are defined in their own resources and referenced from cluster objects. See the [Concepts](https://docs.stackable.tech/home/stable/trino/concepts/index.md) page for more details.

### Create a catalog

You can create a catalog using the `TrinoCatalog` object as follows.

```yaml
apiVersion: trino.stackable.tech/v1alpha2
kind: TrinoCatalog
metadata:
  name: hive-catalog
  labels:
    trino: simple-trino
spec:
  connector:
    hive:
      metastore:
        configMap: simple-hive
      s3:
        inline:
          host: test-minio
          port: 9000
          accessStyle: Path
          credentials:
            secretClass: minio-credentials
---
apiVersion: trino.stackable.tech/v1alpha2
kind: TrinoCatalog
metadata:
  name: iceberg
  labels:
    trino: simple-trino
spec:
  connector:
    iceberg:
      catalog:
        hiveMetastore:
          configMap: simple-hive
      s3:
        inline:
          host: test-minio
          port: 9000
          accessStyle: Path
          credentials:
            secretClass: minio-credentials
```

The `metadata.name` is the name of the catalog that shows up in your Trino instance. The `metadata.labels` are used by TrinoCluster to determine the link between Trino clusters and `TrinoCatalogs`. The `spec.connector.<connector>` determines which connector is used. Each connector supports a different set of attributes.

### Config overrides and config removals

You can use `.spec.configOverrides` to set arbitrary additional properties, which will be added to the catalog.

There is also `.spec.experimentalConfigRemovals` to remove any properties the operator might set, but are not used by Trino. This causes Trino to refuse to startup with an error message such as `Error: Configuration property 'hive.s3.aws-access-key' was not used`. By removing the unneeded properties you can get Trino to start again.

This example illustrates how to use config overrides and config removals

```yaml
apiVersion: trino.stackable.tech/v1alpha2
kind: TrinoCatalog
spec:
  # Add some properties
  configOverrides:
    hive.metastore.username: trino
  # Remove some properties
  experimentalConfigRemovals:
    - hive.s3.aws-access-key
```

### Add a catalog to a Trino cluster

It is necessary to specify within the TrinoCluster which catalogs it should use. Here is an example of this:

```yaml
apiVersion: trino.stackable.tech/v1alpha1
kind: TrinoCluster
metadata:
  name: simple-trino
spec:
  clusterConfig:
    catalogLabelSelector:
      matchLabels:
        trino: simple-trino
# ...
```

The `spec.catalogLabelSelector` is used to fetch the list of `TrinoCatalogs` used for this Trino cluster. In this case the `hive` and `iceberg` catalogs will be used as they both match the `catalogLabelSelector` value `simple-trino`.

A `TrinoCluster` can, once created, detect and use new catalogs that have been subsequently created with a matching label. This also means that it is possible to reuse a `TrinoCatalog` within multiple `TrinoClusters`.

### Catalog name tweaking

By default the name of the catalog in Trino is inferred from the `.metadata.name` of the TrinoCatalog object. This ensures that no catalog names clash, as there can only be one TrinoCatalog with a given name.

One inconvenience is that you need to quote catalogs (or schemas and tables for that matter) containing `-` in Trino, while _is fine. As Kubernetes doesn’t allow_ in the object names, we offer a feature to replace `-` with _, which allows you to use valid Kubernetes names, but keeps the convenience of using_ in catalog names.

In order to replace `-` with `_`, use the setting `name.inferred.replaceHyphensWithUnderscores`. The Trino catalog will be called `my_postgres`:

```yaml
apiVersion: trino.stackable.tech/v1alpha2
kind: TrinoCatalog
metadata:
  name: my-postgres
spec:
  name:
    inferred:
      replaceHyphensWithUnderscores: true
# ...
```

### Generic fallback connector

Trino supports lots of different connectors and we can not cover all the available connectors. In case the Trino operator does not support a specific connector, there is a fallback mechanism: The [Generic](https://docs.stackable.tech/home/stable/trino/usage-guide/catalogs/generic/index.md).
