Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 10 additions & 2 deletions docs/source/api/file_index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ Interface
:members:
:undoc-members:

.. doxygenclass:: paimon::FileIndexResult
.. doxygentypedef:: paimon::FileIndexResult

.. doxygenclass:: paimon::IndexResult
:members:
:undoc-members:

.. doxygentypedef:: paimon::BitmapIndexResult

.. doxygenclass:: paimon::BitmapResult
:members:
:undoc-members:

.. doxygenclass:: paimon::BitmapIndexResult
.. doxygenclass:: paimon::ScoredIndexResult
:members:
:undoc-members:
2 changes: 2 additions & 0 deletions docs/source/user_guide/file_index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ exact matching row positions within that file.
within the candidates used for that evaluation. ``Remain`` is not exact, while
``Skip`` is exact. A bitmap alone does not imply exactness. Combining different
predicates preserves an exact guarantee only when justified by both results.
Scalar index results never omit matches, but inexact results may contain false

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document that Bitmap and BSI only prune null checks on nanosecond timestamp columns. Value predicates now retain every candidate even when the query literal is microsecond-aligned. IS NULL and IS NOT NULL still use the index. This affects existing tables and belongs alongside the scalar-index guarantees so users can explain why these filters fall back to reading data.

positives.

For a root full-text or vector TopK request, predicate filtering, row-range
restrictions and deletion vectors are applied before the TopK limit. Filtering after
Expand Down
63 changes: 0 additions & 63 deletions include/paimon/file_index/bitmap_index_result.h

This file was deleted.

3 changes: 2 additions & 1 deletion include/paimon/file_index/file_index_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <vector>

