|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +import pyarrow as pa |
| 19 | +import pytest |
| 20 | +from datafusion import ExecutionContext |
| 21 | +from datafusion import functions as f |
| 22 | + |
| 23 | + |
| 24 | +@pytest.fixture |
| 25 | +def df(): |
| 26 | + ctx = ExecutionContext() |
| 27 | + |
| 28 | + # create a RecordBatch and a new DataFrame from it |
| 29 | + batch = pa.RecordBatch.from_arrays( |
| 30 | + [pa.array(["Hello", "World", "!"]), pa.array([4, 5, 6])], |
| 31 | + names=["a", "b"], |
| 32 | + ) |
| 33 | + |
| 34 | + return ctx.create_dataframe([[batch]]) |
| 35 | + |
| 36 | + |
| 37 | +def test_string_functions(df): |
| 38 | + df = df.select(f.md5(f.col("a")), f.lower(f.col("a"))) |
| 39 | + result = df.collect() |
| 40 | + assert len(result) == 1 |
| 41 | + result = result[0] |
| 42 | + assert result.column(0) == pa.array( |
| 43 | + [ |
| 44 | + "8b1a9953c4611296a827abf8c47804d7", |
| 45 | + "f5a7924e621e84c9280a9a27e1bcb7f6", |
| 46 | + "9033e0e305f247c0c3c80d0c7848c8b3", |
| 47 | + ] |
| 48 | + ) |
| 49 | + assert result.column(1) == pa.array( |
| 50 | + [ |
| 51 | + "hello", |
| 52 | + "world", |
| 53 | + "!", |
| 54 | + ] |
| 55 | + ) |
0 commit comments