USQL-SQL.ARRAY获取长度?

时间:2018-06-22 06:41:11

标签: azure u-sql

对于上下文,我从传感器获取数据并将其存储在这样的字符串中

"axes" : "...,1,23,21,0,12,10,212,12,..."

大小可能随发送数据的机器而变化...所以我的目标是像SQL.ARRAY一样存储它,我想稍后获得此数组的大小以执行一些业务报告。

是否可以找到SQL.ARRAY的长度?

@outputfile =
    SELECT m.MachineID,
           COUNT( * ) AS nbAxesArray
    FROM MachineInfos AS m
         JOIN
             LoadDataAxes AS lda
         ON m.EventIoTID == lda.EventIoTID
         //WHERE getLength(lda.L) == 0 // something like this
    GROUP BY m.MachineID;

1 个答案:

答案 0 :(得分:1)

SQL.ARRAY复杂类型具有许多方法,例如Count,并在后台*实现IEnumberable。一个简单的例子:

DECLARE @outputFile string = @"output/output.csv";

@input =
    SELECT *
    FROM ( VALUES 
        ( 100, "1,23,21,0,12,10,212,12" ),
        ( 101, "7,8,9" )
         ) AS x(rowId, y);


// Convert the string to array
@working =
    SELECT rowId, new SQL.ARRAY<string>(y.Split(',')) AS z
    FROM @input;


/*
// Explode the array to individual rows
@output =
    SELECT b
    FROM @working
         CROSS APPLY
             EXPLODE(z) AS a(b);
*/

@output =
    SELECT rowId, z.Count AS c
    FROM @working;


OUTPUT @output
TO @outputFile
USING Outputters.Csv(quoting:false);

*(我认为)

我的结果:

Results

其他一些示例here。有帮助吗?