| 294 | |
| 295 | @pytest.mark.gandiva |
| 296 | def test_regex(): |
| 297 | import pyarrow.gandiva as gandiva |
| 298 | |
| 299 | elements = ["park", "sparkle", "bright spark and fire", "spark"] |
| 300 | data = pa.array(elements, type=pa.string()) |
| 301 | table = pa.Table.from_arrays([data], names=['a']) |
| 302 | |
| 303 | builder = gandiva.TreeExprBuilder() |
| 304 | node_a = builder.make_field(table.schema.field("a")) |
| 305 | regex = builder.make_literal("%spark%", pa.string()) |
| 306 | like = builder.make_function("like", [node_a, regex], pa.bool_()) |
| 307 | |
| 308 | field_result = pa.field("b", pa.bool_()) |
| 309 | expr = builder.make_expression(like, field_result) |
| 310 | |
| 311 | projector = gandiva.make_projector( |
| 312 | table.schema, [expr], pa.default_memory_pool()) |
| 313 | |
| 314 | r, = projector.evaluate(table.to_batches()[0]) |
| 315 | b = pa.array([False, True, True, True], type=pa.bool_()) |
| 316 | assert r.equals(b) |
| 317 | |
| 318 | |
| 319 | @pytest.mark.gandiva |