HappenLee commented on code in PR #30926:
URL: https://github.com/apache/doris/pull/30926#discussion_r1482134404


##########
be/src/vec/aggregate_functions/aggregate_function_window.h:
##########
@@ -174,6 +175,62 @@ class WindowFunctionDenseRank final
     void deserialize(AggregateDataPtr place, BufferReadable& buf, Arena*) 
const override {}
 };
 
+struct PercentRankData {
+    int64_t rank = 0;
+    int64_t count = 0;
+    int64_t peer_group_start = 0;
+    int64_t partition_size = 0;
+};
+
+class WindowFunctionPercentRank final
+        : public IAggregateFunctionDataHelper<PercentRankData, 
WindowFunctionPercentRank> {
+private:
+    inline static double _cal_percent(int64 rank, int64 total_rows) {
+        return total_rows <= 1 ? 0.0 : (rank - 1) * 1.0 / (total_rows - 1);
+    }
+
+public:
+    WindowFunctionPercentRank(const DataTypes& argument_types_)
+            : IAggregateFunctionDataHelper(argument_types_) {}
+
+    String get_name() const override { return "percent_rank"; }
+
+    DataTypePtr get_return_type() const override { return 
std::make_shared<DataTypeFloat64>(); }
+
+    void add(AggregateDataPtr place, const IColumn**, size_t, Arena*) const 
override {}
+
+    void add_range_single_place(int64_t partition_start, int64_t 
partition_end, int64_t frame_start,
+                                int64_t frame_end, AggregateDataPtr place, 
const IColumn** columns,
+                                Arena* arena) const override {
+        int64_t peer_group_count = frame_end - frame_start;
+        if (WindowFunctionPercentRank::data(place).peer_group_start != 
frame_start) {
+            WindowFunctionPercentRank::data(place).peer_group_start = 
frame_start;
+            WindowFunctionPercentRank::data(place).rank +=
+                    WindowFunctionPercentRank::data(place).count;
+        }
+        WindowFunctionPercentRank::data(place).count = peer_group_count;
+        // some variables are partition related, but there is no chance to 
init them
+        // when the new partition arrives, so we calculate them evey time now.

Review Comment:
   `every time`



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to