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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions mkdocs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,23 @@ catalog:
| echo | true | false | SQLAlchemy engine [echo param](https://docs.sqlalchemy.org/en/20/core/engines.html#sqlalchemy.create_engine.params.echo) to log all statements to the default log handler |
| pool_pre_ping | true | false | SQLAlchemy engine [pool_pre_ping param](https://docs.sqlalchemy.org/en/20/core/engines.html#sqlalchemy.create_engine.params.pool_pre_ping) to test connections for liveness upon each checkout |

### In Memory Catalog

The in-memory catalog is built on top of `SqlCatalog` and uses SQLite in-memory database for its backend.

It is useful for test, demo, and playground but not in production as it does not support concurrent access.

```yaml
catalog:
default:
type: in-memory
warehouse: /tmp/pyiceberg/warehouse
```

| Key | Example | Default | Description |
| --------- |--------------------------|-------------------------------|----------------------------------------------------------------------|
| warehouse | /tmp/pyiceberg/warehouse | file:///tmp/iceberg/warehouse | The directory where the in-memory catalog will store its data files. |

### Hive Catalog

```yaml
Expand Down
11 changes: 11 additions & 0 deletions pyiceberg/catalog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class CatalogType(Enum):
GLUE = "glue"
DYNAMODB = "dynamodb"
SQL = "sql"
IN_MEMORY = "in-memory"


def load_rest(name: str, conf: Properties) -> Catalog:
Expand Down Expand Up @@ -162,12 +163,22 @@ def load_sql(name: str, conf: Properties) -> Catalog:
) from exc


def load_in_memory(name: str, conf: Properties) -> Catalog:
try:
from pyiceberg.catalog.memory import InMemoryCatalog

return InMemoryCatalog(name, **conf)
except ImportError as exc:
raise NotInstalledError("SQLAlchemy support not installed: pip install 'pyiceberg[sql-sqlite]'") from exc


AVAILABLE_CATALOGS: dict[CatalogType, Callable[[str, Properties], Catalog]] = {
CatalogType.REST: load_rest,
CatalogType.HIVE: load_hive,
CatalogType.GLUE: load_glue,
CatalogType.DYNAMODB: load_dynamodb,
CatalogType.SQL: load_sql,
CatalogType.IN_MEMORY: load_in_memory,
}


Expand Down
32 changes: 32 additions & 0 deletions pyiceberg/catalog/memory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

from pyiceberg.catalog.sql import SqlCatalog


class InMemoryCatalog(SqlCatalog):
"""
An in-memory catalog implementation that uses SqlCatalog with SQLite in-memory database.

This is useful for test, demo, and playground but not in production as it does not support concurrent access.
"""

def __init__(self, name: str, warehouse: str = "file:///tmp/iceberg/warehouse", **kwargs: str) -> None:
self._warehouse_location = warehouse
if "uri" not in kwargs:
kwargs["uri"] = "sqlite:///:memory:"
super().__init__(name=name, warehouse=warehouse, **kwargs)
Loading