@@ -505,3 +505,64 @@ def test_late_materialization(test_dataset, benchmark, use_index):
505505 filter = f"{ column } = 0" ,
506506 batch_size = 32 ,
507507 )
508+
509+
510+ @pytest .fixture (scope = "module" )
511+ def test_geo_dataset (tmpdir_factory ):
512+ from geoarrow .rust .core import (
513+ point ,
514+ points ,
515+ )
516+
517+ num_rows = 1_000_000
518+ points_2d = points (
519+ [np .random .randn (num_rows ) * 100 , np .random .randn (num_rows ) * 100 ]
520+ )
521+
522+ schema = pa .schema (
523+ [
524+ pa .field (point ("xy" )).with_name ("points" ),
525+ ]
526+ )
527+ table = pa .Table .from_arrays ([points_2d ], schema = schema )
528+ uri = str (tmpdir_factory .mktemp ("test_geo_dataset" ))
529+ lance .write_dataset (table , uri )
530+ ds = lance .dataset (uri )
531+ return ds
532+
533+
534+ @pytest .mark .benchmark (group = "geo" )
535+ @pytest .mark .parametrize (
536+ "use_index" ,
537+ (False , True ),
538+ ids = ["no_index" , "with_index" ],
539+ )
540+ def test_geo_rtree (test_geo_dataset , benchmark , use_index ):
541+ if use_index :
542+ test_geo_dataset .create_scalar_index (
543+ column = "points" ,
544+ index_type = "RTREE" ,
545+ replace = True ,
546+ )
547+
548+ print (
549+ test_geo_dataset .scanner (
550+ columns = ["points" ],
551+ filter = """
552+ St_Contains(points,
553+ ST_GeomFromText('POLYGON (( 0 0, 2 0, 0 2, 2 2, 0 0 ))'))
554+ """ ,
555+ batch_size = 32 ,
556+ use_scalar_index = use_index ,
557+ ).explain_plan (True )
558+ )
559+ benchmark (
560+ test_geo_dataset .to_table ,
561+ columns = ["points" ],
562+ filter = """
563+ St_Contains(points,
564+ ST_GeomFromText('POLYGON (( 0 0, 2 0, 0 2, 2 2, 0 0 ))'))
565+ """ ,
566+ batch_size = 32 ,
567+ use_scalar_index = use_index ,
568+ )
0 commit comments