Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/paimon/common/predicate/and.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.
*/

#include "paimon/common/predicate/and.h"

#include "paimon/common/predicate/or.h"

namespace paimon {

const CompoundFunction& And::Negate() const {
return Or::Instance();
}

} // namespace paimon
116 changes: 116 additions & 0 deletions src/paimon/common/predicate/and.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* 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.
*/

#pragma once

#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "arrow/array/array_base.h"
#include "fmt/format.h"
#include "paimon/common/predicate/compound_function.h"
#include "paimon/common/predicate/predicate_filter.h"
#include "paimon/predicate/predicate.h"
#include "paimon/result.h"
#include "paimon/status.h"

namespace arrow {
class Schema;
} // namespace arrow

namespace paimon {
class InternalArray;
class InternalRow;

/// A `CompoundFunction` to eval and.
class And : public CompoundFunction {
public:
static const And& Instance() {
static const And instance = And();
return instance;
}

Result<std::vector<char>> Test(
const arrow::Array& array,
const std::vector<std::shared_ptr<Predicate>>& children) const override {
std::vector<char> is_valid(array.length(), true);
for (const auto& child : children) {
auto child_filter = std::dynamic_pointer_cast<PredicateFilter>(child);
if (!child_filter) {
return Status::Invalid(
fmt::format("child filter {} does not support Test", child->ToString()));
}
PAIMON_ASSIGN_OR_RAISE(std::vector<char> child_valid, child_filter->Test(array));
for (size_t i = 0; i < is_valid.size(); i++) {
is_valid[i] = (is_valid[i] & child_valid[i]);
}
}
return is_valid;
}

Result<bool> Test(const std::shared_ptr<arrow::Schema>& schema, const InternalRow& row,
const std::vector<std::shared_ptr<Predicate>>& children) const override {
for (const auto& child : children) {
auto child_filter = std::dynamic_pointer_cast<PredicateFilter>(child);
if (!child_filter) {
return Status::Invalid(
fmt::format("child filter {} does not support Test", child->ToString()));
}
PAIMON_ASSIGN_OR_RAISE(bool is_valid, child_filter->Test(schema, row));
if (!is_valid) {
return false;
}
}
return true;
}

Result<bool> Test(const std::shared_ptr<arrow::Schema>& schema, int64_t row_count,
const InternalRow& min_values, const InternalRow& max_values,
const InternalArray& null_counts,
const std::vector<std::shared_ptr<Predicate>>& children) const override {
for (const auto& child : children) {
auto child_filter = std::dynamic_pointer_cast<PredicateFilter>(child);
if (!child_filter) {
return Status::Invalid(
fmt::format("child filter {} does not support Test", child->ToString()));
}
PAIMON_ASSIGN_OR_RAISE(bool is_valid, child_filter->Test(schema, row_count, min_values,
max_values, null_counts));
if (!is_valid) {
return false;
}
}
return true;
}

Type GetType() const override {
return Type::AND;
}
const CompoundFunction& Negate() const override;
std::string ToString() const override {
return "And";
}

private:
And() = default;
};
} // namespace paimon
26 changes: 26 additions & 0 deletions src/paimon/common/predicate/contains.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.
*/

#include "paimon/common/predicate/contains.h"

namespace paimon {

Result<bool> Contains::TestString(const std::string& field, const std::string& pattern) const {
return field.find(pattern) != std::string::npos;
}
} // namespace paimon
48 changes: 48 additions & 0 deletions src/paimon/common/predicate/contains.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.
*/

#pragma once

#include <string>

#include "paimon/common/predicate/string_leaf_binary_function.h"
#include "paimon/result.h"

namespace paimon {
/// A `StringLeafBinaryFunction` to eval filter like '%abc%'.
class Contains : public StringLeafBinaryFunction {
public:
static const Contains& Instance() {
static const Contains instance = Contains();
return instance;
}

Type GetType() const override {
return Type::CONTAINS;
}

std::string ToString() const override {
return "Contains";
}

Result<bool> TestString(const std::string& field, const std::string& pattern) const override;

private:
Contains() = default;
};
} // namespace paimon
28 changes: 28 additions & 0 deletions src/paimon/common/predicate/ends_with.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.
*/

#include "paimon/common/predicate/ends_with.h"

#include "paimon/common/utils/string_utils.h"

namespace paimon {

Result<bool> EndsWith::TestString(const std::string& field, const std::string& pattern) const {
return StringUtils::EndsWith(field, pattern);
}
} // namespace paimon
48 changes: 48 additions & 0 deletions src/paimon/common/predicate/ends_with.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.
*/

#pragma once

#include <string>

#include "paimon/common/predicate/string_leaf_binary_function.h"
#include "paimon/result.h"

namespace paimon {
/// A `StringLeafBinaryFunction` to eval filter like '%abc' or filter like '_abc'.
class EndsWith : public StringLeafBinaryFunction {
public:
static const EndsWith& Instance() {
static const EndsWith instance = EndsWith();
return instance;
}

Type GetType() const override {
return Type::ENDS_WITH;
}

std::string ToString() const override {
return "EndsWith";
}

Result<bool> TestString(const std::string& field, const std::string& pattern) const override;

private:
EndsWith() = default;
};
} // namespace paimon
30 changes: 30 additions & 0 deletions src/paimon/common/predicate/equal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.
*/

#include "paimon/common/predicate/equal.h"

#include "paimon/common/predicate/not_equal.h"

namespace paimon {
class LeafFunction;

const LeafFunction* Equal::Negate() const {
return &NotEqual::Instance();
}

} // namespace paimon
66 changes: 66 additions & 0 deletions src/paimon/common/predicate/equal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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.
*/

#pragma once

#include <cstdint>
#include <optional>
#include <string>
#include <utility>

#include "paimon/common/predicate/null_false_leaf_binary_function.h"
#include "paimon/predicate/literal.h"
#include "paimon/result.h"

namespace paimon {
class LeafFunction;

/// A `NullFalseLeafBinaryFunction` to eval equal.
class Equal : public NullFalseLeafBinaryFunction {
public:
static const Equal& Instance() {
static const Equal instance = Equal();
return instance;
}

Result<bool> Test(const Literal& field, const Literal& literal) const override {
PAIMON_ASSIGN_OR_RAISE(int32_t compare_res, field.CompareTo(literal));
return compare_res == 0;
}

Result<bool> Test(int64_t row_count, const Literal& min_value, const Literal& max_value,
const std::optional<int64_t>& null_count,
const Literal& literal) const override {
PAIMON_ASSIGN_OR_RAISE(int32_t min_res, literal.CompareTo(min_value));
PAIMON_ASSIGN_OR_RAISE(int32_t max_res, literal.CompareTo(max_value));
return min_res >= 0 && max_res <= 0;
}

Type GetType() const override {
return Type::EQUAL;
}
const LeafFunction* Negate() const override;
std::string ToString() const override {
return "Equal";
}

private:
Equal() = default;
};

} // namespace paimon
Loading