0

這個問題是關於流分析。我想將一個blob導出到SQL中。我知道這個過程,我的問題是我必須使用的查詢。解析對象作爲字符串輸出的流天青分析

{"performanceCounter":[{"available_bytes":{"value":994164736.0},"categoryName":"Memory","instanceName":""}],"internal":{"data":{"id":"459bf840-d259-11e5-a640-1df0b6342362","documentVersion":"1.61"}},"context":{"device":{"type":"PC","network":"Ethernet","screenResolution":{},"locale":"en-US","id":"RD0003FF73B748","roleName":"Sdm.MyGovId.Static.Web","roleInstance":"Sdm.MyGovId.Static.Web_IN_1","oemName":"Microsoft Corporation","deviceName":"Virtual Machine","deviceModel":"Virtual Machine"},"application":{"version":"R2.0_20160205.5"},"location":{"continent":"North America","country":"United States","clientip":"104.41.209.0","province":"Washington","city":"Redmond"},"data":{"isSynthetic":false,"samplingRate":100.0,"eventTime":"2016-02-13T13:53:44.2667669Z"},"user":{"isAuthenticated":false,"anonAcquisitionDate":"0001-01-01T00:00:00Z","authAcquisitionDate":"0001-01-01T00:00:00Z","accountAcquisitionDate":"0001-01-01T00:00:00Z"},"operation":{},"cloud":{},"serverDevice":{},"custom":{"dimensions":[],"metrics":[]},"session":{}}} 
{"performanceCounter":[{"percentage_processor_total":{"value":0.},"categoryName":"Processor","instanceName":"_Total"}],"internal":{"data":{"id":"459bf841-d259-11e5-a640-1df0b6342362","documentVersion":"1.61"}},"context":{"device":{"type":"PC","network":"Ethernet","screenResolution":{},"locale":"en-US","id":"RD0003FF73B748","roleName":"Sdm.MyGovId.Static.Web","roleInstance":"Sdm.MyGovId.Static.Web_IN_1","oemName":"Microsoft Corporation","deviceName":"Virtual Machine","deviceModel":"Virtual Machine"},"application":{"version":"R2.0_20160205.5"},"location":{"continent":"North America","country":"United States","clientip":"104.41.209.0","province":"Washington","city":"Redmond"},"data":{"isSynthetic":false,"samplingRate":100.0,"eventTime":"2016-02-13T13:53:44.2668221Z"},"user":{"isAuthenticated":false,"anonAcquisitionDate":"0001-01-01T00:00:00Z","authAcquisitionDate":"0001-01-01T00:00:00Z","accountAcquisitionDate":"0001-01-01T00:00:00Z"},"operation":{},"cloud":{},"serverDevice":{},"custom":{"dimensions":[],"metrics":[]},"session":{}}} 
{"performanceCounter":[{"percentage_processor_time":{"value":0.0},"categoryName":"Process","instanceName":"w3wp"}],"internal":{"data":{"id":"459bf842-d259-11e5-a640-1df0b6342362","documentVersion":"1.61"}},"context":{"device":{"type":"PC","network":"Ethernet","screenResolution":{},"locale":"en-US","id":"RD0003FF73B748","roleName":"Sdm.MyGovId.Static.Web","roleInstance":"Sdm.MyGovId.Static.Web_IN_1","oemName":"Microsoft Corporation","deviceName":"Virtual Machine","deviceModel":"Virtual Machine"},"application":{"version":"R2.0_20160205.5"},"location":{"continent":"North America","country":"United States","clientip":"104.41.209.0","province":"Washington","city":"Redmond"},"data":{"isSynthetic":false,"samplingRate":100.0,"eventTime":"2016-02-13T13:53:44.2668342Z"},"user":{"isAuthenticated":false,"anonAcquisitionDate":"0001-01-01T00:00:00Z","authAcquisitionDate":"0001-01-01T00:00:00Z","accountAcquisitionDate":"0001-01-01T00:00:00Z"},"operation":{},"cloud":{},"serverDevice":{},"custom":{"dimensions":[],"metrics":[]},"session":{}}} 

