-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for record manifest writer
- Loading branch information
coufon
committed
Dec 22, 2023
1 parent
7c3128b
commit 40ea163
Showing
4 changed files
with
68 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# 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 | ||
# | ||
# https://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 typing import Any, Dict, List | ||
|
||
import pyarrow as pa | ||
import pyarrow.parquet as pq | ||
|
||
from space.core.manifests import RecordManifestWriter | ||
import space.core.proto.metadata_pb2 as meta | ||
from space.core.schema.arrow import field_metadata | ||
|
||
|
||
class TestRecordManifestWriter: | ||
|
||
def test_write(self, tmp_path): | ||
data_dir = tmp_path / "dataset" / "data" | ||
metadata_dir = tmp_path / "dataset" / "metadata" | ||
metadata_dir.mkdir(parents=True) | ||
|
||
manifest_writer = RecordManifestWriter(metadata_dir=str(metadata_dir)) | ||
|
||
manifest_writer.write( | ||
"data/file0.arrayrecord", 0, | ||
meta.StorageStatistics(num_rows=123, | ||
index_compressed_bytes=10, | ||
index_uncompressed_bytes=20, | ||
record_uncompressed_bytes=30)) | ||
manifest_writer.write( | ||
"data/file1.arrayrecord", 1, | ||
meta.StorageStatistics(num_rows=456, | ||
index_compressed_bytes=10, | ||
index_uncompressed_bytes=20, | ||
record_uncompressed_bytes=100)) | ||
|
||
manifest_path = manifest_writer.finish() | ||
|
||
data_dir_str = str(data_dir) | ||
assert manifest_path is not None | ||
assert pq.read_table(manifest_path).to_pydict() == { | ||
"_FILE": ["data/file0.arrayrecord", "data/file1.arrayrecord"], | ||
"_FIELD_ID": [0, 1], | ||
"_NUM_ROWS": [123, 456], | ||
"_UNCOMPRESSED_BYTES": [30, 100] | ||
} | ||
|
||
def test_empty_manifest_should_return_none(self, tmp_path): | ||
metadata_dir = tmp_path / "dataset" / "metadata" | ||
manifest_writer = RecordManifestWriter(metadata_dir=str(metadata_dir)) | ||
|
||
assert manifest_writer.finish() is None |
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