gpt4 book ai didi

powerquery - 在 M 中声明数据类型的更好语法 - Text.Type 或类型文本?

转载 作者:行者123 更新时间:2023-12-05 03:58:16 25 4
gpt4 key购买 nike

对于 Power Query/PowerBI 中的 M,我应该使用哪种语法来设置数据类型?
A) type text(或type logicaltype date等)
B) Text.Type(或Logical.TypeDate.Type等)

既然选项 B 存在,是否有任何理由使用选项 A 语法?我尝试阅读 Power Query M language specification 的第 5 章,但我找不到明确的答案。

这是一个使用 Table.AddColumn 的示例(尽管数据类型无处不在):

let
OldTable = #table({"Col1"},{{"This column"}}),
fMyFunc = (paramText as text ) as text => let returnText = paramText & "_new" in returnText,
NewTable = Table.AddColumn(OldTable, "NewCol", each "Sample", Text.Type),
NewerTable = Table.AddColumn(NewTable, "NewerCol", each fMyFunc([NewCol]), Text.Type)
in
NewerTable

我相信引入选项 B 只是为了标准化类型定义;例如,有 Int64.Type 但没有 type Int64。因此,我的问题的答案可能是“这根本不重要”。但是,如果一个选项似乎是 future 的共识,我宁愿现在就开始在我的代码中保持一致。

最佳答案

我同意这并不重要,除非从风格的角度来看。

正如您所提到的,像 Int64.Type 这样的非基本类型不能像 type text 那样写成 type Int64 , 所以如果你想让你的风格在原始类型和非原始类型之间保持一致,那么你需要选项 B。


您链接的文档第 48 页和第 49 页列出的原始类型是:

  • type null, which classifies the null value
  • type logical, which classifies the values true and false
  • type number, which classifies number values
  • type time, which classifies time values
  • type date, which classifies date values
  • type datetime, which classifies datetime values
  • type datetimezone, which classifies datetimezone values
  • type duration, which classifies duration values
  • type text, which classifies text values
  • type binary, which classifies binary values
  • type type, which classifies type values.
  • type list, which classifies list values
  • type record, which classifies record values
  • type table, which classifies table values
  • type function, which classifies function values
  • type anynonnull, which classifies all values excluding null

关于powerquery - 在 M 中声明数据类型的更好语法 - Text.Type 或类型文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58118348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com