Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend column statistics analysis to include columns with GroupByColumns #141

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Dax.Model.Extractor/StatExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,10 @@ private static string EscapeTableName(Table table)

private static string DistinctCountExpression(Column column)
{
return column.GroupByColumns.Count == 0
? $"DISTINCTCOUNT({EscapeColumnName(column)})"
: $"COUNTROWS(ALLNOBLANKROW({EscapeColumnName(column)}))";
// We always use COUNTROWS(ALLNOBLANKROW(t[c])) instead of DISTINCTCOUNT(t[c]) because it is compatible with GroupByColumns settings, such as Fields Parameters.
// COUNTROWS(ALLNOBLANKROW()) always reads the list of values from the attribute hierarchy (when AvailableInMDX=true) or queries the table if the hierarchy is not available (when AvailableInMDX=false)

return $"COUNTROWS(ALLNOBLANKROW({EscapeColumnName(column)}))";
}

private static string EscapeColumnName(Column column)
Expand All @@ -257,7 +258,7 @@ private void LoadColumnStatistics(bool analyzeDirectQuery, DirectLakeExtractionM
// skip direct query tables if the analyzeDirectQuery is false
where t.Columns.Count > 1 && (analyzeDirectQuery || !t.HasDirectQueryPartitions)
from c in t.Columns
where c.State == "Ready" && !c.IsRowNumber && c.GroupByColumns.Count == 0
where c.State == "Ready" && !c.IsRowNumber
// only include the column if the table does not have Direct Lake partitions or if they are resident or if analyzeDirectLake is true
&& (!t.HasDirectLakePartitions
|| (analyzeDirectLake >= DirectLakeExtractionMode.ResidentOnly && c.IsResident)
Expand Down