Uh oh!
There was an error while loading. Please reload this page.
Update Table.GenerateByPage to handle empty tables being returned - #484
Update Table.GenerateByPage to handle empty tables being returned#484Ben Gribaudo (bgribaudo) wants to merge 5 commits into
Conversation
We specifically can't use Table.Combine, as that will effectively break the streaming behavior for most cases. FWIW, we somehow ended up with an older implementation as the "boilerplate" for this function. A slightly newer definition -- albeit one which still doesn't fix the "empty row" problem -- looks like this: What's better about it is that when you know the table type, it avoids the duplicate request for the first page. |
Ben Gribaudo (bgribaudo)
commented
Mar 25, 2022
Curt Hagenlocher (@CurtHagenlocher), Thanks for that revised logic! I was planning to look into the effects of the first-row-get-type logic today--but the revision you provided should save me that effort. :-) Is switching from |
Without this change, `try Table.GenerateByPage(each error "bad", type table[A=any])` won't catch the `error "bad"` raised here (which simulates the first data page fetch attempt raising an error).
Ben Gribaudo (bgribaudo)
commented
May 2, 2022
Curt Hagenlocher (@CurtHagenlocher), do you like either of the last two commits ("Adjusting error propagation" or "Reverting last change to avoid triggering a row fetch")? |
brigadir13
commented
Apr 30, 2025
|
The problem with filtering each page using On the whole, I think that M doesn't have the right primitives to let this function be written generically and efficiently inside M. At one point I was looking to add this as a standard library function in C#, but that was over ten years ago and I no longer remember why I got pushback. I think when we run into a situation internally where "empty pages" is a potential issue, we're usually able to add a filter after the |
Per
Table.GenerateByPage's Helper Functions description, this method should callgetNextPageuntil that callback returns null, then will combine all returned pages into a single table.However, when the existing
Table.GenerateByPagereturns an empty table, its actual behavior differs from the above description (see below examples). If the callback returns an empty table,Table.GenerateByPagemay output 0 rows or an extra, all-null row--neither of which seems desirable or in alignment with the above description.This PR addresses these behavior anomalies. (Note: It would be good for someone with internal Power Query knowledge to validate this PR to ensure that it is done in a way that aligns with PQ's lazy paradigm and that it does not trigger extra streaming.)
Demo of Existing's Behavior Anomalies