What steps will reproduce the problem?
call flexviews.create_mvlog('watch', 't_event_evt');
call flexviews.create('watch', 'mv_event_daily_med', 'INCREMENTAL');
set @mv_id = flexviews.get_id('watch', 'mv_event_daily_med');
call flexviews.add_table(@mv_id, 'watch', 't_event_evt', 'evt', NULL);
call flexviews.add_expr(@mv_id, 'GROUP', "date_format(evt.evt_date,
'%Y-%m-%d')", 'evt_date');
call flexviews.add_expr(@mv_id, 'GROUP', "evt.evt_source", 'evt_source');
call flexviews.add_expr(@mv_id, 'GROUP', "evt.evt_key_short", 'evt_key_short');
call flexviews.add_expr(@mv_id, 'AVG', "evt.evt_duration", 'evt_average');
call flexviews.add_expr(@mv_id, 'GROUP', "evt.evt_key", 'evt_key');
What is the expected output? What do you see instead?
When I loog @MV_DEBUG I see :
SELECT NULL as mview$pk,
(date_format(evt.evt_date, '%Y-%m-%d')) as `evt_date`,
(evt.evt_source) as `evt_source`,
(evt.evt_key_short) as `evt_key_short`,
AVG(evt.evt_duration) as `evt_average`,
SUM(evt.evt_duration) as `evt_average`_sum,
COUNT(evt.evt_duration) as `evt_average`_cnt,
(evt.evt_key) as `evt_key`,
COUNT(*) as `CNT`
FROM watch.t_event_evt as evt
GROUP BY (date_format(evt.evt_date, '%Y-%m-%d')), (evt.evt_source),
(evt.evt_key_short), (evt.evt_key) LIMIT 0
The problem is around `evt_average`_sum and `evt_average`_cnt
I should have `evt_average_cnt` and `evt_average_cnt`
When I look get_select i can see you force the `` around alias :
IF SUBSTR(v_mview_alias,1,1) != '`' THEN
SET v_mview_alias = CONCAT('`',v_mview_alias,'`');
END IF;
So when you use it there :
IF v_mview_expr_type = 'AVG' THEN
SET v_select_list = CONCAT(v_select_list, ',SUM', v_mview_expression, ' as ', v_mview_alias, '_sum' );
SET v_select_list = CONCAT(v_select_list, ',COUNT', v_mview_expression, ' as ', v_mview_alias, '_cnt' );
END IF;
Its bugged.
This is my patch :
IF v_mview_expr_type = 'AVG' THEN
SET v_select_list = CONCAT(v_select_list, ',SUM', v_mview_expression, ' as ', LEFT(v_mview_alias, LENGTH(v_mview_alias)-1), '_sum`' );
SET v_select_list = CONCAT(v_select_list, ',COUNT', v_mview_expression, ' as ', LEFT(v_mview_alias, LENGTH(v_mview_alias)-1), '_cnt`' );
END IF;
Original issue reported on code.google.com by ox...@bouh.org on 30 Sep 2011 at 10:49
Original issue reported on code.google.com by
ox...@bouh.org
on 30 Sep 2011 at 10:49