-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: range use python generator
- Loading branch information
1 parent
bb506a4
commit ec40b9a
Showing
21 changed files
with
395 additions
and
417 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,29 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Callable | ||
|
||
if TYPE_CHECKING: | ||
from collections.abc import Iterator | ||
|
||
from daft import DataType | ||
from daft.io._generator import GeneratorScanOperator | ||
from daft.logical.schema import Schema | ||
from daft.table.table import Table | ||
|
||
|
||
def _range_generators(start: int, end: int, step: int) -> Iterator[Callable[[], Iterator[Table]]]: | ||
def generator_for_value(value: int) -> Callable[[], Iterator[Table]]: | ||
def generator() -> Iterator[Table]: | ||
yield Table.from_pydict({"id": [value]}) | ||
|
||
return generator | ||
|
||
for value in range(start, end, step): | ||
yield generator_for_value(value) | ||
|
||
|
||
class RangeScanOperator(GeneratorScanOperator): | ||
def __init__(self, start: int, end: int, step: int = 1) -> None: | ||
schema = Schema._from_field_name_and_types([("id", DataType.int64())]) | ||
|
||
super().__init__(schema=schema, generators=_range_generators(start, end, step)) |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.