如何在 Kusto 中使用 Materialize?

发布于 2025-01-10 21:34:56 字数 751 浏览 1 评论 0原文

我有一个名为“consumation”的函数,它接受 4 个参数,最后按名称汇总一个值。从这个函数中,我试图具体化一些公式,以获得更好的查询性能。

例如:

let firstFormula = materialize (
    consumption("ID", "scale", "node", 100.0)
);

let secondformula = materialize (
    consumption("ID", "scale", "node", 60.0)
);

然后我创建一个公式,它将来自第一个公式的值除以来自第二个公式的值。

let thirdFormula =  view (){
union 
    firstformula,
    secondformula
    | summarize 
        value1 = max(case(Name == "ABCD", todouble(Value), 0.0)),
        value2 = max(case(Name == "EFGH", todouble(Value), 0.0))
    | project Value = round(value1 / value2 * 100.0, 2)
};

我首先在不使用 Materialize 函数的情况下测试了公式,以检查 CPU 性能。然后我使用 Materialize 对其进行了测试。我最终获得了比不使用实体化更好的性能。我在这里做错了什么吗?我是否以错误的方式使用了实体化函数?

I have a function called consumption which takes 4 parameters and finally summarizes a value by Name. From this function I am trying to materialize some formulas to have as a result a better query performance.

For example:

let firstFormula = materialize (
    consumption("ID", "scale", "node", 100.0)
);

let secondformula = materialize (
    consumption("ID", "scale", "node", 60.0)
);

I am then creating a formula which divides the value coming from the firstformula by the value coming from secondformula.

let thirdFormula =  view (){
union 
    firstformula,
    secondformula
    | summarize 
        value1 = max(case(Name == "ABCD", todouble(Value), 0.0)),
        value2 = max(case(Name == "EFGH", todouble(Value), 0.0))
    | project Value = round(value1 / value2 * 100.0, 2)
};

I tested the formulas first without using the materialize function in order to check the CPU performance. I then tested it using the materialize. I ended up having a better performance from the one not using the materialize. Am I doing something wrong here ? Am I using the materialize function in a wrong way ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还在原地等你 2025-01-17 21:34:57

Materialize() 函数对于缓存将在后续查询语句中使用的查询结果非常有用,例如,如果您有一个组织的汇总,然后有一列将其显示为总数的百分比,在这种情况下具体化结果聚合然后计算总数,将显着减少(可能几乎一半)处理时间,例如:

let Agg = materialize(T | filter | summarize sum(Value) by Org);
let total_sum = toscalar(Agg | summarize sum(sum_Value))
Agg
| extend PercentOfTotal = sum_Value/total_sum

在您的情况下,您似乎正在具体化处理每一行的结果,但从未多次使用具体化数据然后证明缓存成本的合理性这导致了更高的查询成本。

The materialize() function is useful to cache query results that will be used in subsequent query statements, for example, if you have a summarization by an organization and then a column that displays it as percentage of the total, in such case materializing the results of the aggregation and then calculating the total, will reduce significantly (probably by almost a half) the processing time, for example:

let Agg = materialize(T | filter | summarize sum(Value) by Org);
let total_sum = toscalar(Agg | summarize sum(sum_Value))
Agg
| extend PercentOfTotal = sum_Value/total_sum

In Your case, it seems that you are materializing the results of processing each row but never used the materialized data multiple times afterward to justify the caching cost and this resulted in a higher query cost.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文