ApplyMap - 脚本函数
ApplyMap 脚本函数用于将表达式输出映射至先前加载的映射表。
Syntax:
ApplyMap('map_name', expression [ , default_mapping ] )
Return data type: 双
Arguments:
参数 | 说明 |
---|---|
|
以前通过 mapping load 或 mapping select 语句创建的映射表的名称。该名称必须用单直引号引起来。 警告: 如果您在宏扩展的变量中使用该函数并引用不存在的映射表格,函数调用会失败并且不会创建字段。
|
|
表达式,即将被映射的结果。 |
|
如果已指定,即如果映射表不包含与 |
警告: ApplyMap 的输出字段不应有和其输入字段中的一个相同的名称。这可能导致意外结果。不使用的示例:ApplyMap('Map', A) as A。
Example:
在此例中,我们加载了销售人员和国家代码(表示销售人员所居住的国家)的列表。我们使用表格将国家代码映射到国家,以便将国家代码替换为国家名称。在映射表中仅定义了三个国家,其他国家代码已映射到
// Load mapping table of country codes:
map1:
mapping LOAD *
Inline [
CCode, Country
Sw, Sweden
Dk, Denmark
No, Norway
] ;
// Load list of salesmen, mapping country code to country
// If the country code is not in the mapping table, put Rest of the world
Salespersons:
LOAD *,
ApplyMap('map1', CCode,'Rest of the world') As Country
Inline [
CCode, Salesperson
Sw, John
Sw, Mary
Sw, Per
Dk, Preben
Dk, Olle
No, Ole
Sf, Risttu
] ;
// We don't need the CCode anymore
Drop Field 'CCode';
最终生成的表格(销售人员)如下所示:
Salesperson | Country |
---|---|
John | Sweden |
Mary | Sweden |
Per | Sweden |
Preben | Denmark |
Olle | Denmark |
Ole | Norway |
Risttu | Rest of the world |