packages/perspective/src/cpp/sparse_tree.cpp
// can contain additional rows
// notably pivot changed rows will be added
can contain additional rows
notably pivot changed rows will be added
can contain additional rows notably pivot changed rows will be added
std::pair<t_table_sptr, t_table_sptr>
t_stree::build_strand_table(const t_table& flattened,
                            const t_aggspecvec& aggspecs,
                            const t_config& config) const
{
    PSP_TRACE_SENTINEL();
    PSP_VERBOSE_ASSERT(m_init, "touching uninited object");
    auto rv = build_strand_table_common(flattened, aggspecs, config);
    t_table_sptr strands =
        std::make_shared<t_table>(rv.m_strand_schema);
    strands->init();
    t_table_sptr aggs = std::make_shared<t_table>(rv.m_aggschema);
    aggs->init();
    t_col_csptr pkey_col = flattened.get_const_column("psp_pkey");
    t_col_csptr op_col = flattened.get_const_column("psp_op");
    t_uindex npivotlike = rv.m_npivotlike;
    t_colcptrvec piv_fcols(npivotlike);
    t_colptrvec piv_scols(npivotlike);
    t_uindex insert_count = 0;
    for (t_uindex pidx = 0; pidx < npivotlike; ++pidx)
    {
        const t_str& piv = rv.m_strand_schema.m_columns[pidx];
        piv_fcols[pidx] = flattened.get_const_column(piv).get();
        piv_scols[pidx] = strands->get_column(piv).get();
    }
    t_uindex aggcolsize = rv.m_aggschema.m_columns.size();
    t_colcptrvec agg_fcols(aggcolsize);
    t_colptrvec agg_acols(aggcolsize);
    t_uindex strand_count_idx = 0;
    for (t_uindex aggidx = 0; aggidx < aggcolsize; ++aggidx)
    {
        const t_str& aggcol = rv.m_aggschema.m_columns[aggidx];
        if (aggcol == "psp_strand_count")
        {
            agg_fcols[aggidx] = 0;
            strand_count_idx = aggidx;
        }
        else
        {
            agg_fcols[aggidx] =
                flattened.get_const_column(aggcol).get();
        }
        agg_acols[aggidx] = aggs->get_column(aggcol).get();
    }
    t_column* agg_scount = aggs->get_column("psp_strand_count").get();
    t_column* spkey = strands->get_column("psp_pkey").get();
    t_mask msk;
    if (config.has_filters())
    {
        msk = filter_table_for_config(flattened, config);
    }
    t_bool has_filters = config.has_filters();
    for (t_uindex idx = 0, loop_end = flattened.size();
         idx < loop_end;
         ++idx)
    {
        t_bool filter = !has_filters || msk.get(idx);
        t_tscalar pkey = pkey_col->get_scalar(idx);
        t_uint8 op_ = *(op_col->get_nth<t_uint8>(idx));
        t_op op = static_cast<t_op>(op_);
        if (!filter || op == OP_DELETE)
        {
            continue;
        }
        for (t_uindex pidx = 0,
                      ploop_end = rv.m_pivot_like_columns.size();
             pidx < ploop_end;
             ++pidx)
        {
            piv_scols[pidx]->push_back(
                piv_fcols[pidx]->get_scalar(idx));
        }
        for (t_uindex aggidx = 0; aggidx < aggcolsize; ++aggidx)
        {
            if (aggidx != strand_count_idx)
            {
                agg_acols[aggidx]->push_back(
                    agg_fcols[aggidx]->get_scalar(idx));
            }
        }
        agg_scount->push_back<t_int8>(1);
        spkey->push_back(pkey);
        ++insert_count;
    }
    strands->reserve(insert_count);
    strands->set_size(insert_count);
    aggs->reserve(insert_count);
    aggs->set_size(insert_count);
    agg_scount->valid_raw_fill(true);
    return std::pair<t_table_sptr, t_table_sptr>(strands, aggs);
}
std :: pair < t_table_sptr , t_table_sptr > t_stree :: build_strand_table ( const t_table & flattened , const t_aggspecvec & aggspecs , const t_config & config ) const { PSP_TRACE_SENTINEL ( ) ; PSP_VERBOSE_ASSERT ( m_init , " " ) ; auto rv = build_strand_table_common ( flattened , aggspecs , config ) ; t_table_sptr strands = std :: make_shared < t_table > ( rv . m_strand_schema ) ; strands -> init ( ) ; t_table_sptr aggs = std :: make_shared < t_table > ( rv . m_aggschema ) ; aggs -> init ( ) ; t_col_csptr pkey_col = flattened . get_const_column ( " " ) ; t_col_csptr op_col = flattened . get_const_column ( " " ) ; t_uindex npivotlike = rv . m_npivotlike ; t_colcptrvec piv_fcols ( npivotlike ) ; t_colptrvec piv_scols ( npivotlike ) ; t_uindex insert_count = 0 ; for ( t_uindex pidx = 0 ; pidx < npivotlike ; ++ pidx ) { const t_str & piv = rv . m_strand_schema . m_columns [ pidx ] ; piv_fcols [ pidx ] = flattened . get_const_column ( piv ) . get ( ) ; piv_scols [ pidx ] = strands -> get_column ( piv ) . get ( ) ; } t_uindex aggcolsize = rv . m_aggschema . m_columns . size ( ) ; t_colcptrvec agg_fcols ( aggcolsize ) ; t_colptrvec agg_acols ( aggcolsize ) ; t_uindex strand_count_idx = 0 ; for ( t_uindex aggidx = 0 ; aggidx < aggcolsize ; ++ aggidx ) { const t_str & aggcol = rv . m_aggschema . m_columns [ aggidx ] ; if ( aggcol == " " ) { agg_fcols [ aggidx ] = 0 ; strand_count_idx = aggidx ; } else { agg_fcols [ aggidx ] = flattened . get_const_column ( aggcol ) . get ( ) ; } agg_acols [ aggidx ] = aggs -> get_column ( aggcol ) . get ( ) ; } t_column * agg_scount = aggs -> get_column ( " " ) . get ( ) ; t_column * spkey = strands -> get_column ( " " ) . get ( ) ; t_mask msk ; if ( config . has_filters ( ) ) { msk = filter_table_for_config ( flattened , config ) ; } t_bool has_filters = config . has_filters ( ) ; for ( t_uindex idx = 0 , loop_end = flattened . size ( ) ; idx < loop_end ; ++ idx ) { t_bool filter = ! has_filters || msk . get ( idx ) ; t_tscalar pkey = pkey_col -> get_scalar ( idx ) ; t_uint8 op_ = * ( op_col -> get_nth < t_uint8 > ( idx ) ) ; t_op op = static_cast < t_op > ( op_ ) ; if ( ! filter || op == OP_DELETE ) { continue ; } for ( t_uindex pidx = 0 , ploop_end = rv . m_pivot_like_columns . size ( ) ; pidx < ploop_end ; ++ pidx ) { piv_scols [ pidx ] -> push_back ( piv_fcols [ pidx ] -> get_scalar ( idx ) ) ; } for ( t_uindex aggidx = 0 ; aggidx < aggcolsize ; ++ aggidx ) { if ( aggidx != strand_count_idx ) { agg_acols [ aggidx ] -> push_back ( agg_fcols [ aggidx ] -> get_scalar ( idx ) ) ; } } agg_scount -> push_back < t_int8 > ( 1 ) ; spkey -> push_back ( pkey ) ; ++ insert_count ; } strands -> reserve ( insert_count ) ; strands -> set_size ( insert_count ) ; aggs -> reserve ( insert_count ) ; aggs -> set_size ( insert_count ) ; agg_scount -> valid_raw_fill ( true ) ; return std :: pair < t_table_sptr , t_table_sptr > ( strands , aggs ) ; }
can contain additional rows
notably pivot changed rows will be added
can contain additional rows notably pivot changed rows will be added
// strand table // strand table // nothing to do