Mapping
mapping 접두사는 스크립트 실행 중 필드 값과 필드 이름을 교체하는 등의 용도로 사용할 수 있는 매핑 테이블을 만드는 데 사용됩니다.
Syntax:
Mapping( loadstatement | selectstatement )
mapping 접두사는 LOAD 또는 SELECT 문 앞에 넣을 수 있으며 로드 문의 결과를 매핑 테이블로 저장합니다. 매핑은 스크립트 실행 중에 US, U.S. 또는 America를 USA로 바꾸는 등, 필드 값을 효율적으로 대체하는 방법을 제공합니다. 매핑 테이블은 두 개의 열, 즉 비교 값을 포함하는 첫째 열과 원하는 매핑 값을 포함하는 둘째 열로 구성됩니다. 매핑 테이블은 메모리에 임시로 저장되며 스크립트 실행 후 자동으로 삭제됩니다.
매핑 테이블의 내용은 Map … Using 문, Rename Field 문, Applymap() 함수 또는 Mapsubstring() 함수 등을 사용하여 액세스할 수 있습니다.
Example:
이 예에서는 거주 국가를 나타내는 국가 코드에 따라 영업직원 목록을 로드합니다. 국가 코드와 국가를 매핑하는 테이블을 사용하여 국가 코드를 국가명으로 바꿉니다. 매핑 테이블에는 3개 국가만 정의되어 있으며 다른 국가 코드는
// 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
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
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';
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 |