@Override public void setup(Context context) throws IOException, InterruptedException { LOGGER.info("TopKRollupPhaseOneJob.TopKRollupPhaseOneReducer.setup()"); Configuration configuration = context.getConfiguration(); FileSystem fileSystem = FileSystem.get(configuration); Path configPath = new Path(configuration.get(TOPK_ROLLUP_PHASE1_CONFIG_PATH.toString())); try { starTreeConfig = StarTreeConfig.decode(fileSystem.open(configPath)); config = TopKRollupPhaseOneConfig.fromStarTreeConfig(starTreeConfig); dimensionNames = config.getDimensionNames(); metricTypes = config.getMetricTypes(); metricSchema = new MetricSchema(config.getMetricNames(), metricTypes); metricThresholds = config.getMetricThresholds(); keyWritable = new BytesWritable(); valWritable = new BytesWritable(); MetricSums metricSumsObj = OBJECT_MAPPER.readValue( fileSystem.open( new Path(configuration.get(TOPK_ROLLUP_PHASE1_METRIC_SUMS_PATH.toString()))), MetricSums.class); metricSums = metricSumsObj.getMetricSum(); } catch (Exception e) { throw new IOException(e); } }
@Override public void setup(Context context) throws IOException, InterruptedException { LOGGER.info("TopKRollupPhaseOneJob.TopKRollupPhaseOneMapper.setup()"); Configuration configuration = context.getConfiguration(); FileSystem fileSystem = FileSystem.get(configuration); Path configPath = new Path(configuration.get(TOPK_ROLLUP_PHASE1_CONFIG_PATH.toString())); try { starTreeConfig = StarTreeConfig.decode(fileSystem.open(configPath)); config = TopKRollupPhaseOneConfig.fromStarTreeConfig(starTreeConfig); dimensionNames = config.getDimensionNames(); keyWritable = new BytesWritable(); valWritable = new BytesWritable(); dimensionNameToIndexMapping = new HashMap<String, Integer>(); for (int i = 0; i < dimensionNames.size(); i++) { dimensionNameToIndexMapping.put(dimensionNames.get(i), i); } } catch (Exception e) { throw new IOException(e); } }
@Override public void map(BytesWritable dimensionKeyBytes, BytesWritable aggSeries, Context context) throws IOException, InterruptedException { DimensionKey dimensionKey = DimensionKey.fromBytes(dimensionKeyBytes.getBytes()); String[] dimensionValues = dimensionKey.getDimensionValues(); for (String dimensionName : config.getDimensionNames()) { String dimensionValue = dimensionValues[dimensionNameToIndexMapping.get(dimensionName)]; TopKRollupPhaseOneMapOutputKey keyWrapper; keyWrapper = new TopKRollupPhaseOneMapOutputKey(dimensionName, dimensionValue); byte[] keyBytes = keyWrapper.toBytes(); keyWritable.set(keyBytes, 0, keyBytes.length); context.write(keyWritable, aggSeries); } }