drop table Orders, Salesmen, T456a;
| 這一行將導致從記憶體捨棄三個表格。 |
Tab1:
Load * Inline [
Customer, Items, UnitPrice
Bob, 5, 1.50
];
Tab2:
LOAD Customer, Sum( Items * UnitPrice ) as Sales
resident Tab1
group by Customer;
drop table Tab1;
| 建立表格 Tab2 後,將捨棄表格 Tab1。 |
// 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';
Drop Mapping Table map1;
Metrics:
Load * Inline [
Transaction ID, Sales Amount, Sales Cost, City, Customer ID
1000012, 4509.33, 1234.22, Oslo, 250v9849
1000013, 1043.21, 180.23, Gothenburg, 195d5930
1000014, 6038.35, 1400.10, Copenhagen, 195d5930
];
| 此範例說明如何使用 Drop mapping table 變體。會建立一個對應表格 map1,然後在後續的 LOAD 陳述式中使用 ApplyMap 函數。對應表格使用後,會從記憶體中捨棄,以最佳化 RAM 使用量,供指令碼執行後續表格中要載入的資料使用。 在此情況下,對應表格中只有少數幾列,RAM 最佳化效果會很小。然而,對於大型對應表格或在迴圈中建立對應表格時,效能可以顯著提升。 |