2016-05-23 64 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