public void map(WritableComparable key, Writable val, Context context) throws IOException, InterruptedException { try{ Configuration config = context.getConfiguration(); String[] strs = val.toString().split(Constants.HIVE_RECORD_COLUMN_SEPARATOR); String family = config.get(Constants.CUBEBUILDER_CONFIGURATION_FAMILY); String column = strs[COLUMN_INDEX]; String Value = strs[VALUE_INDEX]; String sKey = generateKey(strs, config); byte[] bKey = Bytes.toBytes(sKey); Put put = new Put(bKey); put.add(Bytes.toBytes(family), Bytes.toBytes(column), (value <= 0) ? Bytes.toBytes(Double.MIN_VALUE) : Bytes.toBytes(value)); ImmutableBytesWritable ibKey = new ImmutableBytesWritable(bKey); context.write(ibKey, put); context.getCounter(CubeBuilderContextCounters.CompletedMapExecutions).increment(1); } catch(Exception e){ context.getCounter(CubeBuilderContextCounters.FailedMapExecutions).increment(1); } }
// driver code Configuration config = Configuration.create(); config.setLong("foo.bar.somelong",1337); ... // mapper code public class SomeMapper ... { private long someLong = 0; public void setup(Context context) { Configuration config = context.getConfiguration(); someLong = config.getLong("foo.bar.somelong"); } }
public void map(MD5Hash key, OverlapDataWritable value, Context context) Configuration conf = context.getConfiguration(); String someProperty = conf.get("something"); .... }
public void map(Text key, Text value, Context context) { Configuration conf = context.getConfiguration(); String someParam = conf.get(Constants.SOME_PARAM); // use someParam in processing input }
public void map( IntWritable key, // your key type Text value, // your value type Context context ) { // ... String rowsSerialized = context.getConfiguration().get("CassandraRows"); String[] rows = deserializeRows(rowsSerialized); // TODO: implement deserializer //... }
Extractor extractor = null; protected void setup(Context context) throws IOException, InterruptedException { try { Configuration conf = context.getConfiguration(); String className = conf.get("PrefixExtractorClass"); extractor = Class.forName(className); } Catch (ClassNotFoundException e) { //handle the exception } }
public void setup(Context context) { try { String constructor = context.getConfiguration().get("ExtractorConstructor"); this.extractor = (Extractor) construct(constructor); } catch (Exception e) { throw new RuntimeException(e); } }
@Override protected void setup(Context context) throws IOException, InterruptedException { Path[] uris = DistributedCache.getLocalCacheFiles(context .getConfiguration()); String patternsFile = uris[0].toString(); BufferedReader in = new BufferedReader(new FileReader(patternsFile)); ... in.close(); }
@Override protected void setup(Context context) throws IOException, InterruptedException { FileSystem fs = FileSystem.get(context.getConfiguration()); URI files[]=DistributedCache.getCacheFiles(context.getConfiguration()); Path path = new Path(files[0].toString()); in = fs.open(path); dtree=new DecisionTree().loadTree(in); }
@Override public void setup(Context context) { Configuration conf = context.getConfiguration(); try { cachefiles = DistributedCache.getLocalCacheFiles(conf); File database = new File(cachefiles[0].toString()); reader = new DatabaseReader.Builder(database).build(); } catch (IOException e) { e.printStackTrace(); } }
private StringBuilder getBundleBaseLocation() { StringBuilder bundleBaseLocation = new StringBuilder(context.getConfiguration().getBundleLocation()); if (StringBuilderUtils.isNotBlank(bundleBaseLocation)) { bundleBaseLocation.append('/'); } return bundleBaseLocation; } }
@Override public String getAssetContent(HttpServletRequest request) { Context context = (Context) request.getAttribute(WebConstants.DANDELION_CONTEXT_ATTRIBUTE); logger.debug("Generating asset..."); String generatedContent = getJavascriptContent(request); logger.debug("Asset generated successfully"); if (context.getConfiguration().isToolAssetPrettyPrintingEnabled()) { return ScriptingUtils.prettyPrintJs(generatedContent); } return generatedContent; }
@Override public boolean isApplicable(HandlerContext handlerContext) { HttpServletResponse wrappedResponse = handlerContext.getResponse(); HttpServletRequest request = handlerContext.getRequest(); boolean isJsProcessingEnabled = handlerContext.getContext().getConfiguration().isAssetJsProcessingEnabled(); boolean isHtmlRequest = wrappedResponse.getContentType() != null && wrappedResponse.getContentType().contains("text/html"); boolean notBrowsingDebugger = !request.getRequestURI().contains("ddl-debugger"); return isJsProcessingEnabled && isHtmlRequest && notBrowsingDebugger; }
@Override public boolean isApplicable(HandlerContext handlerContext) { HttpServletResponse wrappedResponse = handlerContext.getResponse(); HttpServletRequest request = handlerContext.getRequest(); boolean isJsProcessingEnabled = handlerContext.getContext().getConfiguration().isAssetJsProcessingEnabled(); boolean isHtmlRequest = wrappedResponse.getContentType() != null && wrappedResponse.getContentType().contains("text/html"); boolean notBrowsingDebugger = !request.getRequestURI().contains("ddl-debugger"); return isJsProcessingEnabled && isHtmlRequest && notBrowsingDebugger; }
@Override public BundleLoader getBundleLoader(Context context) { if (context.getConfiguration().getComponentsStandalone().contains(COMPONENT_NAME)) { return new DatatableBundleLoader(context, true); } else { return new DatatableBundleLoader(context, false); } }
@Override public boolean isApplicable(HandlerContext handlerContext) { return handlerContext.getContext().getConfiguration().isToolDebuggerEnabled() && handlerContext.getRequest().getParameter(WebConstants.DANDELION_CLEAR_STORAGE) != null; }
@Override public boolean isApplicable(HandlerContext handlerContext) { return handlerContext.getContext().getConfiguration().isToolDebuggerEnabled() && handlerContext.getRequest().getParameter(WebConstants.DANDELION_CLEAR_CACHE) != null; }
@Override public void initCache(Context context) { super.initCache(context); mapRequestAssets = new ConcurrentLruCache<String, CacheEntry>(context.getConfiguration().getCacheMaxSize()); }
@Override public void initCache(Context context) { super.initCache(context); mapRequestAssets = new ConcurrentLruCache<String, CacheEntry>(context.getConfiguration().getCacheMaxSize()); }
@Override public void setup(Context context) throws IOException, InterruptedException{ Configuration conf = context.getConfiguration(); Cluster cluster = new Cluster(conf); Job currentJob = cluster.getJob(context.getJobID()); mapperCounter = currentJob.getCounters().findCounter(COUNTER_NAME).getValue(); }