westonpace commented on code in PR #35568: URL: https://github.com/apache/arrow/pull/35568#discussion_r1196918634
########## python/pyarrow/dataset/protocol.py: ########## @@ -0,0 +1,77 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. +"""Protocol definitions for pyarrow.dataset + +These provide the abstract interface for a dataset. Other libraries may implement +this interface to expose their data, without having to extend PyArrow's classes. + +Applications and libraries that want to consume datasets should accept datasets +that implement these protocols, rather than requiring the specific +PyArrow classes. +""" +from abc import abstractmethod +from typing import Iterator, List, Optional, Protocol + +from pyarrow.dataset import Expression +from pyarrow import Table, IntegerArray, RecordBatch, RecordBatchReader, Schema + + +class Scanner(Protocol): + @abstractmethod + def count_rows(self) -> int: + ... + + @abstractmethod + def head(self, num_rows: int) -> Table: + ... + + @abstractmethod + def take(self, indices: IntegerArray) -> Table: + ... + + @abstractmethod + def to_table(self) -> Table: + ... + + @abstractmethod + def to_batches(self) -> Iterator[RecordBatch]: + ... + + @abstractmethod + def to_reader(self) -> RecordBatchReader: + ... + + +class Scannable(Protocol): + @abstractmethod + def scanner(self, columns: Optional[List[str]] = None, + filter: Optional[Expression] = None, **kwargs) -> Scanner: Review Comment: Must this filter be satisfied? Or is it best effort? If it must be satisfied then how will you handle UDFs and other strange functions in the filter? ########## python/pyarrow/dataset/protocol.py: ########## @@ -0,0 +1,77 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. +"""Protocol definitions for pyarrow.dataset + +These provide the abstract interface for a dataset. Other libraries may implement +this interface to expose their data, without having to extend PyArrow's classes. + +Applications and libraries that want to consume datasets should accept datasets +that implement these protocols, rather than requiring the specific +PyArrow classes. +""" +from abc import abstractmethod +from typing import Iterator, List, Optional, Protocol + +from pyarrow.dataset import Expression +from pyarrow import Table, IntegerArray, RecordBatch, RecordBatchReader, Schema + + +class Scanner(Protocol): Review Comment: Any notion of ordering / sortedness is missing. ########## python/pyarrow/dataset/protocol.py: ########## @@ -0,0 +1,77 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. +"""Protocol definitions for pyarrow.dataset + +These provide the abstract interface for a dataset. Other libraries may implement +this interface to expose their data, without having to extend PyArrow's classes. + +Applications and libraries that want to consume datasets should accept datasets +that implement these protocols, rather than requiring the specific +PyArrow classes. +""" +from abc import abstractmethod +from typing import Iterator, List, Optional, Protocol + +from pyarrow.dataset import Expression +from pyarrow import Table, IntegerArray, RecordBatch, RecordBatchReader, Schema + + +class Scanner(Protocol): + @abstractmethod + def count_rows(self) -> int: + ... + + @abstractmethod + def head(self, num_rows: int) -> Table: + ... + + @abstractmethod + def take(self, indices: IntegerArray) -> Table: + ... + + @abstractmethod + def to_table(self) -> Table: + ... + + @abstractmethod + def to_batches(self) -> Iterator[RecordBatch]: + ... Review Comment: If you have `to_reader` then you could create a default implementation for these two methods. Is there any particular reason to include them? In other words, do you expect an implementation to be able to somehow support `to_table` more efficiently than `to_reader().read_all()`? ########## python/pyarrow/dataset/protocol.py: ########## @@ -0,0 +1,77 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. +"""Protocol definitions for pyarrow.dataset + +These provide the abstract interface for a dataset. Other libraries may implement +this interface to expose their data, without having to extend PyArrow's classes. + +Applications and libraries that want to consume datasets should accept datasets +that implement these protocols, rather than requiring the specific +PyArrow classes. +""" +from abc import abstractmethod +from typing import Iterator, List, Optional, Protocol + +from pyarrow.dataset import Expression +from pyarrow import Table, IntegerArray, RecordBatch, RecordBatchReader, Schema + + +class Scanner(Protocol): + @abstractmethod + def count_rows(self) -> int: + ... + + @abstractmethod + def head(self, num_rows: int) -> Table: + ... + + @abstractmethod + def take(self, indices: IntegerArray) -> Table: + ... + + @abstractmethod + def to_table(self) -> Table: + ... + + @abstractmethod + def to_batches(self) -> Iterator[RecordBatch]: + ... + + @abstractmethod + def to_reader(self) -> RecordBatchReader: + ... + + +class Scannable(Protocol): + @abstractmethod + def scanner(self, columns: Optional[List[str]] = None, Review Comment: The difference between `Sequence[str]` and `Dict[str, Expression]` is significant. The former only allows you to pick which columns to load. The latter introduces the concept of project expressions which is big. ########## python/pyarrow/dataset/protocol.py: ########## @@ -0,0 +1,77 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. +"""Protocol definitions for pyarrow.dataset + +These provide the abstract interface for a dataset. Other libraries may implement +this interface to expose their data, without having to extend PyArrow's classes. + +Applications and libraries that want to consume datasets should accept datasets +that implement these protocols, rather than requiring the specific +PyArrow classes. +""" +from abc import abstractmethod +from typing import Iterator, List, Optional, Protocol + +from pyarrow.dataset import Expression +from pyarrow import Table, IntegerArray, RecordBatch, RecordBatchReader, Schema + + +class Scanner(Protocol): + @abstractmethod + def count_rows(self) -> int: + ... + + @abstractmethod + def head(self, num_rows: int) -> Table: + ... + + @abstractmethod + def take(self, indices: IntegerArray) -> Table: + ... + + @abstractmethod + def to_table(self) -> Table: + ... + + @abstractmethod + def to_batches(self) -> Iterator[RecordBatch]: + ... + + @abstractmethod + def to_reader(self) -> RecordBatchReader: + ... Review Comment: Isn't that the C stream interface? ########## python/pyarrow/dataset/protocol.py: ########## @@ -0,0 +1,77 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. +"""Protocol definitions for pyarrow.dataset + +These provide the abstract interface for a dataset. Other libraries may implement +this interface to expose their data, without having to extend PyArrow's classes. + +Applications and libraries that want to consume datasets should accept datasets +that implement these protocols, rather than requiring the specific +PyArrow classes. +""" +from abc import abstractmethod +from typing import Iterator, List, Optional, Protocol + +from pyarrow.dataset import Expression +from pyarrow import Table, IntegerArray, RecordBatch, RecordBatchReader, Schema + + +class Scanner(Protocol): + @abstractmethod + def count_rows(self) -> int: + ... + + @abstractmethod + def head(self, num_rows: int) -> Table: + ... + + @abstractmethod + def take(self, indices: IntegerArray) -> Table: + ... + + @abstractmethod + def to_table(self) -> Table: + ... + + @abstractmethod + def to_batches(self) -> Iterator[RecordBatch]: + ... + + @abstractmethod + def to_reader(self) -> RecordBatchReader: + ... + + +class Scannable(Protocol): + @abstractmethod + def scanner(self, columns: Optional[List[str]] = None, + filter: Optional[Expression] = None, **kwargs) -> Scanner: Review Comment: You could potentially consider using Substrait's extended expression instead of pyarrow expressions. This could remove the pyarrow dependency entirely and frame this in terms of Substrait and the C stream interface. For those that want to use pyarrow expressions then https://github.com/apache/arrow/pull/34834 should make that pretty straightforward. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
