1

我需要一种可以将 2 SA 输入的输入组合到 1 SA 输出的方法。

例如

我正在尝试从两个输入中读取数据并希望将它们放在一个输出中(SQL 表)得到一个异常说“不允许重复的输出名称”</p>

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

1 回答 1

5

由于两个查询的数据类型似乎相同,您可以使用 UNION 将两个查询的输出合并为一个,然后再输出到 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
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
于 2016-05-23T20:51:05.097 回答