mirror of
https://github.com/langchain-ai/datafusion.git
synced 2026-07-21 03:05:28 -04:00
bfb3e6a8b2
Co-authored-by: Muru Muthusamy <mmuthusamy@womply.com>
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
# Licensed to the Apache Software Foundation (ASF) under one
|
|
# or more contributor license agreements. See the NOTICE file
|
|
# distributed with this work for additional information
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
# to you under the Apache License, Version 2.0 (the
|
|
# "License"); you may not use this file except in compliance
|
|
# with the License. You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing,
|
|
# software distributed under the License is distributed on an
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
# KIND, either express or implied. See the License for the
|
|
# specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import pyarrow as pa
|
|
import pytest
|
|
from datafusion import ExecutionContext
|
|
|
|
|
|
@pytest.fixture
|
|
def ctx():
|
|
return ExecutionContext()
|
|
|
|
|
|
def test_register_record_batches(ctx):
|
|
|
|
# create a RecordBatch and register it as memtable
|
|
batch = pa.RecordBatch.from_arrays(
|
|
[pa.array([1, 2, 3]), pa.array([4, 5, 6])],
|
|
names=["a", "b"],
|
|
)
|
|
|
|
ctx.register_record_batches("t", [[batch]])
|
|
|
|
assert ctx.tables() == {"t"}
|
|
|
|
result = ctx.sql("SELECT a+b, a-b FROM t").collect()
|
|
|
|
assert result[0].column(0) == pa.array([5, 7, 9])
|
|
assert result[0].column(1) == pa.array([-3, -3, -3])
|