#include "paimon/file_index/file_index_result.h"
#include "paimon/file_index/scored_file_index_result.h"
#include "paimon/index/index_reader_capabilities.h"
#include "paimon/predicate/full_text_search.h"
#include "paimon/predicate/function_visitor.h"
Expand All @@ -46,8 +45,10 @@ struct FullTextMatch;
/// including when no rows match.
///
/// Readers set FileIndexResult::IsExact() when creating each result; callers use that guarantee.
/// Scalar results may contain false positives but must not omit matching rows.
/// @note Callers of `Visit*` for DECIMAL fields must ensure each literal's scale matches the scale
/// of the indexed data; otherwise, index filtering results may be incorrect.
/// TIMESTAMP literals must match the indexed field's precision.
class PAIMON_EXPORT FileIndexReader : public IndexReaderCapabilities,
public FunctionVisitor<std::shared_ptr<FileIndexResult>> {
public:
Expand Down
78 changes: 9 additions & 69 deletions include/paimon/file_index/file_index_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,77 +18,17 @@

#pragma once

#include <cstdint>
#include <memory>
#include <string>

#include "paimon/defs.h"
#include "paimon/result.h"
#include "paimon/visibility.h"
#include "paimon/index/bitmap_result.h"
#include "paimon/index/index_result.h"
#include "paimon/index/scored_index_result.h"
#include "paimon/utils/roaring_bitmap32.h"

namespace paimon {
/// File index result to decide whether filter a file.
class PAIMON_EXPORT FileIndexResult : public std::enable_shared_from_this<FileIndexResult> {
public:
virtual ~FileIndexResult() = default;

/// @return A shared instance representing "retain the file".
/// @note This is a singleton-like utility; all calls return equivalent objects.
static std::shared_ptr<FileIndexResult> Remain();

/// @return A shared instance representing "skip the file".
/// @note This is a singleton-like utility; all calls return equivalent objects.
static std::shared_ptr<FileIndexResult> Skip();

/// @return Whether the file is remained.
virtual Result<bool> IsRemain() const = 0;

/// Whether these rows exactly match the evaluated predicate within its candidate scope.
bool IsExact() const {
return is_exact_;
}

/// Compute the intersection for two predicates, conservatively propagating precision.
virtual Result<std::shared_ptr<FileIndexResult>> And(
const std::shared_ptr<FileIndexResult>& other) = 0;

/// Compute the union for two predicates, conservatively propagating precision.
virtual Result<std::shared_ptr<FileIndexResult>> Or(
const std::shared_ptr<FileIndexResult>& other) = 0;

virtual std::string ToString() const = 0;

protected:
explicit FileIndexResult(bool is_exact) : is_exact_(is_exact) {}

private:
bool is_exact_;
};

/// Concrete implementation of FileIndexResult that always retains the file.
class PAIMON_EXPORT Remain : public FileIndexResult {
public:
Remain() : FileIndexResult(false) {}

Result<bool> IsRemain() const override;
Result<std::shared_ptr<FileIndexResult>> And(
const std::shared_ptr<FileIndexResult>& other) override;
Result<std::shared_ptr<FileIndexResult>> Or(
const std::shared_ptr<FileIndexResult>& other) override;
std::string ToString() const override;
};

/// Concrete implementation of FileIndexResult that always skips the file.
class PAIMON_EXPORT Skip : public FileIndexResult {
public:
Skip() : FileIndexResult(true) {}

Result<bool> IsRemain() const override;
Result<std::shared_ptr<FileIndexResult>> And(
const std::shared_ptr<FileIndexResult>& other) override;
Result<std::shared_ptr<FileIndexResult>> Or(
const std::shared_ptr<FileIndexResult>& other) override;
std::string ToString() const override;
};
using FileIndexResult = IndexResult<RoaringBitmap32>;
using BitmapIndexResult = BitmapResult<RoaringBitmap32>;
using ScoredFileIndexResult = ScoredIndexResult<RoaringBitmap32>;
using Remain = RemainIndexResult<RoaringBitmap32>;
using Skip = SkipIndexResult<RoaringBitmap32>;

} // namespace paimon
59 changes: 59 additions & 0 deletions include/paimon/index/bitmap_result.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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 <functional>
#include <memory>
#include <string>

#include "paimon/index/index_result.h"

namespace paimon {

/// Lazily loaded row positions, shared by file and real-time index results.
template <typename Bitmap>
class PAIMON_EXPORT BitmapResult : public IndexResult<Bitmap> {
public:
using BitmapSupplier = std::function<Result<Bitmap>()>;

/// Construct a materialized result, rejecting negative row positions.
static Result<std::shared_ptr<BitmapResult<Bitmap>>> Create(Bitmap rows, bool is_exact);

explicit BitmapResult(BitmapSupplier bitmap_supplier, bool is_exact = false);

Result<bool> IsRemain() const override;

/// Load the bitmap if needed. The result owns the returned bitmap.
Result<const Bitmap*> GetBitmap() const;

Result<std::shared_ptr<IndexResult<Bitmap>>> And(
const std::shared_ptr<IndexResult<Bitmap>>& other) override;
Result<std::shared_ptr<IndexResult<Bitmap>>> Or(
const std::shared_ptr<IndexResult<Bitmap>>& other) override;
std::string ToString() const override;

private:
BitmapResult(Bitmap rows, bool is_exact);

mutable bool initialized_ = false;
BitmapSupplier bitmap_supplier_;
mutable Bitmap bitmap_;
};

} // namespace paimon
90 changes: 90 additions & 0 deletions include/paimon/index/index_result.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* 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 <memory>
#include <string>

#include "paimon/result.h"
#include "paimon/visibility.h"

namespace paimon {

/// An index result within one source, read view and candidate scope.
/// Implementations are provided for RoaringBitmap32 and RoaringBitmap64.
/// Bitmap constrains And/Or to compatible result types; this base class stores no bitmap.
/// Scalar predicate results never omit matches: exact results contain only matching rows,
/// while inexact results may contain false positives. This does not guarantee search recall.
template <typename Bitmap>
class PAIMON_EXPORT IndexResult : public std::enable_shared_from_this<IndexResult<Bitmap>> {
public:
virtual ~IndexResult() = default;

static std::shared_ptr<IndexResult<Bitmap>> Remain();
static std::shared_ptr<IndexResult<Bitmap>> Skip();

bool IsExact() const {
return is_exact_;
}

/// Whether the result retains candidates. This alone does not establish exactness.
virtual Result<bool> IsRemain() const = 0;

/// Combine different predicates over the same source, view and candidate scope.
virtual Result<std::shared_ptr<IndexResult<Bitmap>>> And(
const std::shared_ptr<IndexResult<Bitmap>>& other) = 0;
virtual Result<std::shared_ptr<IndexResult<Bitmap>>> Or(
const std::shared_ptr<IndexResult<Bitmap>>& other) = 0;

virtual std::string ToString() const = 0;

protected:
explicit IndexResult(bool is_exact) : is_exact_(is_exact) {}

private:
bool is_exact_;
};

template <typename Bitmap>
class PAIMON_EXPORT RemainIndexResult : public IndexResult<Bitmap> {
public:
RemainIndexResult() : IndexResult<Bitmap>(false) {}

Result<bool> IsRemain() const override;
Result<std::shared_ptr<IndexResult<Bitmap>>> And(
const std::shared_ptr<IndexResult<Bitmap>>& other) override;
Result<std::shared_ptr<IndexResult<Bitmap>>> Or(
const std::shared_ptr<IndexResult<Bitmap>>& other) override;
std::string ToString() const override;
};

template <typename Bitmap>
class PAIMON_EXPORT SkipIndexResult : public IndexResult<Bitmap> {
public:
SkipIndexResult() : IndexResult<Bitmap>(true) {}

Result<bool> IsRemain() const override;
Result<std::shared_ptr<IndexResult<Bitmap>>> And(
const std::shared_ptr<IndexResult<Bitmap>>& other) override;
Result<std::shared_ptr<IndexResult<Bitmap>>> Or(
const std::shared_ptr<IndexResult<Bitmap>>& other) override;
std::string ToString() const override;
};

} // namespace paimon
Loading
Loading