![](/img/trans.png)
[英]Bulk Import using nodeJS with Azure DocumentDB. Partition Key issue
[英]how to process data based on the partition key using azure stream analytics?
我正在從用節點 js 編寫的 web 作業向事件中心發送批處理數據,並且我可以在 Azure stream 分析中接收數據。 但我無法在 ASA 上看到分區鍵。 我正在使用以下代碼將數據發送到事件中心。
const {EventHubClient} = require("@azure/event-hubs");
var axios = require('axios');
const connectionString = "Endpoint=connectionstring";
const eventHubsName = "eventhubname";
async function main(){
const client = EventHubClient.createFromConnectionString(connectionString,eventHubsName);
var axios = require('axios');
var response = await axios.get('https://nseindia.com/live_market/dynaContent/live_watch/stock_watch/nifty500StockWatch.json');
var response1 = await axios.get('https://www.nseindia.com/live_market/dynaContent/live_analysis/gainers/niftyGainers1.json');
var eventData = [{body:response1['data']['data'],partitionKey:"pk12346"},{body:response['data']['data'],partitionKey:"pk12345"}];
console.log(eventData);
console.log("begin send...");
await client.sendBatch(eventData);
await client.close();
}
main().catch(err =>{
console.log("Error occurred: ",err);
});
response1['data']['data'] 和 response1['data']['data'] 中的數據是 object 數據的數組。 例如 [{key1:value1,key2:value2},{{key1:value1,key2:value2}}]
如果我無法在 ASA 上看到分區(在從輸入中獲取樣本數據時)如何使用 where 條件作為 partitionkey 並應用 trnsformation。
您需要編寫一個提取數組數據的查詢。 以下是我的一個 POC 的示例:
with deviceAndMessage as (Select IoTHub.ConnectionDeviceId as deviceId, * from inputData),
unpackedmessages as (Select deviceAndMessage.Deviceid, message.ArrayValue.DisplayName, message.ArrayValue.Value.Value, message.ArrayValue.Value.SourceTimestamp from deviceAndMessage CROSS APPLY GetArrayElements(deviceAndMessage.message) AS message),
inputWeatherData as (select deviceId, unpackedmessages.DisplayName, unpackedmessages.Value, unpackedmessages.SourceTimestamp from unpackedmessages),
humidity as (select * from inputWeatherData where DisplayName = 'Humidity')
我的信息結構是
{
"message" : [
{
"DisplayName" : "Test",
"Value" : {
"SourceTimestamp" : "whatever",
"Value" : 1
}
},
{
"DisplayName" : "Test",
"Value" : {
"SourceTimestamp" : "whatever",
"Value" : 1
}
}
]
}
也許您可以使用此示例並針對您的數據結構進行調整。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.