我已经设置了从Application Insights到Blog的连续导出。通过数据流,我可以将JSON文件导出到SQL DB中。到目前为止,一切都很好。 同样在Phani Rahul Sivalenka的帮助下,我可以按照以下说明查询自定义维度的各个属性:Application Insights and Azure Stream Analytics Query a custom JSON property
当我手动导出到CSV文件时,我的自定义尺寸如下所示:
"{""OperatingSystemVersion"":""10.0.18362.418"",""OperatingSystem"":""WINDOWS"",""RuntimePlatform"":""UWP"",""Manufacturer"":""LENOVO"",""ScreenHeight"":""696"",""IsSimulator"":""False"",""ScreenWidth"":""1366"",""Language"":""it"",""IsTablet"":""False"",""Model"":""LENOVO_BI_IDEAPAD4Q_BU_idea_FM_""}"
除单列外,我还希望将整个自定义维度作为字符串包含在SQL Table列(varchar(max))中。 在我的数据流输出查询的“测试结果”中,我看到了上面的格式-但是,当真正导出/打印到SQL DB中时,我的所有测试都在SQL表中仅以值“ Array”或“ Record”作为值而结束列。
在数据流查询中我该怎么做才能将整个自定义维度值作为字符串获取,并且能够将其作为一个完整的字符串写入SQL Table中?
答案 0 :(得分:0)
在数据流查询中我要做什么才能获得整个自定义 维值作为字符串,我可以将其写入SQL表 作为一个整体?
您可以使用UDF将单个raw的所有键值合并为一个json格式字符串。
UDF:
function main(raw) {
let str = "{";
for(let key in raw) {
str = str + "\""+ key+"\":\""+raw[key]+"\",";
}
str += "}";
return str;
}
SQL:
SELECT udf.jsonstring(INPUT1) FROM INPUT1
输出:
答案 1 :(得分:0)
答案使我步入正轨。 上面的脚本未包含预期的值。因此,我修改了脚本以使其根据需要工作:
function main(dimensions) {
let str = "{";
for (let i in dimensions)
{
let dim = dimensions[i];
for (let key in dim)
{
str = str + "\"" + key+ "\":\""+dim[key]+"\",";
}
}
str += "}";
return str;
}
选择:
WITH pageViews as (
SELECT
V.ArrayValue.name as pageName
, *
, customDimensions = UDF.flattenCustomDimensions(A.context.custom.dimensions)
, customDimensionsString = UDF.createCustomDimesionsString(A.context.custom.dimensions)
FROM [AIInput] as A
CROSS APPLY GetElements(A.[view]) as V
)
通过此操作,我在SQL表中获得了自定义维度字符串,如下所示:
{"Language":"tr","IsSimulator":"False","ScreenWidth":"1366","Manufacturer":"Hewlett-Packard","OperatingSystem":"WINDOWS","IsTablet":"False","Model":"K8K51ES#AB8","OperatingSystemVersion":"10.0.17763.805","ScreenHeight":"696","RuntimePlatform":"UWP",}