wengh commented on code in PR #49961: URL: https://github.com/apache/spark/pull/49961#discussion_r1974189026
########## python/pyspark/sql/tests/test_python_datasource.py: ########## @@ -246,6 +248,137 @@ def reader(self, schema) -> "DataSourceReader": assertDataFrameEqual(df, [Row(x=0, y="0"), Row(x=1, y="1")]) self.assertEqual(df.select(spark_partition_id()).distinct().count(), 2) + def test_filter_pushdown(self): + class TestDataSourceReader(DataSourceReader): + def __init__(self): + self.has_filter = False + + def pushdownFilters(self, filters: List[Filter]) -> Iterable[Filter]: + assert set(filters) == { + EqualTo(("x",), 1), + EqualTo(("y",), 2), + }, filters + self.has_filter = True + # pretend we support x = 1 filter but in fact we don't + # so we only return y = 2 filter + yield filters[filters.index(EqualTo(("y",), 2))] + + def partitions(self): + assert self.has_filter + return super().partitions() + + def read(self, partition): + assert self.has_filter + yield [1, 1] + yield [1, 2] + yield [2, 2] + + class TestDataSource(DataSource): + @classmethod + def name(cls): + return "test" + + def schema(self): + return "x int, y int" + + def reader(self, schema) -> "DataSourceReader": + return TestDataSourceReader() + + self.spark.dataSource.register(TestDataSource) + df = self.spark.read.format("test").load().filter("x = 1 and y = 2") Review Comment: We should also include metadata such as PushedFilters in the description of PythonScan, like what FileScan does. -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org