generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 5
Transition to pyiceberg #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
itakserman-cloudinary
wants to merge
20
commits into
aws-samples:main
Choose a base branch
from
itakserman-cloudinary:transition_to_pyiceberg
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
02b0e46
Initial commit
itakserman-cloudinary dbc81f9
finalize tests
itakserman-cloudinary 53c13c8
finalize tests
itakserman-cloudinary 649cd88
Adjust readme
itakserman-cloudinary 0c8b47c
slight updates
itakserman-cloudinary 4f6fab4
Update template
itakserman-cloudinary eb7230e
Update template
itakserman-cloudinary 41fe55e
Adjust readme
itakserman-cloudinary e157ddb
finalize tests
itakserman-cloudinary bd480e1
linting
itakserman-cloudinary e2d7d9d
Support partition of complex types and multiple columns
itakserman-cloudinary e118a22
Repalce readme arch diagram
itakserman-cloudinary 882c58c
gitignore
itakserman-cloudinary a14126c
Add deploy from ECR
itakserman-cloudinary f9fce1a
Add deploy from ECR
itakserman-cloudinary e3f9772
Add deploy from ECR
itakserman-cloudinary a0c2075
Add deploy from ECR
itakserman-cloudinary 8bd7f93
Add deploy from ECR
itakserman-cloudinary d02e9bf
pr comments
itakserman-cloudinary fedb2f3
pr comments
itakserman-cloudinary File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -2,4 +2,5 @@ boto3==1.34.51 | |
| botocore==1.34.51 | ||
| pyiceberg[s3fs,glue] | ||
| pandas | ||
| typing_extensions | ||
| typing_extensions | ||
| pyarrow | ||
This file contains hidden or 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,21 @@ | ||
| # Use an official Python runtime as a parent image | ||
| FROM python:3.10-slim | ||
|
|
||
| # Set the working directory in the container | ||
| WORKDIR /lambda | ||
|
|
||
| # Copy the current directory contents into the container at /app | ||
| COPY . /lambda | ||
|
|
||
| # Install any needed packages specified in requirements.txt | ||
| RUN pip install --no-cache-dir -r tests/requirements.txt | ||
|
|
||
| # Install SQLite | ||
| RUN apt-get update && \ | ||
| apt-get install -y sqlite3 | ||
|
|
||
| ENV CW_NAMESPACE=TestNamespace \ | ||
| PYTHONPATH=/lambda | ||
|
|
||
| # Run the test suite | ||
| CMD ["pytest", "/lambda/tests/test_app.py"] |
Empty file.
This file contains hidden or 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,8 @@ | ||
| boto3==1.34.51 | ||
| botocore==1.34.51 | ||
| pyiceberg[s3fs,glue]==0.7.0 | ||
| SQLAlchemy==2.0.30 | ||
| pyarrow==17.0.0 | ||
| pandas==2.2.2 | ||
| pytest==7.1.2 | ||
| unittest2==1.1.0 |
This file contains hidden or 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,114 @@ | ||
| import os | ||
| import shutil | ||
| import unittest | ||
| from numbers import Number | ||
| from unittest.mock import patch | ||
| from pyiceberg.schema import Schema | ||
| from pyiceberg.types import LongType, StringType, NestedField | ||
| from pyiceberg.partitioning import PartitionField, PartitionSpec | ||
| from pyiceberg.catalog.sql import SqlCatalog | ||
| import numpy as np | ||
| import pyarrow as pa | ||
| from app import send_files_metrics, send_partition_metrics, send_snapshot_metrics | ||
|
|
||
| # Mock AWS credentials | ||
| os.environ['AWS_ACCESS_KEY_ID'] = 'testing' | ||
| os.environ['AWS_SECRET_ACCESS_KEY'] = 'testing' | ||
| os.environ['AWS_SECURITY_TOKEN'] = 'testing' | ||
| os.environ['AWS_SESSION_TOKEN'] = 'testing' | ||
|
|
||
| class TestIcebergMetrics(unittest.TestCase): | ||
|
|
||
| @patch.dict(os.environ, {'CW_NAMESPACE': 'TestNamespace'}) | ||
| def setUp(self): | ||
| self.schema = Schema( | ||
| NestedField(1, 'id', LongType(), False), | ||
| NestedField(2, 'data', StringType(), False) | ||
| ) | ||
| self.partition_spec = PartitionSpec( | ||
| fields=[ | ||
| PartitionField(source_id=2, field_id=1000, name="data", transform="identity") | ||
| ] | ||
| ) | ||
|
|
||
| catalog_path = './tests/test_db' | ||
| if os.path.exists(catalog_path): | ||
| shutil.rmtree(catalog_path) | ||
| os.makedirs(catalog_path) | ||
| warehouse_path = os.path.abspath(catalog_path) | ||
| self.catalog = SqlCatalog( | ||
| "default", | ||
| **{ | ||
| "uri": f"sqlite:///{warehouse_path}/pyiceberg_catalog.db", | ||
| "warehouse": f"file://{warehouse_path}", | ||
| }, | ||
| ) | ||
| self.catalog.create_namespace('default') | ||
| self.catalog.create_table( | ||
| 'default.test_table', | ||
| schema=self.schema, | ||
| partition_spec=self.partition_spec | ||
| ) | ||
|
|
||
| # Load the table and insert some data | ||
| self.table = self.catalog.load_table(('default', 'test_table')) | ||
| self.update_table(0, 5) | ||
|
|
||
|
|
||
| def create_arrow_table(self, range_start, range_end): | ||
| data = { | ||
| 'id': pa.array(range(range_start, range_end), pa.int64()), | ||
| 'data': pa.array(['data' + str(i) for i in range(range_start, range_end)], pa.string()) | ||
| } | ||
| return pa.Table.from_pydict(data) | ||
|
|
||
|
|
||
| def assert_metrics(self, expected, table, snapshot, method_to_test): | ||
| def send_metrics_stub(metrics, namespace, table, snapshot): | ||
| metrics = {k: v.item() if not isinstance(v, Number) else v for k, v in metrics.items()} | ||
| self.assertDictEqual(metrics, expected) | ||
|
|
||
| with patch('app.send_metrics', side_effect=send_metrics_stub): | ||
| method_to_test(table, snapshot) | ||
|
|
||
|
|
||
| def test_send_files_metrics(self): | ||
| expected_file_metrics = {'avg_record_count': np.int64(1), 'max_record_count': np.int64(1), 'min_record_count': np.int64(1), 'avg_file_size': np.int64(1068), 'max_file_size': np.int64(1068), 'min_file_size': np.int64(1068)} | ||
| self.assert_metrics(expected_file_metrics, self.table, self.snapshot, send_files_metrics) | ||
|
|
||
|
|
||
| @patch('app.send_custom_metric') | ||
| def test_send_partition_metrics(self, mock_send_custom_metric): | ||
| expected_partition_metrics = {'avg_record_count': np.int64(1), 'max_record_count': np.int64(1), 'min_record_count': np.int64(1), 'deviation_record_count': np.float64(0.0), 'skew_record_count': np.float64(0.0), 'avg_file_count': np.int64(1), 'max_file_count': np.int64(1), 'min_file_count': np.int64(1), 'deviation_file_count': np.float64(0.0), 'skew_file_count': np.float64(0.0)} | ||
| self.assert_metrics(expected_partition_metrics, self.table, self.snapshot, send_partition_metrics) | ||
|
|
||
|
|
||
| def test_send_snapshot_metrics(self): | ||
| expected_snapshot_metrics = {'added_data_files': 5, 'added_records': 5, 'changed_partition_count': 5, 'total_records': 5, 'total_data_files': 5, 'total_delete_files': 0, 'added_files_size': 5340, 'total_files_size': 5340, 'added_position_deletes': 0} | ||
| self.assert_metrics(expected_snapshot_metrics, self.table, self.snapshot, send_snapshot_metrics) | ||
|
|
||
|
|
||
| def update_table(self, range_start, range_end): | ||
| # Perform an update operation on the Iceberg table | ||
| arrow_table = self.create_arrow_table(range_start, range_end) | ||
| self.table.append(arrow_table) | ||
| self.table.refresh() | ||
| self.snapshot = self.table.current_snapshot() | ||
|
|
||
|
|
||
| @patch('app.send_custom_metric') | ||
| def test_metrics_after_update(self, mock_send_custom_metric): | ||
| self.update_table(5, 10) | ||
|
|
||
| expected_file_metrics = {'avg_record_count': np.int64(1), 'max_record_count': np.int64(1), 'min_record_count': np.int64(1), 'avg_file_size': np.int64(1068), 'max_file_size': np.int64(1068), 'min_file_size': np.int64(1068)} | ||
| self.assert_metrics(expected_file_metrics, self.table, self.snapshot, send_files_metrics) | ||
|
|
||
| expected_partition_metrics = {'avg_record_count': np.int64(1), 'max_record_count': np.int64(1), 'min_record_count': np.int64(1), 'deviation_record_count': np.float64(0.0), 'skew_record_count': np.float64(0.0), 'avg_file_count': np.int64(1), 'max_file_count': np.int64(1), 'min_file_count': np.int64(1), 'deviation_file_count': np.float64(0.0), 'skew_file_count': np.float64(0.0)} | ||
| self.assert_metrics(expected_partition_metrics, self.table, self.snapshot, send_partition_metrics) | ||
|
|
||
| expected_snapshot_metrics = {'added_data_files': 5, 'added_records': 5, 'changed_partition_count': 5, 'total_records': 10, 'total_data_files': 10, 'total_delete_files': 0, 'added_files_size': 5340, 'total_files_size': 10680, 'added_position_deletes': 0} | ||
| self.assert_metrics(expected_snapshot_metrics, self.table, self.snapshot, send_snapshot_metrics) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.