<div dir="ltr">Tomasz-<div>I&#39;ve entered <a id="key-val" rel="98845" href="http://jira.pentaho.com/browse/MONDRIAN-1370" style="background-color:transparent;font-family:arial,FreeSans,Helvetica,sans-serif;font-size:1.167em;line-height:1.429;color:rgb(153,102,0)">MONDRIAN-1370</a> for the bug you found.  I expect it will get picked up for the next release.  Thanks for identifying this.</div>

<div><br></div><div style>Matt</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jan 8, 2013 at 5:44 PM, Matt Campbell <span dir="ltr">&lt;<a href="mailto:mkambol@gmail.com" target="_blank">mkambol@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>I see what your saying-- the aggregator selected when using the ExplicitRecognizer is different from the DefaultRecognizer.  A count distinct measure in an explicit aggregate can be incorrectly summed. </div>


<div><br></div><div>I&#39;ll discuss this with the team and get back to you.</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jan 8, 2013 at 3:24 PM, Tomasz Karlik <span dir="ltr">&lt;<a href="mailto:tkarlik@gmail.com" target="_blank">tkarlik@gmail.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I suppose that without this change Mondrian will always use aggregate<br>
table. Aggregate table column is handled by RolapAggregator.Sum, so<br>
code created to deal with different distinct count scenarios is<br>
omitted.<br>
<br>
When using rule-based recognition Mondrian uses Recognizer.java code<br>
(lines 782-792):<br>
<br>
        // NOTE: This assumes that the aggregate table does not have an explicit<br>
        // average column.<br>
        if (factAgg == RolapAggregator.Avg) {<br>
            String columnExpr = getFactCountExpr(aggUsage);<br>
            return new RolapAggregator.AvgFromSum(columnExpr);<br>
        } else if (factAgg == RolapAggregator.DistinctCount) {<br>
            //return RolapAggregator.Count;<br>
            return RolapAggregator.DistinctCount;<br>
        } else {<br>
            return factAgg;<br>
        }<br>
