2016-05-23 65 views
1

我需要一種方法,可以將來自2個SA輸入的輸入與1個SA輸出相結合。流分析(SA)多輸入和一個輸出

我想從兩個輸入讀取到的數據,並希望把他們一分出來就把(SQL表) 獲得一個異常說「重複的輸出名稱中不允許使用」

SELECT 
    Input.internal.data.id AS id, 
    Input.context.data.eventtime AS eventtime, 
    recordProperty.PropertyName AS name, 
    Cast(recordProperty.PropertyValue.Value AS bigint) AS value 
INTO 
    [output-custommetric] 
FROM 
    [input-custommetric] AS Input TIMESTAMP BY Input.context.data.eventtime 
    CROSS APPLY GetElements(Input.[context].[custom].[metrics]) AS flat 
    CROSS APPLY GetRecordProperties(Flat.ArrayValue) AS recordProperty 

SELECT 
    Input.internal.data.id AS id, 
    Input.context.data.eventtime AS eventtime, 
    recordProperty.PropertyName AS name, 
    Cast(recordProperty.PropertyValue.Value AS bigint) AS value 
INTO 
    [output-custommetric] 
FROM 
    [input-slacustommetric] AS Input TIMESTAMP BY Input.context.data.eventtime 
    CROSS APPLY GetElements(Input.[context].[custom].[metrics]) AS flat 
    CROSS APPLY GetRecordProperties(Flat.ArrayValue) AS recordProperty 

回答

4

由於兩個查詢的數據類型似乎相同,因此可以在輸出到SQL表之前使用UNION將兩個查詢的輸出組合爲一個。

這裏是你的查詢重寫:

SELECT 
    Input.internal.data.id AS id, 
    Input.context.data.eventtime AS eventtime, 
    recordProperty.PropertyName AS name, 
    Cast(recordProperty.PropertyValue.Value AS bigint) AS value 
INTO 
    [output-custommetric] 
FROM 
    [input-custommetric] AS Input TIMESTAMP BY Input.context.data.eventtime 
    CROSS APPLY GetElements(Input.[context].[custom].[metrics]) AS flat 
    CROSS APPLY GetRecordProperties(Flat.ArrayValue) AS recordProperty 
UNION 
SELECT 
    Input.internal.data.id AS id, 
    Input.context.data.eventtime AS eventtime, 
    recordProperty.PropertyName AS name, 
    Cast(recordProperty.PropertyValue.Value AS bigint) AS value 
FROM 
    [input-slacustommetric] AS Input TIMESTAMP BY Input.context.data.eventtime 
    CROSS APPLY GetElements(Input.[context].[custom].[metrics]) AS flat 
    CROSS APPLY GetRecordProperties(Flat.ArrayValue) AS recordProperty