Training
Module
Use built-in functions and GROUP BY in Transact-SQL - Training
Use built-in functions and GROUP BY in Transact-SQL
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
BinaryFormat.Group(binaryFormat as function, group as list, optional extra as nullable function, optional lastKey as any) as function
The parameters are as follows:
binaryFormat
parameter specifies the binary format of the key value.group
parameter provides information about the group of known items.extra
parameter can be used to specify a function that will return a binary format value for the value following any key that was unexpected. If the extra
parameter is not specified, then an error will be raised if there are unexpected key values.The group
parameter specifies a list of item definitions. Each item definition is a list, containing 3-5 values, as follows:
The following assumes a key value that is a single byte, with 4 expected items in the group, all of which have a byte of data following the key. The items appear in the input as follows:
Usage
let
b = #binary({
1, 11,
2, 22,
2, 22,
5, 55,
1, 11
}),
f = BinaryFormat.Group(
BinaryFormat.Byte,
{
{1, BinaryFormat.Byte, BinaryOccurrence.Required},
{2, BinaryFormat.Byte, BinaryOccurrence.Repeating},
{3, BinaryFormat.Byte, BinaryOccurrence.Optional},
{4, BinaryFormat.Byte, BinaryOccurrence.Repeating}
},
(extra) => BinaryFormat.Byte
)
in
f(b)
Output
{11, {22, 22}, null, {}}
The following example illustrates the item value transform and default item value. The repeating item with key 1 sums the list of values read using List.Sum. The optional item with key 2 has a default value of 123 instead of null.
Usage
let
b = #binary({
1, 101,
1, 102
}),
f = BinaryFormat.Group(
BinaryFormat.Byte,
{
{1, BinaryFormat.Byte, BinaryOccurrence.Repeating,
0, (list) => List.Sum(list)},
{2, BinaryFormat.Byte, BinaryOccurrence.Optional, 123}
}
)
in
f(b)
Output
{203, 123}
Training
Module
Use built-in functions and GROUP BY in Transact-SQL - Training
Use built-in functions and GROUP BY in Transact-SQL