简体   繁体   English

Kusto - 最新版本行的物化视图

[英]Kusto - Materialized View on latest version of rows

I have a Table called 'metadata', that contains a list of Parameter and ParamterValue that is partitioned by a TestId.我有一个名为“元数据”的表,其中包含由 TestId 分区的参数和参数值列表。 Everytime a Test is changed, the Test will be reingested to Azure Data Explorer with a never Version.每次更改测试时,测试都将重新摄取到 Azure Data Explorer,且版本为 never。

My overall goal is to:我的总体目标是:

  1. Define a Function (GetTestsFromSearch) that takes a Parameter (dynamic) of key value pairs, that lets me Query all Tests (Of latest version) for a match of the Key/Value pairs:定义一个 Function (GetTestsFromSearch),它采用键值对的参数(动态),这让我可以查询所有测试(最新版本)以查找键/值对的匹配项:
( {{"Search param1", "Search value1"},{"Search param2", "Search value2"}}

Example例子

GetTestsFromSearch({{"ProjectId", "SturnProject"},{"Product Name", "Nacelle "}})

Should return应该返回

TestId测试编号 Version版本
fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 3 3个
ea5b688c-b61f-4c5b-bb87-af2eac94d454 ea5b688c-b61f-4c5b-bb87-af2eac94d454 1 1个

from the example metadata.table below来自下面的示例 metadata.table

  1. Another Goal is to Create a Materialized View that contains only latest metadata for each Test (Explained below table)另一个目标是创建一个只包含每个测试的最新元数据的物化视图(下表解释)

Example of metadata.table metadata.table 示例

TestId测试编号 TestName测试名称 Parameter范围 ParameterValue参数值 Version版本
fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 MyTest我的测试 ProjectId项目编号 SturnProject转向计划 1 1个
fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 MyTest我的测试 Product Category产品分类 2MW 2兆瓦 1 1个
fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 MyTest我的测试 Project Start Date项目开始日期 2022-02-03 2022-02-03 1 1个
fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 MyTest我的测试 ProjectId项目编号 SturnProject转向计划 2 2个
fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 MyTest我的测试 Product Category产品分类 2MW 2兆瓦 2 2个
fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 MyTest我的测试 Project Start Date项目开始日期 2022-02-03 2022-02-03 2 2个
fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 MyTest我的测试 ProjectId项目编号 SturnProject转向计划 3 3个
fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 MyTest我的测试 Product Category产品分类 2MW 2兆瓦 3 3个
fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 MyTest我的测试 Project Start Date项目开始日期 2022-02-03 2022-02-03 3 3个
ea5b688c-b61f-4c5b-bb87-af2eac94d454 ea5b688c-b61f-4c5b-bb87-af2eac94d454 MyTest我的测试 ProjectId项目编号 SturnProject转向计划 1 1个
ea5b688c-b61f-4c5b-bb87-af2eac94d454 ea5b688c-b61f-4c5b-bb87-af2eac94d454 MyTest我的测试 Project State项目 State Open打开 1 1个
ea5b688c-b61f-4c5b-bb87-af2eac94d454 ea5b688c-b61f-4c5b-bb87-af2eac94d454 MyTest我的测试 Product Name产品名称 Nacelle机舱 1 1个

Over time there will be thousands of Tests in several different Versions, and hence I anticipate, that it would be a good idea to create a Materialized View , that only maintains the Latest Versions of each Test - I have tried to create the view as:随着时间的推移,将有数以千计的测试在几个不同的版本中,因此我预计,创建一个物化视图是个好主意,它只维护每个测试的最新版本——我试图将视图创建为:

metadata
| summarize arg_max(Version,*) by TestId

But this only gives me one Parameter and Parameter Value for each TestId/Version, not the entire result set of the Test.但这只为每个 TestId/Version 提供了一个参数和参数值,而不是测试的整个结果集。

  • Can anyone point me in the right direction for this materialized view?谁能为我指明这个物化视图的正确方向?

I have included an example of a metadata.table as DataTable, which can be used in kusto directly.我已经包含了一个 metadata.table 作为 DataTable 的示例,它可以直接在 kusto 中使用。

Metadata Table as DataTable元数据表作为数据表

datatable (TestId: string, Name: string, Parameter: string, ParameterValue: string, Version: int) [
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Test Report, DMS number","1234-231",int(3),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Project name","Thor3",int(3),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","GTRS reference","gtrs",int(3),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Product Category","2MW",int(3),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Project number","TE-12321",int(3),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","DUT responsible person","ANFRB3",int(3),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Test execution person","ANFRB3",int(3),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Project Manager","ANFRB3",int(3),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","DVPR, DMS number","1234-1234",int(3),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","DVRE, DMS number","1231-1213",int(3),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Test Start Date","2022-02-23T00:00:00.0000000Z",int(3),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Test Category","Verification safety",int(3),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","GTRS reference","gtrs",int(2),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Project number","TE-12321",int(2),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","DUT responsible person","ANFRB2",int(2),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Test execution person","ANFRB2",int(2),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Project Manager","ANFRB2",int(2),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","DVPR, DMS number","1234-1234",int(2),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","DVRE, DMS number","1231-1213",int(2),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Test Start Date","2022-02-23T00:00:00.0000000Z",int(2),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Test Category","Verification safety",int(2),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Product Category","2MW",int(2),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Project name","Thor3",int(2),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Test Report, DMS number","1234-231",int(2),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Test Category","Verification safety",int(1),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Project Manager","ANFRB",int(1),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","GTRS reference","gtrs",int(1),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Product Category","2MW",int(1),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Project name","Thor3",int(1),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Project number","TE-12321",int(1),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","DUT responsible person","ANFRB",int(1),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Test execution person","ANFRB",int(1),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","DVPR, DMS number","1234-1234",int(1),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Test Report, DMS number","1234-231",int(1),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","DVRE, DMS number","1231-1213",int(1),
    "fc76aa10-5cf8-447e-95f6-3bd801ef2ed0","ANFRB-FILEVIEW-TEST","Test Start Date","2022-02-23T00:00:00.0000000Z",int(1),
    "ea5b688c-b61f-4c5b-bb87-af2eac94d454","ANFRB2-TEST","GTRS reference","gtrs232",int(1),
    "ea5b688c-b61f-4c5b-bb87-af2eac94d454","ANFRB2-TEST","Product Category","4MW",int(1),
    "ea5b688c-b61f-4c5b-bb87-af2eac94d454","ANFRB2-TEST","Project name","Myproject",int(1),
    "ea5b688c-b61f-4c5b-bb87-af2eac94d454","ANFRB2-TEST","Project number","43324534",int(1),
    "ea5b688c-b61f-4c5b-bb87-af2eac94d454","ANFRB2-TEST","DUT responsible person","ANFRB",int(1),
    "ea5b688c-b61f-4c5b-bb87-af2eac94d454","ANFRB2-TEST","Test execution person","ANFRB",int(1),
    "ea5b688c-b61f-4c5b-bb87-af2eac94d454","ANFRB2-TEST","Project Manager","ANFRB",int(1),
    "ea5b688c-b61f-4c5b-bb87-af2eac94d454","ANFRB2-TEST","DVPR, DMS number","435123454",int(1),
    "ea5b688c-b61f-4c5b-bb87-af2eac94d454","ANFRB2-TEST","Test Report, DMS number","123123123",int(1),
    "ea5b688c-b61f-4c5b-bb87-af2eac94d454","ANFRB2-TEST","DVRE, DMS number","12312312312",int(1),
    "ea5b688c-b61f-4c5b-bb87-af2eac94d454","ANFRB2-TEST","Test Start Date","2022-03-01T00:00:00.0000000Z",int(1),
    "ea5b688c-b61f-4c5b-bb87-af2eac94d454","ANFRB2-TEST","Test Category","Verification functionality",int(1),
    "ea5b688c-b61f-4c5b-bb87-af2eac94d454","ANFRB2-TEST","Test facility","CHE",int(1),
    "ea5b688c-b61f-4c5b-bb87-af2eac94d454","ANFRB2-TEST","Test rig","rig23",int(1),
    "ea5b688c-b61f-4c5b-bb87-af2eac94d454","ANFRB2-TEST","Sample ID","1",int(1),
    "ea5b688c-b61f-4c5b-bb87-af2eac94d454","ANFRB2-TEST","Link to test data","asdfsafdsdfa",int(1)
]

Thanks谢谢

If most tests include same properties (as in your example), you can consider changing the schema to a wide schema, in which each run ( Version ) of a TestId and Name is a single record.如果大多数测试包含相同的属性(如您的示例),您可以考虑将架构更改为宽架构,其中TestIdName的每次运行( Version )都是一条记录。 The result schema would look like the output of the following:结果架构类似于以下 output:

**datatable**
| extend pack(Parameter, ParameterValue)
| summarize make_bag(Column1) by TestId, Name, Version
| evaluate bag_unpack(bag_Column1)

Then, you can set up a materialized view with the following aggregation that will provide what you're looking for IIUC:然后,您可以使用以下聚合设置物化视图,它将提供您正在寻找的 IIUC:

T | summarize arg_max(Version, *) by TestId, Name

To switch from the schema in your example to the suggested one, you can either change your ingestion pipeline to ingest in new schema format, or use an update policy for the transformation.要从示例中的架构切换到建议的架构,您可以将摄取管道更改为以新的架构格式摄取,或者使用更新策略进行转换。 If you choose the latter, avoid using bag_unpack plugin in the update policy function. Instead, project the columns you need explicitly, to avoid a non-deterministic schema.如果您选择后者,请避免在更新策略 function 中使用bag_unpack插件。相反,显式投影您需要的列,以避免非确定性架构。

Another alternative, is keeping all properties in single dynamic column, as in the result of:另一种选择是将所有属性保留在单个动态列中,结果如下:

**datatable**
| extend pack(Parameter, ParameterValue)
| summarize make_bag(Column1) by TestId, Name, Version

And using same materialized view definition as above.并使用与上面相同的物化视图定义。

For the 1st question - using the 2nd suggested schema, you can try something like the following:对于第一个问题 - 使用第二个建议的架构,您可以尝试如下操作:

let GetTestsFromSearch = (Filter:dynamic)
{
    T
    | extend pack(Parameter, ParameterValue)
    | summarize Properties = make_bag(Column1) by TestId, Name, Version  
    | summarize arg_max(Version, *) by TestId, Name
    | extend Filter
    | mv-apply Filter on 
    ( 
        extend key=tostring(bag_keys(Filter)[0]) 
        | extend expected = tostring(Filter[key]), actual = tostring(Properties[key])
        | summarize count(), countif(actual == expected)
        | where count_  == countif_
    )
};
GetTestsFromSearch(dynamic({"Test Category" : "Verification safety", "Project name" : "Thor3"}));
TestId测试编号 Name名称 Version版本 Properties特性 count_数数_ countif_ countif_
fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 fc76aa10-5cf8-447e-95f6-3bd801ef2ed0 ANFRB-FILEVIEW-TEST ANFRB-FILEVIEW-测试 3 3个 { {
"Test Report, DMS number": "1234-231", "检测报告,DMS编号": "1234-231",
"Project name": "Thor3", “项目名称”:“雷神3”,
"GTRS reference": "gtrs", “GTRS参考”:“gtrs”,
"Product Category": "2MW", “产品类别”:“2MW”,
"Project number": "TE-12321", “项目编号”:“TE-12321”,
"DUT responsible person": "ANFRB3", “DUT负责人”:“ANFRB3”,
"Test execution person": "ANFRB3", “测试执行人”:“ANFRB3”,
"Project Manager": "ANFRB3", “项目经理”:“ANFRB3”,
"DVPR, DMS number": "1234-1234", "DVPR, DMS 号码": "1234-1234",
"DVRE, DMS number": "1231-1213", "DVRE, DMS 号码": "1231-1213",
"Test Start Date": "2022-02-23T00:00:00.0000000Z", “测试开始日期”:“2022-02-23T00:00:00.0000000Z”,
"Test Category": "Verification safety" 《测试类别》:《验证安全》
} }
2 2个 2 2个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Kusto - 向现有物化视图添加列 - Kusto - Adding a column to an existing materialized view 截断并加载 Kusto 表而不是物化视图,以便它可以用于连续导出 - Truncate and Load a Kusto table instead of a Materialized view so that it can be used for continous export 在不在 Kusto 中序列化数据的情况下在物化视图中按用户名和时间戳查找下一条记录 - Finding next record by username and timestamp in a materialized view without serializing data in Kusto STRUCT 的 BigQuery 具体化视图 - BigQuery Materialized View of a STRUCT 刷新postgres物化视图的性能 - performance of refreshing postgres materialized view 大查询物化视图; 使用(内部)连接创建物化视图 - big query materialized view; create a materialized view using an (inner) join BigQuery 中的视图与具体化视图 - View vs Materialized views in BigQuery 不支持的编码:使用 Kusto Spark 连接器或使用 Spark 版本 < 3.3.0 的 Kusto 导出从 Kusto 读取时的 DELTA_BYTE_ARRAY - Unsupported encoding: DELTA_BYTE_ARRAY when reading from Kusto using Kusto Spark connector or using Kusto export with Spark version < 3.3.0 BigQuery 实体化视图 - ARRAY_AGG 问题 - BigQuery Materialized View - ARRAY_AGG issue BigQuery 实体化视图:查询限制与创建查询限制 - BigQuery Materialized view: Query Limitations vs Creation Query Limitations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM