-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
107 additions
and
23 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,52 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# See the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# Distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND. | ||
|
||
""" | ||
Arrow Reader | ||
Used to read datasets registered using the register_arrow or register_df functions. | ||
""" | ||
|
||
import pyarrow | ||
from orso.schema import FlatColumn | ||
from orso.schema import RelationSchema | ||
|
||
from opteryx.connectors.base.base_connector import DEFAULT_MORSEL_SIZE | ||
from opteryx.connectors.base.base_connector import BaseConnector | ||
from opteryx.shared import MaterializedDatasets | ||
from opteryx.utils import arrow | ||
|
||
|
||
class IcebergConnector(BaseConnector): | ||
__mode__ = "Internal" | ||
__type__ = "ARROW" | ||
|
||
def __init__(self, *args, **kwargs): | ||
BaseConnector.__init__(self, **kwargs) | ||
|
||
self.dataset = self.dataset.lower() | ||
self._datasets = MaterializedDatasets() | ||
|
||
def get_dataset_schema(self) -> RelationSchema: | ||
dataset = self._datasets[self.dataset] | ||
arrow_schema = dataset.schema | ||
|
||
self.schema = RelationSchema( | ||
name=self.dataset, | ||
columns=[FlatColumn.from_arrow(field) for field in arrow_schema], | ||
) | ||
|
||
return self.schema | ||
|
||
def read_dataset(self, columns: list = None, **kwargs) -> pyarrow.Table: | ||
dataset = self._datasets[self.dataset] | ||
|
||
batch_size = DEFAULT_MORSEL_SIZE // (dataset.nbytes / dataset.num_rows) | ||
|
||
for batch in dataset.to_batches(max_chunksize=batch_size): | ||
morsel = pyarrow.Table.from_batches([batch], schema=dataset.schema) | ||
if columns: | ||
morsel = arrow.post_read_projector(morsel, columns) | ||
yield morsel |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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