我知道已经过了整整一年,也许你已经知道了,但是,这就是我所做的:
在我的 Parameters 文件中,我使用了一个字符串数组,例如:
"StreamAnalyticsJobQueryMultiline": {
"value": [
"WITH allData AS ( ",
" SELECT ",
" *, ",
" GetMetadataPropertyValue([%%INPUTSTREAMNAME%%], '[User].[EventNamespace]') AS EventNamespace ",
" FROM [%%INPUTSTREAMNAME%%] Partition By PartitionId ",
"SELECT ",
" *, ",
" 'EventHubWriterv1' AS EventType ",
"INTO ",
" [%%OUTPUTSTREAMNAME%%] ",
"FROM ",
" allData Partition By PartitionId "
]
当数组被连接并作为字符串输出时,它会产生类似这样的结果,其中该数组中的每个项目仍然用引号括起来,整个内容包含在方括号内(请参阅:https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-string#concat)
["Foo","Bar","Blah"]
因此,需要进行额外的转换才能将其转换为流分析输出中可读的内容。
还要注意这里的 %%INPUTSTREAMNAME%% 和 %%OUTPUTSTREAMNAME%%,因为我的输入和输出流也是参数,并且使用典型的内联 [parameter('ParamName')] 不能很好地处理其余的转换需要。
在我的 Template 文件中,我采用 StreamAnalyticsJobQueryMultiline 参数并使用 variables 字段进行此转换:
"QueryStringRaw": "[string(concat(parameters('StreamAnalyticsJobQueryMultiline')))]",
// Update the end-of-lines by removing the doublequote and comma, and replacing it with a newline character
"QueryStringIter1": "[replace(variables('QueryStringRaw'), '\",', '\n')]",
// Update the beginning-of-lines by removing the doublequote
"QueryStringIter2": "[replace(variables('QueryStringIter1'), '\"', '')]",
// Update the InputStreamName and OutputStreamName values
"QueryStringIter3": "[replace(variables('QueryStringIter2'), '%%INPUTSTREAMNAME%%', parameters('InputStreamName'))]",
"QueryStringIter4": "[replace(variables('QueryStringIter3'), '%%OUTPUTSTREAMNAME%%', parameters('OutputStreamName'))]",
// Produce the final output for the query string by trimming the leading and trailing square brackets
"QueryStringFinal": "[substring(variables('QueryStringIter4'), 1, sub(length(variables('QueryStringIter4')), 2))]"
然后我在 Microsoft.StreamAnalytics/streamingjobs 属性的转换部分引用它:
"transformation": {
"name": "Transformation",
"properties": {
"streamingUnits": "[parameters('StreamAnalyticsStreamingUnitsScale')]",
"query": "[variables('QueryStringFinal')]"
}
}