那麼你可以看到3個json對象哪些對象在數組performanceCounter中有不同的字段。基本上是每個對象的第一個對象。第一個是available_bytes,第二個是percentage_processor_total,第三個是percentage_processor_time。

因爲我將它導出到一個名爲performaceCounter的sql表中,所以我應該爲每個不同的對象都有一個不同的列,所以我想將它保存到一個字符串中,然後在我的應用程序中解析它。

作爲起點我有這個查詢讀取的輸入(斑點)和寫入輸出(SQL)

Select GetArrayElement(A.performanceCounter,0) as a 
INTO 
    PerformanceCounterOutput 
FROM PerformanceCounterInput A 

這GetArrayElement取入的PerformanceCounter陣列的索引0,但然後寫入一個不同列中查找每個對象中的每個不同字段。所以我應該有所有不同的櫃檯,併爲每一個列,但我的想法更像是一列呼叫performanceCounterData並保存字符串如

「‘available_bytes’:‘值’:994164736.0},‘類別名稱’:」存儲器」, 「實例名」: 「」」

或該

「{」 percentage_processor_total 「:{」 值 「:0.},」 類別名稱 「:」 處理器」, 「實例名」: 「_總」} 「

」{「percentage_processor_ti我 「:」 值 「:0.0},」 類別名稱 「:」 過程 「 」實例名「: 」W3WP「}」

我怎麼能投像一個String數組? 我試圖CAST(GetArrayElement(A.performanceCounter,0)作爲爲nvarchar(MAX)),但我不能。

請一些很好的幫助會得到回報

回答

1

用下面的解決方案,我得到2列與屬性的名稱,另一個屬性的值,這是我最初的目的

With pc as 
    (
     Select 
     GetArrayElement(A.[performanceCounter],0) as counter 
     ,A.context.data.eventTime as eventTime 
      ,A.context.location.clientip as clientIp 
      ,A.context.location.continent as continent 
      ,A.context.location.country as country 
      ,A.context.location.province as province 
      ,A.context.location.city as city 
     FROM PerformanceCounterInput A 
    ) 
     select 
    props.propertyName, 
    props.propertyValue, 
    pc.counter.categoryName, 
    pc.counter.instanceName, 
    pc.eventTime, 
    pc.clientIp, 
    pc.continent, 
    pc.country, 
    pc.province, 
    pc.city 
    from pc 
    cross apply GetRecordProperties(pc.counter) as props 
    where props.propertyname<>'categoryname' and props.propertyname<>'instancename' 

無論如何,如果有人發現瞭如何編寫在分析純文本的對象,仍然獎勵和讚賞將

1

你可以做這樣的事情的下方,這給櫃檯爲(propertyName的,的PropertyValue)對。

with T1 as 
(
select 
    GetArrayElement(iotInput.performanceCounter, 0) Counter, 
    System.Timestamp [EventTime] 
from 
    iotInput timestamp by context.data.eventTime 
) 

select 
    [EventTime], 
    Counter.categoryName, 
    Counter.available_bytes [Value]  
from 
    T1 
where 
    Counter.categoryName = 'Memory' 

    union all 

select 
    [EventTime], 
    Counter.categoryName, 
    Counter.percentage_processor_time [Value]  
from 
    T1 
where 
    Counter.categoryName = 'Process' 

查詢,讓每個計數器類型一個欄也可以做,你將不得不或者通過與每一個反「案」的語句做一個連接或一組。

+0

在這種情況下,我需要事先知道將被導出到blob的所有不同計數器(available_bytes,percentage_processor_time ......) 因爲它是JSon,所以我沒有任何結構決定,可以收到不同的計數器。看看我在下面找到的解決方案,看看我的意思。總之非常感謝您的時間和不同的方法 –

+0

GetRecordProperties()函數非常適合這裏。對不起,沒有注意到你已經在使用它了。到目前爲止,您所寫的查詢是最好的方法。 –