-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Project skips scan if the filter covers all the columns (#117)
- Loading branch information
Showing
8 changed files
with
163 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2022 Lance Authors | ||
// | ||
// Licensed 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. | ||
|
||
#include "lance/io/project.h" | ||
|
||
#include <arrow/compute/exec/expression.h> | ||
#include <arrow/dataset/dataset.h> | ||
#include <arrow/table.h> | ||
#include <arrow/type.h> | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "lance/arrow/scanner.h" | ||
#include "lance/arrow/stl.h" | ||
#include "lance/format/schema.h" | ||
#include "lance/io/filter.h" | ||
#include "lance/io/limit.h" | ||
#include "lance/io/reader.h" | ||
#include "lance/testing/io.h" | ||
|
||
TEST_CASE("Project schema") { | ||
auto schema = | ||
::arrow::schema({arrow::field("k", arrow::int16()), arrow::field("v", arrow::int32())}); | ||
auto arr = arrow::StructArray::Make(::arrow::ArrayVector({ | ||
lance::arrow::ToArray<int16_t>({1, 2, 3, 4}).ValueOrDie(), | ||
lance::arrow::ToArray<int32_t>({10, 20, 30, 40}).ValueOrDie(), | ||
}), | ||
std::vector<std::string>({"k", "v"})) | ||
.ValueOrDie(); | ||
auto tbl = | ||
arrow::Table::FromRecordBatches({arrow::RecordBatch::FromStructArray(arr).ValueOrDie()}) | ||
.ValueOrDie(); | ||
auto dataset = std::make_shared<arrow::dataset::InMemoryDataset>(tbl); | ||
|
||
auto scan_builder = lance::arrow::ScannerBuilder(dataset); | ||
scan_builder.Project({"v"}); | ||
scan_builder.Filter( | ||
arrow::compute::equal(arrow::compute::field_ref("v"), arrow::compute::literal(20))); | ||
auto scanner = scan_builder.Finish().ValueOrDie(); | ||
|
||
auto lance_schema = lance::format::Schema(schema); | ||
auto project = lance::io::Project::Make(lance_schema, scanner->options()).ValueOrDie(); | ||
|
||
auto reader = lance::testing::MakeReader(tbl).ValueOrDie(); | ||
auto batch = project->Execute(reader, 0).ValueOrDie(); | ||
CHECK(batch->GetColumnByName("v")->Equals(lance::arrow::ToArray({20}).ValueOrDie())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright Lance Authors | ||
# | ||
# Licensed 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. | ||
|
||
add_library( | ||
lance_testing | ||
OBJECT | ||
io.cc | ||
io.h | ||
) | ||
target_include_directories(lance_testing SYSTEM PRIVATE ${Protobuf_INCLUDE_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2022 Lance Authors | ||
// | ||
// Licensed 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. | ||
|
||
#include "lance/testing/io.h" | ||
|
||
#include <arrow/io/api.h> | ||
#include <arrow/result.h> | ||
|
||
#include "lance/arrow/writer.h" | ||
#include "lance/io/reader.h" | ||
|
||
namespace lance::testing { | ||
|
||
::arrow::Result<std::shared_ptr<io::FileReader>> MakeReader( | ||
const std::shared_ptr<::arrow::Table>& table) { | ||
auto sink = ::arrow::io::BufferOutputStream::Create().ValueOrDie(); | ||
ARROW_RETURN_NOT_OK(lance::arrow::WriteTable(*table, sink)); | ||
auto infile = make_shared<::arrow::io::BufferReader>(sink->Finish().ValueOrDie()); | ||
auto reader = std::make_shared<io::FileReader>(infile); | ||
ARROW_RETURN_NOT_OK(reader->Open()); | ||
return reader; | ||
} | ||
|
||
} // namespace lance::testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2022 Lance Authors | ||
// | ||
// Licensed 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. | ||
|
||
#pragma once | ||
|
||
#include <arrow/result.h> | ||
#include <arrow/table.h> | ||
|
||
#include <memory> | ||
|
||
#include "lance/io/reader.h" | ||
|
||
namespace lance::testing { | ||
|
||
/// Make lance::io::FileReader from an Arrow Table. | ||
::arrow::Result<std::shared_ptr<lance::io::FileReader>> MakeReader( | ||
const std::shared_ptr<::arrow::Table>& table); | ||
|
||
} // namespace lance::testing |