@@ -190,6 +190,87 @@ t_ctx2::get_ctraversal_indices() const {
190190 return std::vector<t_index>();
191191}
192192
193+ std::pair<t_tscalar, t_tscalar>
194+ t_ctx2::get_min_max (const std::string& colname) const {
195+ t_uindex ctx_nrows = get_row_count ();
196+ t_uindex ctx_ncols = get_column_count ();
197+ auto rval = std::make_pair (mknone (), mknone ());
198+ t_uindex scol = m_trees[0 ]->get_aggtable ()->get_schema ().get_colidx (colname);
199+ std::vector<std::pair<t_uindex, t_uindex>> cells;
200+ for (t_index ridx = 0 ; ridx < ctx_nrows; ++ridx) {
201+ for (t_index cidx = 0 ; cidx < ctx_ncols; ++cidx) {
202+ cells.push_back (
203+ std::pair<t_index, t_index>(ridx, cidx));
204+ }
205+ }
206+
207+ auto cells_info = resolve_cells (cells);
208+ typedef std::pair<t_uindex, t_uindex> t_aggpair;
209+ std::map<t_aggpair, const t_column*> aggmap;
210+ auto n_aggs = m_config.get_num_aggregates ();
211+ for (t_uindex treeidx = 0 , tree_loop_end = m_trees.size (); treeidx < tree_loop_end;
212+ ++treeidx) {
213+ auto aggtable = m_trees[treeidx]->get_aggtable ();
214+ t_schema aggschema = aggtable->get_schema ();
215+ for (t_uindex aggidx = 0 , agg_loop_end = n_aggs;
216+ aggidx < agg_loop_end; ++aggidx) {
217+ const std::string& aggname = aggschema.m_columns [aggidx];
218+ aggmap[t_aggpair (treeidx, aggidx)] = aggtable->get_const_column (aggname).get ();
219+ }
220+ }
221+
222+ const std::vector<t_aggspec>& aggspecs = m_config.get_aggregates ();
223+ bool is_finished = false ;
224+ t_uindex row_depth = m_row_depth + 1 ;
225+ while (!is_finished && row_depth > 0 ) {
226+ for (std::size_t i = 0 ; i < cells_info.size (); ++i) {
227+ const t_cellinfo& cinfo = cells_info[i];
228+ if (cinfo.m_idx < 0 || cinfo.m_agg_index != scol) {
229+ continue ;
230+ } else {
231+ t_index nidx = m_rtraversal->get_tree_index (cinfo.m_ridx );
232+ if (rtree ()->get_depth (nidx) != row_depth) {
233+ continue ;
234+ }
235+
236+ auto col_depth
237+ = ctree ()->get_depth (m_ctraversal->get_tree_index (
238+ calc_translated_colidx (n_aggs, cinfo.m_cidx )));
239+ if (m_config.get_num_cpivots () != col_depth) {
240+ continue ;
241+ }
242+
243+ auto aggcol = aggmap[t_aggpair (cinfo.m_treenum , cinfo.m_agg_index )];
244+ t_index p_idx = m_trees[cinfo.m_treenum ]->get_parent_idx (cinfo.m_idx );
245+ t_uindex agg_ridx = m_trees[cinfo.m_treenum ]->get_aggidx (cinfo.m_idx );
246+ t_uindex agg_pridx = p_idx == INVALID_INDEX
247+ ? INVALID_INDEX
248+ : m_trees[cinfo.m_treenum ]->get_aggidx (p_idx);
249+
250+ auto val = extract_aggregate (
251+ aggspecs[cinfo.m_agg_index ], aggcol, agg_ridx, agg_pridx);
252+
253+ if (!val.is_valid ()) {
254+ continue ;
255+ }
256+
257+ is_finished = true ;
258+ if (rval.first .is_none () || (!val.is_none () && val < rval.first )) {
259+ rval.first = val;
260+ }
261+
262+ if (val > rval.second ) {
263+ rval.second = val;
264+ }
265+ }
266+ }
267+
268+ row_depth--;
269+ }
270+
271+ return rval;
272+ }
273+
193274std::vector<t_tscalar>
194275t_ctx2::get_data (t_index start_row, t_index end_row, t_index start_col, t_index end_col) const {
195276 t_uindex ctx_nrows = get_row_count ();
0 commit comments