Skip to content

Commit 16eef5d

Browse files
committed
Fixed invalid DAX query in LoadColumnStatistics with low columnBatchSize
Fixed an issue where a low columnBatchSize could generate an invalid DAX query during column statistics analysis, due to filters applied to the RowNumber and GroupByColumn properties.
1 parent f8ae1f1 commit 16eef5d

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/Dax.Model.Extractor/StatExtractor.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ private void LoadColumnStatistics(bool analyzeDirectQuery, DirectLakeExtractionM
257257
// skip direct query tables if the analyzeDirectQuery is false
258258
where t.Columns.Count > 1 && (analyzeDirectQuery || !t.HasDirectQueryPartitions)
259259
from c in t.Columns
260-
where c.State == "Ready"
260+
where c.State == "Ready" && !c.IsRowNumber && c.GroupByColumns.Count == 0
261261
// only include the column if the table does not have Direct Lake partitions or if they are resident or if analyzeDirectLake is true
262262
&& (!t.HasDirectLakePartitions
263263
|| (analyzeDirectLake >= DirectLakeExtractionMode.ResidentOnly && c.IsResident)
@@ -269,14 +269,12 @@ from c in t.Columns
269269
foreach ( var columnSet in loopColumns ) {
270270
var idString = 0;
271271
var dax = "EVALUATE ";
272-
int validColumns = columnSet.Where(c => !c.IsRowNumber).Count();
273272
//only union if there is more than 1 column in the columnSet
274-
if (validColumns > 1) { dax += "UNION("; }
273+
if (columnSet.Count > 1) { dax += "UNION("; }
275274
dax += string.Join(",", columnSet
276-
.Where(c => !c.IsRowNumber && c.GroupByColumns.Count == 0 )
277275
.Select(c => $"\n ROW(\"Table\", \"{idString++:0000}{EmbedNameInString(c.Table.TableName.Name)}\", \"Column\", \"{idString++:0000}{EmbedNameInString(c.ColumnName.Name)}\", \"Cardinality\", {DistinctCountExpression(c)})").ToList());
278276
//only close the union call if there is more than 1 column in the columnSet
279-
if (validColumns > 1) { dax += ")"; }
277+
if (columnSet.Count > 1) { dax += ")"; }
280278

281279
var cmd = CreateCommand(dax);
282280
cmd.CommandTimeout = CommandTimeout;

0 commit comments

Comments
 (0)