ストリームアナリティクスでarray_aggまたはstring_aggに相当するpostgresを実行する方法はありますか?私は数秒ごとに来るデータを持っており、時間枠内で値のカウントを取得したいと考えています。 2秒のスライディングウィンドウでAzureストリーム分析array_agg相当?
{time:12:01:01,name:A,location:X,value:10}
{time:12:01:01,name:B,location:X,value:9}
{time:12:01:02,name:C,location:Y,value:5}
{time:12:01:02,name:B,location:Y,value:4}
{time:12:01:03,name:B,location:Z,value:2}
{time:12:01:03,name:A,location:Z,value:3}
{time:12:01:06,name:B,location:Z,value:4}
{time:12:01:06,name:C,location:Z,value:7}
{time:12:01:08,name:B,location:Y,value:1}
{time:12:01:13,name:B,location:X,value:8}
、私はデータは、以下を参照してくださいグループにしたい:
データ
12:01:01, 2 events, 9.5 avg, 2 distinct names, 1 distinct location, nameA:1, nameB:1, locationX:1
12:01:02, 4 events, 7 avg, 3 distinct names, 2 distinct location, nameA:1, nameB:2,nameC:1,locationX:1,locationY:1
12:01:03...
12:01:06...
...
私はイベントの数、平均値を得ることができ、かつ問題のない別個のカウント。私はウインドウとwithステートメントを使ってタイムスタンプに参加し、そのタイムスタンプの集計カウントを取得します。 Azureで文字列を集計する方法がわからないため、名前と場所で合計数を取得する方法を調べるのに問題があります。
with agg1 as (
select system.timestamp as start,
avg(value) as avg,
count(1) as events,
count(distinct name) as distinct names,
count(distinct location) as distinct location
from input timestamp by created
group by slidingwindow(second,2)
),
agg2 as (
select agg2_inner.start,
array_agg(name,'|',ct_name) as countbyname (????)
from (
select system.timestamp as start,
name, count(1) as ct_name
from input timestamp by created
group by slidingwindow(second,2), name
) as agg2_inner
group by agg2_inner.start, slidingwindow(seconds,2)
)
select * from agg1 join agg2 on (datediff(second,agg1,agg2) between 0 and 2
and agg1.start = agg2.start)
クエリがビット動的である必要があるように、名前、場所のリストが設定されていません。カウントが単一のクエリ内のオブジェクト内にある場合、後で個々のカウントを取得するために解析することができます。