| 154 | @pytest.mark.skip(reason="Gandiva C++ did not have *real* binary, " |
| 155 | "time and date support.") |
| 156 | def test_in_expr_todo(): |
| 157 | import pyarrow.gandiva as gandiva |
| 158 | # TODO: Implement reasonable support for timestamp, time & date. |
| 159 | # Current exceptions: |
| 160 | # pyarrow.lib.ArrowException: ExpressionValidationError: |
| 161 | # Evaluation expression for IN clause returns XXXX values are of typeXXXX |
| 162 | |
| 163 | # binary |
| 164 | arr = pa.array([b"ga", b"an", b"nd", b"di", b"iv", b"va"]) |
| 165 | table = pa.Table.from_arrays([arr], ["a"]) |
| 166 | |
| 167 | builder = gandiva.TreeExprBuilder() |
| 168 | node_a = builder.make_field(table.schema.field("a")) |
| 169 | cond = builder.make_in_expression(node_a, [b'an', b'nd'], pa.binary()) |
| 170 | condition = builder.make_condition(cond) |
| 171 | |
| 172 | filter = gandiva.make_filter(table.schema, condition) |
| 173 | result = filter.evaluate(table.to_batches()[0], pa.default_memory_pool()) |
| 174 | assert result.to_array().equals(pa.array([1, 2], type=pa.uint32())) |
| 175 | |
| 176 | # timestamp |
| 177 | datetime_1 = datetime.datetime.utcfromtimestamp(1542238951.621877) |
| 178 | datetime_2 = datetime.datetime.utcfromtimestamp(1542238911.621877) |
| 179 | datetime_3 = datetime.datetime.utcfromtimestamp(1542238051.621877) |
| 180 | |
| 181 | arr = pa.array([datetime_1, datetime_2, datetime_3]) |
| 182 | table = pa.Table.from_arrays([arr], ["a"]) |
| 183 | |
| 184 | builder = gandiva.TreeExprBuilder() |
| 185 | node_a = builder.make_field(table.schema.field("a")) |
| 186 | cond = builder.make_in_expression(node_a, [datetime_2], pa.timestamp('ms')) |
| 187 | condition = builder.make_condition(cond) |
| 188 | |
| 189 | filter = gandiva.make_filter(table.schema, condition) |
| 190 | result = filter.evaluate(table.to_batches()[0], pa.default_memory_pool()) |
| 191 | assert list(result.to_array()) == [1] |
| 192 | |
| 193 | # time |
| 194 | time_1 = datetime_1.time() |
| 195 | time_2 = datetime_2.time() |
| 196 | time_3 = datetime_3.time() |
| 197 | |
| 198 | arr = pa.array([time_1, time_2, time_3]) |
| 199 | table = pa.Table.from_arrays([arr], ["a"]) |
| 200 | |
| 201 | builder = gandiva.TreeExprBuilder() |
| 202 | node_a = builder.make_field(table.schema.field("a")) |
| 203 | cond = builder.make_in_expression(node_a, [time_2], pa.time64('ms')) |
| 204 | condition = builder.make_condition(cond) |
| 205 | |
| 206 | filter = gandiva.make_filter(table.schema, condition) |
| 207 | result = filter.evaluate(table.to_batches()[0], pa.default_memory_pool()) |
| 208 | assert list(result.to_array()) == [1] |
| 209 | |
| 210 | # date |
| 211 | date_1 = datetime_1.date() |
| 212 | date_2 = datetime_2.date() |
| 213 | date_3 = datetime_3.date() |