mirror of
https://github.com/langchain-ai/delta-rs.git
synced 2026-07-19 22:34:16 -04:00
20214a5aba
Allows one to create a table without writing. (created a new one, I keep messing up these rebases..) - closes https://github.com/delta-io/delta-rs/issues/1892
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
import pathlib
|
|
|
|
import pyarrow as pa
|
|
import pytest
|
|
|
|
from deltalake import DeltaTable
|
|
from deltalake.exceptions import DeltaError
|
|
|
|
|
|
def test_create_roundtrip_metadata(tmp_path: pathlib.Path, sample_data: pa.Table):
|
|
dt = DeltaTable.create(
|
|
tmp_path,
|
|
sample_data.schema,
|
|
name="test_name",
|
|
description="test_desc",
|
|
configuration={"delta.appendOnly": "false", "foo": "bar"},
|
|
)
|
|
|
|
metadata = dt.metadata()
|
|
|
|
assert metadata.name == "test_name"
|
|
assert metadata.description == "test_desc"
|
|
assert metadata.configuration == {"delta.appendOnly": "false", "foo": "bar"}
|
|
|
|
|
|
def test_create_modes(tmp_path: pathlib.Path, sample_data: pa.Table):
|
|
dt = DeltaTable.create(tmp_path, sample_data.schema, mode="error")
|
|
last_action = dt.history(1)[0]
|
|
|
|
with pytest.raises(DeltaError):
|
|
dt = DeltaTable.create(tmp_path, sample_data.schema, mode="error")
|
|
|
|
assert last_action["operation"] == "CREATE TABLE"
|
|
with pytest.raises(DeltaError):
|
|
dt = DeltaTable.create(tmp_path, sample_data.schema, mode="append")
|
|
|
|
dt = DeltaTable.create(tmp_path, sample_data.schema, mode="ignore")
|
|
assert dt.version() == 0
|
|
|
|
dt = DeltaTable.create(tmp_path, sample_data.schema, mode="overwrite")
|
|
assert dt.version() == 1
|
|
|
|
last_action = dt.history(1)[0]
|
|
|
|
assert last_action["operation"] == "CREATE OR REPLACE TABLE"
|
|
|
|
|
|
def test_create_schema(tmp_path: pathlib.Path, sample_data: pa.Table):
|
|
dt = DeltaTable.create(
|
|
tmp_path,
|
|
sample_data.schema,
|
|
)
|
|
|
|
assert dt.schema().to_pyarrow() == sample_data.schema
|