Are there really necessary separate methods to deal with both of<br>
recognizers? How to change schema definition, to handle distinct-count<br>
aggregated measures correctly when using explicit recognizer?<br>
<div><div><br>
<br>
On Mon, Jan 7, 2013 at 3:46 PM, Matt Campbell &lt;<a href="mailto:mkambol@gmail.com" target="_blank">mkambol@gmail.com</a>&gt; wrote:<br>
&gt; Distinct count measures in aggregate tables are tricky and require care on<br>
&gt; the part of the schema author.  There are some cases where it is appropriate<br>
&gt; to pull a distinct count value from an aggregate table--i.e. when the<br>
&gt; attributes are dependent on the measure (like gender in the case of customer<br>
&gt; count).<br>
&gt;<br>
&gt; I&#39;m hoping Julian or Luc can jump in, but I&#39;d be worried your change would<br>
&gt; cause Mondrian to always query the fact table for count distincts, even when<br>
&gt; it may be appropriate to query the agg table.<br>
&gt;<br>
&gt;<br>
&gt; On Mon, Jan 7, 2013 at 3:47 AM, Tomasz Karlik &lt;<a href="mailto:tkarlik@gmail.com" target="_blank">tkarlik@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; SQL seems to be wrong:<br>
&gt;&gt;<br>
&gt;&gt; select<br>
&gt;&gt;     &quot;agg_c_10_sales_fact_1997&quot;.&quot;the_year&quot; as &quot;c0&quot;,<br>
&gt;&gt;     sum(&quot;agg_c_10_sales_fact_1997&quot;.&quot;customer_count&quot;) as &quot;m0&quot;<br>
&gt;&gt; from<br>
&gt;&gt;     &quot;agg_c_10_sales_fact_1997&quot; as &quot;agg_c_10_sales_fact_1997&quot;<br>
&gt;&gt; where<br>
&gt;&gt;     &quot;agg_c_10_sales_fact_1997&quot;.&quot;the_year&quot; = 1997<br>
&gt;&gt; group by<br>
&gt;&gt;     &quot;agg_c_10_sales_fact_1997&quot;.&quot;the_year&quot;<br>
&gt;&gt;<br>
&gt;&gt; Log file is in attachment.<br>
&gt;&gt;<br>
&gt;&gt; On Mon, Jan 7, 2013 at 9:19 AM, Julian Hyde &lt;<a href="mailto:jhyde@pentaho.com" target="_blank">jhyde@pentaho.com</a>&gt; wrote:<br>
&gt;&gt; &gt; The easiest way to approach this is to look at the SQL Mondrian is<br>
&gt;&gt; &gt; generating. Is it asking the right question of the DBMS?<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Can you turn on SQL tracing and post the log you get during the run that<br>
&gt;&gt; &gt; produces the incorrect results.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Julian<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On Jan 7, 2013, at 12:10 AM, Tomasz Karlik &lt;<a href="mailto:tkarlik@gmail.com" target="_blank">tkarlik@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; I am getting different results while running simple query on FoodMart<br>
&gt;&gt; &gt;&gt; (PostgreSql db). Result differs and seems to be wrong when using<br>
&gt;&gt; &gt;&gt; explicit aggregate. I&#39;ve created simple test which shows this<br>
&gt;&gt; &gt;&gt; behavior. Also I&#39;ve made some patch, but i&#39;m not sure if the problem<br>
&gt;&gt; &gt;&gt; is in sources? The problem doesn&#39;t appear when aggregate table is<br>
&gt;&gt; &gt;&gt; recognized by the default rules.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; query:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; select<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; NON EMPTY {[Measures].[Customer Count]} ON COLUMNS,<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; NON EMPTY {[Time].[Year].Members} ON ROWS<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; from [Sales]<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; aggregate table: agg_c_10_sales_fact_1997<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; expected result:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Axis #0:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; {}<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Axis #1:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; {[Measures].[Customer Count]}<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Axis #2:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; {[Time].[1997]}<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Row #0: 5 581<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; actual result:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Axis #0:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; {}<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Axis #1:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; {[Measures].[Customer Count]}<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Axis #2:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; {[Time].[1997]}<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Row #0: 16 947<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &lt;ExplicitRecognizerTest.java&gt;&lt;mondrian_rolap_aggmatcher_Recognizer.java.patch&gt;_______________________________________________<br>
&gt;&gt; &gt;&gt; Mondrian mailing list<br>
&gt;&gt; &gt;&gt; <a href="mailto:Mondrian@pentaho.org" target="_blank">Mondrian@pentaho.org</a><br>
&gt;&gt; &gt;&gt; <a href="http://lists.pentaho.org/mailman/listinfo/mondrian" target="_blank">http://lists.pentaho.org/mailman/listinfo/mondrian</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; Mondrian mailing list<br>
&gt;&gt; &gt; <a href="mailto:Mondrian@pentaho.org" target="_blank">Mondrian@pentaho.org</a><br>
&gt;&gt; &gt; <a href="http://lists.pentaho.org/mailman/listinfo/mondrian" target="_blank">http://lists.pentaho.org/mailman/listinfo/mondrian</a><br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Mondrian mailing list<br>
&gt;&gt; <a href="mailto:Mondrian@pentaho.org" target="_blank">Mondrian@pentaho.org</a><br>
&gt;&gt; <a href="http://lists.pentaho.org/mailman/listinfo/mondrian" target="_blank">http://lists.pentaho.org/mailman/listinfo/mondrian</a><br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Mondrian mailing list<br>
&gt; <a href="mailto:Mondrian@pentaho.org" target="_blank">Mondrian@pentaho.org</a><br>
&gt; <a href="http://lists.pentaho.org/mailman/listinfo/mondrian" target="_blank">http://lists.pentaho.org/mailman/listinfo/mondrian</a><br>
&gt;<br>
_______________________________________________<br>
Mondrian mailing list<br>
<a href="mailto:Mondrian@pentaho.org" target="_blank">Mondrian@pentaho.org</a><br>
<a href="http://lists.pentaho.org/mailman/listinfo/mondrian" target="_blank">http://lists.pentaho.org/mailman/listinfo/mondrian</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>