一連のダイナミックデータがStream Analyticsジョブによって処理されています。私が明示的に問い合わせることができる統一プロパティはいくつかありますが、ペイロードの大部分はクエリ時には不明な型のものです。私の目標は、この未知のデータ(レコード)を取得し、Azureテーブルに書き込まれたクエリの最上位フィールドにすべてのプロパティを昇格させることです。レコードのトップレベルの既知のプロパティをストリームアナリティクスクエリの結果にプロモート
私はレコードのプロパティを平坦化することができます。常にレコードの子オブジェクトとしてクエリに追加されます。 GetRecordProperties()
私はすべてのプロパティに対して別のレコードが返されることを望まないので役に立ちません。
WITH
[custom_events_temp] AS
(
SELECT
[magellan].[context].[data].[eventTime] as [event_time],
[flat_event].ArrayValue.name as [event_name],
udf.FlattenCustomDimensions([magellan].[context].[custom].[dimensions]) as [flat_custom_dim]
FROM [Magellan--AI-CustomEvents] magellan
TIMESTAMP BY [magellan].[context].[data].[eventTime]
CROSS APPLY GetElements([magellan].[event]) as [flat_event]
),
-- create table with extracted webhook data
[all_webhooks] AS
(
SELECT
[flat_custom_dim].[hook_event_source] as PartitionKey,
udf.CreateGuid('') as RowKey,
-- event data
[custom_events_temp].[event_time],
[custom_events_temp].[flat_custom_dim].[hook_event_name] as [event_name],
-- webhook payload data
udf.FlattenWebhookPayload(udf.ExtractJsonWebhookPayload([custom_events_temp].[flat_custom_dim].[webhook_payload])) AS [payload]
FROM [custom_events_temp]
)
SELECT * INTO [TrashTableOut] FROM [all_webhooks]
をそして私が得る結果の記録は次のようになります。
私のクエリは次のようになります。アイデアはネストされたオブジェクトであるのすべてをネストしないようにして、各プロパティがAzureテーブルに独自の列を持つようにすることです。
{
"partitionkey": "zzzzzzzzz",
"rowkey": "8beeb783-b07f-8a98-ef56-71c43378a5fc",
"event_time": "2017-10-15T05:37:06.3240000Z",
"event_name": "subscriber.updated_lead_score",
"payload": {
"event": "subscriber.updated_custom_field",
"data.subscriber.id": "...",
"occurred_at": "2017-10-15T05:36:57.000Z",
"data.account_id": "11111",
"data.subscriber.status": "active",
"data.subscriber.custom_fields.coupon": "xxxxxxx",
"data.subscriber.custom_fields.coupon_discounted_price": "11111",
"data.subscriber.custom_fields.coupon_pre_discount_price": "11111",
"data.subscriber.custom_fields.name": "John Doe",
"data.subscriber.custom_fields.first_name": "John",
"data.subscriber.custom_fields.ip_address": "0.0.0.0",
"data.subscriber.tags": "tag1,tag2,tag3",
"data.subscriber.time_zone": "Europe/Berlin",
"data.subscriber.utc_offset": 120,
"data.subscriber.created_at": "2017-03-27T18:19:35.000Z"
}
}
これは可能ですか? UDF FlattenCustomDimensions
は項目の配列をとり、プロパティとして公開します。 UDF ExtractJsonWebhookPayload
は文字列を受け取ります&はJSONに変換しますが、UDF FlattenWebhookPayload
は複合JSONオブジェクトを取ります&は、結果のオブジェクトに表示されるドット構文を作成します。誰かが良いアイデア/オプションが用意されていない限り
{
"partitionkey": "zzzzzzzzz",
"rowkey": "8beeb783-b07f-8a98-ef56-71c43378a5fc",
"event_time": "2017-10-15T05:37:06.3240000Z",
"event_name": "subscriber.updated_lead_score",
"payload.event": "subscriber.updated_custom_field",
"payload.data.subscriber.id": "...",
"payload.occurred_at": "2017-10-15T05:36:57.000Z",
"payload.data.account_id": "11111",
"payload.data.subscriber.status": "active",
"payload.data.subscriber.custom_fields.coupon": "xxxxxxx",
"payload.data.subscriber.custom_fields.coupon_discounted_price": "11111",
"payload.data.subscriber.custom_fields.coupon_pre_discount_price": "11111",
"payload.data.subscriber.custom_fields.name": "John Doe",
"payload.data.subscriber.custom_fields.first_name": "John",
"payload.data.subscriber.custom_fields.ip_address": "0.0.0.0",
"payload.data.subscriber.tags": "tag1,tag2,tag3",
"payload.data.subscriber.time_zone": "Europe/Berlin",
"payload.data.subscriber.utc_offset": 120,
"payload.data.subscriber.created_at": "2017-03-27T18:19:35.000Z"
}
:
私の究極の目標は次のようになり、結果セットを取得することです。
メインテーブルの特定の列の中にあなたが一時に展開列を照会することができますすべてのネストされたフィールドを宣伝するためのクエリを記述することができます。しかし、クエリは大きくなり、変更するのが難しくなります。 [javascript UDF](https://docs.microsoft.com/en-us/azure/stream-analytics/stream-analytics-javascript-user-defined-functions)の使用を検討しましたか?はるかにクリーンなので、あなたはUDFに渡す単一のフィールドで完全なペイロードを渡す必要があります。 –
さて、ええ、ポイントは私はフィールドを知らないです。フィールド名を知ることは、ドット構文を使用して直接照会することで容易に対処できます。 –