lgbo-ustc commented on code in PR #4634:
URL: https://github.com/apache/incubator-gluten/pull/4634#discussion_r1522350915


##########
cpp-ch/local-engine/Storages/Parquet/ColumnIndexFilter.h:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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 <config.h>
+
+#if USE_PARQUET
+#include <memory>
+#include <Columns/IColumn.h>
+#include <Core/Field.h>
+#include <Interpreters/ActionsDAG.h>
+#include <Storages/Parquet/RowRanges.h>
+#include <parquet/page_index.h>
+
+namespace DB
+{
+class RPNBuilderTreeNode;
+class Context;
+using ContextPtr = std::shared_ptr<const Context>;
+}
+
+namespace local_engine
+{
+class ColumnIndex;
+using ColumnIndexPtr = std::unique_ptr<ColumnIndex>;
+using PageIndexs = std::vector<int32_t>;
+using ColumnIndexStore = std::unordered_map<std::string, ColumnIndexPtr>;
+
+struct PageIndexsBuilder
+{
+    static constexpr int32_t ALL_PAGES = -1;
+    template <typename Predict>
+    static PageIndexs filter(const size_t size, Predict predict)
+    {
+        PageIndexs pages;
+        for (int32_t from = 0; from != size; ++from)
+            if (predict(from))
+                pages.emplace_back(from);
+        return pages;
+    }
+};
+
+struct RowRangesBuilder
+{
+    const int64_t rowGroupRowCount; // the total number of rows in the 
row-group
+    const std::vector<parquet::PageLocation> & pageLocations;
+
+    RowRangesBuilder(int64_t row_group_row_count, const 
std::vector<parquet::PageLocation> & page_locations)
+        : rowGroupRowCount(row_group_row_count), pageLocations(page_locations)
+    {
+    }
+
+    /**
+     * @param pageIndex
+     *           the index of the page
+     * @return the index of the first row in the page
+     */
+    size_t firstRowIndex(int pageIndex) const { return 
pageLocations[pageIndex].first_row_index; }
+
+    /**
+     * @param pageIndex
+     *          the index of the page
+     * @return the calculated index of the last row of the given page
+     */
+    size_t lastRowIndex(size_t pageIndex) const
+    {
+        const size_t nextPageIndex = pageIndex + 1;
+        const size_t pageCount = std::ssize(pageLocations);
+
+        const size_t lastRowIndex = (nextPageIndex >= pageCount ? 
rowGroupRowCount : pageLocations[nextPageIndex].first_row_index) - 1;
+        return lastRowIndex;
+    }
+
+    RowRanges all() const { return RowRanges::createSingle(rowGroupRowCount); }
+
+    RowRanges toRowRanges(const PageIndexs & pages) const
+    {
+        if (pages.size() == 1 && pages[0] == PageIndexsBuilder::ALL_PAGES)
+            return all();
+        RowRanges row_ranges;
+        std::ranges::for_each(pages, [&](size_t pageIndex) { 
row_ranges.add(Range{firstRowIndex(pageIndex), lastRowIndex(pageIndex)}); });
+        return row_ranges;
+    }
+};
+
+/**
+ * Column index containing min/max and null count values for the pages in a 
column chunk. It also implements methods
+ * to return the indexes of the matching pages.
+ *
+ * @see parquet::ColumnIndex
+ */
+class ColumnIndex
+{
+public:
+    virtual ~ColumnIndex() = default;
+
+    virtual const parquet::OffsetIndex & offsetIndex() const = 0;
+
+    virtual bool hasParquetColumnIndex() const = 0;
+
+    /// \brief Returns the row ranges where the column value is not equal to 
the given value.
+    /// column != literal => (min, max) = literal =>
+    /// min != literal || literal != max
+    virtual PageIndexs notEq(const DB::Field & value) const = 0;
+
+    /// \brief Returns the row ranges where the column value is equal to the 
given value.
+    /// column == literal => literal not in (min, max) =>
+    ///  min <= literal && literal <= max
+    virtual PageIndexs eq(const DB::Field & value) const = 0;
+
+    /// \brief Returns the row ranges where the column value is greater than 
the given value.
+    /// column > literal
+    virtual PageIndexs gt(const DB::Field & value) const = 0;
+
+    /// column >= literal
+    virtual PageIndexs gtEg(const DB::Field & value) const = 0;
+
+    /// \brief Returns the row ranges where the column value is less than the 
given value.
+    /// column < literal
+    virtual PageIndexs lt(const DB::Field & value) const = 0;
+
+    /// column <= literal
+    virtual PageIndexs ltEg(const DB::Field & value) const = 0;
+
+    virtual PageIndexs in(const DB::ColumnPtr & column) const = 0;
+
+    //TODO: parameters
+    static ColumnIndexPtr create(
+        const parquet::ColumnDescriptor * descr,
+        const std::shared_ptr<parquet::ColumnIndex> & column_index,
+        const std::shared_ptr<parquet::OffsetIndex> & offset_index);
+};
+
+template <typename DType>
+class TypedColumnIndex : public ColumnIndex
+{
+public:
+    using T = typename DType::c_type;
+};
+
+using ColumnIndexInt64 = TypedColumnIndex<parquet::Int64Type>;
+using ColumnIndexInt32 = TypedColumnIndex<parquet::Int32Type>;
+
+class ColumnIndexFilter
+{
+public:
+    /// The expression is stored as Reverse Polish Notation.
+    struct RPNElement

Review Comment:
   What does RPN mean?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to