在门户中编辑流分析转换查询时,您可以将其格式化以方便多行阅读...例如
SELECT
INTO [Output1]
FROM [Input1]
PARTITION BY PartitionId
WHERE etc etc etc
将其放入 CI/CD 的 ARM 模板中时,它会作为一个巨大的长字符串输入,最终会在门户中显示为...
SELECT * INTO [Output1] FROM [Input1] PARTITION BY PartitionId WHERE etc etc etc to infinity....
官方文档非常无用,没有为模板的查询部分提供任何线索,只是说它是一个“字符串”......
有一个 Microsoft 示例模板,这是我能找到的唯一指定了转换查询的示例... https://github.com/Azure/azure-quickstart-templates/blob/master/101-streamanalytics-create/azuredeploy.json ...看起来它正在尝试进行间距...
"query": "SELECT\r\n *\r\nINTO\r\n [YourOutputAlias]\r\nFROM\r\n [YourInputAlias]"
...但失败得很严重 - 请参阅屏幕截图
有人成功做到了吗?
还有人知道为什么可以在 Azure 资源浏览器 ( https://resources.azure.com/ ) 中看到转换查询吗?或者它无法与流作业的其余部分一起从门户导出? (在资源组级别完成)
提前致谢
最佳答案
我知道已经过去了一整年了,也许你已经明白了这一点,但是,这就是我所做的:
在我的参数文件中,我使用了一个字符串数组,例如:
"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://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-string#concat )
["Foo","Bar","Blah"]
因此需要进行额外的转换,以便将其转换为流分析输出中可读的内容。
另请注意此处的 %%INPUTSTREAMNAME%% 和 %%OUTPUTSTREAMNAME%%,因为我的输入和输出流也是参数,并且使用典型的内联 [parameter('ParamName')] 不能很好地处理其余的转换需要。
在我的模板文件中,我采用StreamAnalyticsJobQueryMultiline参数并使用变量字段来执行此转换:
"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')]"
}
}
关于Azure 流分析作业 - 转换查询 - ARM 模板中的正确格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60926277/