Mohammed Sirajuddin
Mohammed Sirajuddin

Reputation: 71

Stream Analyatic(SA) Multiple Input and one Output

I need a way where I can combine the input from 2 SA input to 1 SA output.

Eg

I am trying to read to the data from two input and want to put them in one out put(SQL Table) Getting an exception saying “Duplicate output names are not allowed”

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

Upvotes: 1

Views: 1508

Answers (1)

Aλeᵡ
Aλeᵡ

Reputation: 491

Since data type of both queries seem to be same, you can use UNION to combine the outputs of your two queries into one before outputting into SQL table.

Here is rewrite of your query:

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

Upvotes: 5

Related Questions