KeyValueStore
mapreduce에서 사용할 키-값 쌍 저장
설명
mapreduce
함수는 실행 중에 자동으로 KeyValueStore
객체를 만들고 이 객체를 사용하여 map 함수와 reduce 함수에 의해 추가된 키-값 쌍을 저장합니다. mapreduce
를 사용하기 위해 KeyValueStore
객체를 명시적으로 만들 필요는 없지만, map 함수와 reduce 함수에서 이 객체와 상호 작용하려면 add
와 addmulti
객체 함수를 사용해야 합니다.
생성
mapreduce
함수는 실행 중에 자동으로 KeyValueStore
객체를 생성합니다.
예제
map 함수에서 KeyValueStore에 키-값 쌍 추가
다음 map 함수는 add
함수를 사용하여 중간 KeyValueStore
객체(intermKVStore
)에 한 번에 하나씩 키-값 쌍을 추가합니다.
function MeanDistMapFun(data, info, intermKVStore) distances = data.Distance(~isnan(data.Distance)); sumLenKey = 'sumAndLength'; sumLenValue = [sum(distances), length(distances)]; add(intermKVStore, sumLenKey, sumLenValue); end
map 함수에서 KeyValueStore에 여러 개의 키-값 쌍 추가
다음 map 함수는 addmulti
를 사용하여 중간 KeyValueStore
객체(intermKVStore
)에 여러 개의 키-값 쌍을 추가합니다. 참고로, 이 map 함수는 intermKeys
변수에 여러 개의 키를 수집하고, intermVals
변수에 여러 개의 값을 수집합니다. 이는 addmulti
를 한 번 호출하여 모든 키-값 쌍을 한 번에 추가하기 위한 준비입니다. add
를 루프에 사용하는 것보다 addmulti
를 한 번 호출하는 것이 모범 사례입니다.
function meanArrivalDelayByDayMapper(data, ~, intermKVStore) % Mapper function for the MeanByGroupMapReduceExample. % Copyright 2014 The MathWorks, Inc. % Data is an n-by-2 table: first column is the DayOfWeek and the second % is the ArrDelay. Remove missing values first. delays = data.ArrDelay; day = data.DayOfWeek; notNaN =~isnan(delays); day = day(notNaN); delays = delays(notNaN); % find the unique days in this chunk [intermKeys,~,idx] = unique(day, 'stable'); % group delays by idx and apply @grpstatsfun function to each group intermVals = accumarray(idx,delays,size(intermKeys),@countsum); addmulti(intermKVStore,intermKeys,intermVals); function out = countsum(x) n = length(x); % count s = sum(x); % mean out = {[n, s]};
확장 기능
스레드 기반 환경
MATLAB®의 backgroundPool
을 사용해 백그라운드에서 코드를 실행하거나 Parallel Computing Toolbox™의 ThreadPool
을 사용해 코드 실행 속도를 높일 수 있습니다.
버전 내역
R2014b에 개발됨
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)