Skip to content

Commit

Permalink
Imports decouple (apache#505)
Browse files Browse the repository at this point in the history
Backport to 0.6.1
  • Loading branch information
ndrluis authored and HonahX committed Mar 29, 2024
1 parent d174760 commit 9b59fa2
Show file tree
Hide file tree
Showing 18 changed files with 27 additions and 35 deletions.
4 changes: 1 addition & 3 deletions pyiceberg/catalog/glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
PREVIOUS_METADATA_LOCATION,
TABLE_TYPE,
Catalog,
Identifier,
Properties,
PropertiesUpdateSummary,
)
from pyiceberg.exceptions import (
Expand All @@ -67,7 +65,7 @@
from pyiceberg.table import CommitTableRequest, CommitTableResponse, Table, update_table_metadata
from pyiceberg.table.metadata import TableMetadata, new_table_metadata
from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, SortOrder
from pyiceberg.typedef import EMPTY_DICT
from pyiceberg.typedef import EMPTY_DICT, Identifier, Properties
from pyiceberg.types import (
BinaryType,
BooleanType,
Expand Down
4 changes: 1 addition & 3 deletions pyiceberg/catalog/hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@
METADATA_LOCATION,
TABLE_TYPE,
Catalog,
Identifier,
Properties,
PropertiesUpdateSummary,
)
from pyiceberg.exceptions import (
Expand All @@ -79,7 +77,7 @@
from pyiceberg.table import CommitTableRequest, CommitTableResponse, Table, TableProperties, update_table_metadata
from pyiceberg.table.metadata import new_table_metadata
from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, SortOrder
from pyiceberg.typedef import EMPTY_DICT
from pyiceberg.typedef import EMPTY_DICT, Identifier, Properties
from pyiceberg.types import (
BinaryType,
BooleanType,
Expand Down
3 changes: 1 addition & 2 deletions pyiceberg/catalog/noop.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@
from pyiceberg.table import (
CommitTableRequest,
CommitTableResponse,
SortOrder,
Table,
)
from pyiceberg.table.sorting import UNSORTED_SORT_ORDER
from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, SortOrder
from pyiceberg.typedef import EMPTY_DICT, Identifier, Properties

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion pyiceberg/catalog/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
CommitTableResponse,
Table,
TableIdentifier,
TableMetadata,
)
from pyiceberg.table.metadata import TableMetadata
from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, SortOrder, assign_fresh_sort_order_ids
from pyiceberg.typedef import EMPTY_DICT, UTF8, IcebergBaseModel

Expand Down
4 changes: 1 addition & 3 deletions pyiceberg/catalog/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
from pyiceberg.catalog import (
METADATA_LOCATION,
Catalog,
Identifier,
Properties,
PropertiesUpdateSummary,
)
from pyiceberg.exceptions import (
Expand All @@ -64,7 +62,7 @@
from pyiceberg.table import CommitTableRequest, CommitTableResponse, Table, update_table_metadata
from pyiceberg.table.metadata import new_table_metadata
from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, SortOrder
from pyiceberg.typedef import EMPTY_DICT
from pyiceberg.typedef import EMPTY_DICT, Identifier, Properties

if TYPE_CHECKING:
import pyarrow as pa
Expand Down
3 changes: 1 addition & 2 deletions pyiceberg/expressions/visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
BoundStartsWith,
BoundTerm,
BoundUnaryPredicate,
L,
Not,
Or,
UnboundPredicate,
Expand All @@ -63,7 +62,7 @@
from pyiceberg.manifest import DataFile, ManifestFile, PartitionFieldSummary
from pyiceberg.partitioning import PartitionSpec
from pyiceberg.schema import Schema
from pyiceberg.typedef import EMPTY_DICT, StructProtocol
from pyiceberg.typedef import EMPTY_DICT, L, StructProtocol
from pyiceberg.types import (
DoubleType,
FloatType,
Expand Down
2 changes: 1 addition & 1 deletion pyiceberg/io/pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
AlwaysTrue,
BooleanExpression,
BoundTerm,
Literal,
)
from pyiceberg.expressions.literals import Literal
from pyiceberg.expressions.visitors import (
BoundBooleanExpressionVisitor,
bind,
Expand Down
13 changes: 7 additions & 6 deletions pyiceberg/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,15 @@
from sortedcontainers import SortedList
from typing_extensions import Annotated

import pyiceberg.expressions.parser as parser
import pyiceberg.expressions.visitors as visitors
from pyiceberg.exceptions import CommitFailedException, ResolveError, ValidationError
from pyiceberg.expressions import (
AlwaysTrue,
And,
BooleanExpression,
EqualTo,
parser,
visitors,
)
from pyiceberg.expressions.visitors import _InclusiveMetricsEvaluator, inclusive_projection
from pyiceberg.io import FileIO, load_file_io
from pyiceberg.manifest import (
POSITIONAL_DELETE_SCHEMA,
Expand Down Expand Up @@ -1293,7 +1292,9 @@ def _match_deletes_to_data_file(data_entry: ManifestEntry, positional_delete_ent
relevant_entries = positional_delete_entries[positional_delete_entries.bisect_right(data_entry) :]

if len(relevant_entries) > 0:
evaluator = _InclusiveMetricsEvaluator(POSITIONAL_DELETE_SCHEMA, EqualTo("file_path", data_entry.data_file.file_path))
evaluator = visitors._InclusiveMetricsEvaluator(
POSITIONAL_DELETE_SCHEMA, EqualTo("file_path", data_entry.data_file.file_path)
)
return {
positional_delete_entry.data_file
for positional_delete_entry in relevant_entries
Expand All @@ -1317,7 +1318,7 @@ def __init__(
super().__init__(table, row_filter, selected_fields, case_sensitive, snapshot_id, options, limit)

def _build_partition_projection(self, spec_id: int) -> BooleanExpression:
project = inclusive_projection(self.table.schema(), self.table.specs()[spec_id])
project = visitors.inclusive_projection(self.table.schema(), self.table.specs()[spec_id])
return project(self.row_filter)

@cached_property
Expand Down Expand Up @@ -1384,7 +1385,7 @@ def plan_files(self) -> Iterable[FileScanTask]:
# this filter depends on the partition spec used to write the manifest file

partition_evaluators: Dict[int, Callable[[DataFile], bool]] = KeyDefaultDict(self._build_partition_evaluator)
metrics_evaluator = _InclusiveMetricsEvaluator(
metrics_evaluator = visitors._InclusiveMetricsEvaluator(
self.table.schema(), self.row_filter, self.case_sensitive, self.options.get("include_empty_files") == "true"
).eval

Expand Down
4 changes: 1 addition & 3 deletions tests/catalog/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

from pyiceberg.catalog import (
Catalog,
Identifier,
Properties,
PropertiesUpdateSummary,
)
from pyiceberg.exceptions import (
Expand All @@ -56,7 +54,7 @@
from pyiceberg.table.metadata import TableMetadata, TableMetadataV1, new_table_metadata
from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, SortOrder
from pyiceberg.transforms import IdentityTransform
from pyiceberg.typedef import EMPTY_DICT
from pyiceberg.typedef import EMPTY_DICT, Identifier, Properties
from pyiceberg.types import IntegerType, LongType, NestedField


Expand Down
3 changes: 2 additions & 1 deletion tests/catalog/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from requests_mock import Mocker

import pyiceberg
from pyiceberg.catalog import PropertiesUpdateSummary, Table, load_catalog
from pyiceberg.catalog import PropertiesUpdateSummary, load_catalog
from pyiceberg.catalog.rest import AUTH_URL, RestCatalog
from pyiceberg.exceptions import (
NamespaceAlreadyExistsError,
Expand All @@ -35,6 +35,7 @@
from pyiceberg.io import load_file_io
from pyiceberg.partitioning import PartitionField, PartitionSpec
from pyiceberg.schema import Schema
from pyiceberg.table import Table
from pyiceberg.table.metadata import TableMetadataV1
from pyiceberg.table.sorting import SortField, SortOrder
from pyiceberg.transforms import IdentityTransform, TruncateTransform
Expand Down
2 changes: 1 addition & 1 deletion tests/catalog/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from pytest_lazyfixture import lazy_fixture
from sqlalchemy.exc import ArgumentError, IntegrityError

from pyiceberg.catalog import Identifier
from pyiceberg.catalog.sql import SqlCatalog
from pyiceberg.exceptions import (
CommitFailedException,
Expand All @@ -47,6 +46,7 @@
SortOrder,
)
from pyiceberg.transforms import IdentityTransform
from pyiceberg.typedef import Identifier
from pyiceberg.types import IntegerType


Expand Down
2 changes: 1 addition & 1 deletion tests/expressions/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import pytest
from pyparsing import ParseException

import pyiceberg.expressions.parser as parser
from pyiceberg.expressions import (
AlwaysFalse,
AlwaysTrue,
Expand All @@ -37,7 +38,6 @@
NotStartsWith,
Or,
StartsWith,
parser,
)


Expand Down
4 changes: 3 additions & 1 deletion tests/integration/test_writes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
from pyspark.sql import SparkSession
from pytest_mock.plugin import MockerFixture

from pyiceberg.catalog import Catalog, Properties, Table, load_catalog
from pyiceberg.catalog import Catalog, load_catalog
from pyiceberg.catalog.sql import SqlCatalog
from pyiceberg.exceptions import NamespaceAlreadyExistsError, NoSuchTableError
from pyiceberg.schema import Schema
from pyiceberg.table import Table
from pyiceberg.typedef import Properties
from pyiceberg.types import (
BinaryType,
BooleanType,
Expand Down
2 changes: 1 addition & 1 deletion tests/io/test_pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
GreaterThan,
Not,
Or,
literal,
)
from pyiceberg.expressions.literals import literal
from pyiceberg.io import InputStream, OutputStream, load_file_io
from pyiceberg.io.pyarrow import (
ICEBERG_SCHEMA,
Expand Down
2 changes: 1 addition & 1 deletion tests/table/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
RemovePropertiesUpdate,
SetPropertiesUpdate,
SetSnapshotRefUpdate,
SnapshotRef,
StaticTable,
Table,
UpdateSchema,
Expand All @@ -64,6 +63,7 @@
update_table_metadata,
)
from pyiceberg.table.metadata import INITIAL_SEQUENCE_NUMBER, TableMetadataUtil, TableMetadataV2
from pyiceberg.table.refs import SnapshotRef
from pyiceberg.table.snapshots import (
Operation,
Snapshot,
Expand Down
3 changes: 1 addition & 2 deletions tests/table/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@
from pyiceberg.partitioning import PartitionField, PartitionSpec
from pyiceberg.schema import Schema
from pyiceberg.serializers import FromByteStream
from pyiceberg.table import SortOrder
from pyiceberg.table.metadata import (
TableMetadataUtil,
TableMetadataV1,
TableMetadataV2,
new_table_metadata,
)
from pyiceberg.table.refs import SnapshotRef, SnapshotRefType
from pyiceberg.table.sorting import NullOrder, SortDirection, SortField
from pyiceberg.table.sorting import NullOrder, SortDirection, SortField, SortOrder
from pyiceberg.transforms import IdentityTransform
from pyiceberg.typedef import UTF8
from pyiceberg.types import (
Expand Down
2 changes: 1 addition & 1 deletion tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

from pyiceberg import schema
from pyiceberg.exceptions import ResolveError, ValidationError
from pyiceberg.expressions import Accessor
from pyiceberg.schema import (
Accessor,
Schema,
build_position_accessors,
promote,
Expand Down
3 changes: 1 addition & 2 deletions tests/utils/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
)
from pyiceberg.partitioning import PartitionField, PartitionSpec
from pyiceberg.schema import Schema
from pyiceberg.table import Snapshot
from pyiceberg.table.snapshots import Operation, Summary
from pyiceberg.table.snapshots import Operation, Snapshot, Summary
from pyiceberg.transforms import IdentityTransform
from pyiceberg.typedef import Record
from pyiceberg.types import IntegerType, NestedField
Expand Down

0 comments on commit 9b59fa2

Please sign in to comment.