-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(python): expose create to DeltaTable class (#1932)
Allows one to create a table without writing. (created a new one, I keep messing up these rebases..) - closes #1892
- Loading branch information
1 parent
18c4834
commit 20214a5
Showing
4 changed files
with
182 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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 |