Ejemplo n.º 1
0
 protected void setup(Context context) throws IOException, InterruptedException {
   // TODO Auto-generated method stub
   super.setup(context);
   this.dimIpRuleDAO = new DMIPRuleDAOImpl<Long, Map<ConstantEnum, String>>();
   this.dimIpRuleDAO.parseDMObj(new File(ConstantEnum.IP_TABLE.name().toLowerCase()));
   this.flagId = context.getConfiguration().get("flags");
 }
    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
      // TODO Auto-generated method stub
      super.setup(context);

      InputSplit split = context.getInputSplit();

      System.out.println("***************Mapper's setup is being executed***************");
      FileSplit FS = (FileSplit) split;

      long datastart = FS.getStart();
      System.out.println("***************GetStart() returns " + datastart + " ***************");

      long datalongth = FS.getLength();
      System.out.println("***************getLength() returns " + datalongth + " ***************");

      String[] datalocations = FS.getLocations();
      System.out.println(
          "***************getLocations() returns "
              + datalocations.length
              + " locations***************");

      for (int i = 0; i < datalocations.length; i++) {
        System.out.println(
            "***************No." + i + " location is : " + datalocations[i] + " ***************");
      }

      Path path = FS.getPath();
      System.out.println(
          "***************getLocations() returns " + path.toString() + " ***************");
    }
Ejemplo n.º 3
0
    /*
     * 将文档中心从hdfs中加载至内存
     */
    protected void setup(Context context) throws IOException, InterruptedException { // 读取中心点向量数据
      Configuration conf = context.getConfiguration();
      Path cents = new Path(CENT_PATH);
      // FileSystem fs = FileSystem.get(conf);
      FileSystem fs = cents.getFileSystem(conf);

      SequenceFile.Reader reader = new SequenceFile.Reader(fs, cents, conf);
      Text key = new Text(); // 读取题号
      Text value = new Text(); // 读取题号对应的单词=TFIDF,单词=TFIDF
      while (reader.next(key, value)) {
        Map<String, Double> tfidfAndword = new HashMap<String, Double>(); // 存储TFIDF和单词
        String[] strs = null;
        Pattern p = Pattern.compile("\"([^\"]+)\"=([^,}]+)"); // 正则匹配取出:单词和TFIDF
        Matcher m = p.matcher(value.toString());
        while (m.find()) {
          strs = m.group().split("=");
          if (strs.length == 2) {
            tfidfAndword.put(
                strs[0].replace("\"", "").trim(),
                Double.parseDouble(strs[1].replace("}", "").trim()));
          }
        }
        centers.put(key.toString(), tfidfAndword);
      }
      reader.close();

      super.setup(context);
    }
Ejemplo n.º 4
0
 /**
  * Expert users can override this method for more complete control over the execution of the
  * Mapper.
  *
  * @param context
  * @throws IOException
  */
 public void run(Context context) throws IOException, InterruptedException {
   setup(context);
   while (context.nextKeyValue()) {
     map(context.getCurrentKey(), context.getCurrentValue(), context);
   }
   cleanup(context);
 }
Ejemplo n.º 5
0
    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
      super.setup(context);

      Configuration conf = context.getConfiguration();
      keyLength = conf.getInt(KEYLEN_CONF, KEYLEN_DEFAULT);
      valLength = conf.getInt(VALLEN_CONF, VALLEN_DEFAULT);
    }
 @Override
 protected void setup(Mapper.Context context) throws IOException, InterruptedException {
   super.setup(context);
   logger.info("in setup of " + context.getTaskAttemptID().toString());
   String fileName = ((FileSplit) context.getInputSplit()).getPath() + "";
   System.out.println("in stdout" + context.getTaskAttemptID().toString() + " " + fileName);
   System.err.println("in stderr" + context.getTaskAttemptID().toString());
 }
Ejemplo n.º 7
0
  /** {@inheritDoc} */
  @Override
  protected void setup(Context ctx) throws IOException, InterruptedException {
    super.setup(ctx);

    wasSetUp = true;

    HadoopErrorSimulator.instance().onMapSetup();
  }
 @Override
 protected void setup(Context context) throws IOException, InterruptedException {
   super.setup(context);
   Configuration conf = context.getConfiguration();
   measure =
       ClassUtils.instantiateAs(
           conf.get(RepresentativePointsDriver.DISTANCE_MEASURE_KEY), DistanceMeasure.class);
   representativePoints = getRepresentativePoints(conf);
 }
    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
      super.setup(context);

      final Configuration conf = context.getConfiguration();

      // get permissible file extensions from the configuration
      Extensions.clear();
      Extensions.addAll(conf.getStringCollection("extensions"));
    }
 @Override
 protected void setup(Context context) throws IOException, InterruptedException {
   super.setup(context);
   batchID = context.getConfiguration().get(ConfigConstants.BATCH_ID);
   commandPath = context.getConfiguration().get(HADOOP_CONVERTER_PATH);
   String outputFolder = context.getConfiguration().get(HADOOP_CONVERTER_OUTPUT_PATH);
   resultExtention = context.getConfiguration().get(HADOOP_CONVERTER_OUTPUT_EXTENSION_PATH);
   batchFolder = new File(outputFolder, batchID);
   batchFolder.mkdirs();
 }
Ejemplo n.º 11
0
 @Override
 protected void setup(Context context) throws IOException, InterruptedException {
   super.setup(context);
   configuration = context.getConfiguration();
   connection = HConnectionManager.createConnection(configuration);
   table = connection.getTable("");
   table.setAutoFlush(false, true);
   table.setWriteBufferSize(12 * 1024 * 1024);
   wal = true;
 }
Ejemplo n.º 12
0
    @Override
    protected void setup(Context context) throws IOException, InterruptedException {

      super.setup(context);

      id = context.getTaskAttemptID().getTaskID().getId();
      increment = context.getConfiguration().getInt("mapred.map.tasks", 0);
      if (increment == 0) {
        throw new IllegalArgumentException("mapred.map.tasks is zero");
      }
    }
Ejemplo n.º 13
0
 @Override
 protected void setup(Context context) throws IOException, InterruptedException {
   super.setup(context);
   filter =
       PcapFilters.valueOf(
               context.getConfiguration().get(PcapFilterConfigurator.PCAP_FILTER_NAME_CONF))
           .create();
   filter.configure(context.getConfiguration());
   start = Long.parseUnsignedLong(context.getConfiguration().get(START_TS_CONF));
   end = Long.parseUnsignedLong(context.getConfiguration().get(END_TS_CONF));
 }
 @Override
 protected void setup(Context context) throws IOException, InterruptedException {
   super.setup(context);
   Configuration config = context.getConfiguration();
   log.info("*** MAPPER PATH -> " + config.get(ProClusConfigKeys.SET_PATH));
   Path medoidsSetPath = new Path(config.get(ProClusConfigKeys.SET_PATH));
   try {
     medoidSet = readMedoidsSet(medoidsSetPath, config);
   } catch (Exception e) {
     log.error("Error reading medoid set in mapper ", e);
   }
 }
Ejemplo n.º 15
0
    protected void setup(Context context) throws IOException, InterruptedException {
      super.setup(context);

      Path pt = new Path("/user/yao/query/query");
      FileSystem fs = FileSystem.get(new Configuration());
      BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(pt)));
      String line = br.readLine();
      String[] keywords = line.split(",");
      k0 = keywords[0];
      k1 = keywords[1];
      k2 = keywords[2];
      br.close();
    }
Ejemplo n.º 16
0
  @Override
  public void setup(Context context) throws IOException, InterruptedException {
    super.setup(context);
    String fieldStrs = context.getConfiguration().get("higo.index.fields");
    split = context.getConfiguration().get("higo.column.split", split);
    String custfields = context.getConfiguration().get("higo.column.custfields", "");
    usedthedate = context.getConfiguration().getBoolean("higo.column.userthedate", usedthedate);
    this.thedate = null;
    if (usedthedate) {
      InputSplit inputSplit = context.getInputSplit();
      Path filepath = ((FileSplit) inputSplit).getPath();
      String inputbase = context.getConfiguration().get("higo.input.base");
      this.thedate = JobIndexPublic.parseThedate(new Path(inputbase), filepath);
      System.out.println(
          "thedatepath: " + thedate + "@" + filepath.toString() + "@" + inputbase + "");
    }

    if (custfields == null || custfields.isEmpty()) {

      String[] fieldslist = fieldStrs.split(",");
      this.fields = new String[fieldslist.length];
      this.isDate = new Boolean[fieldslist.length];
      this.isString = new Boolean[fieldslist.length];
      this.isStore = new Boolean[fieldslist.length];

      for (int i = 0; i < fieldslist.length; i++) {
        String[] fieldSchema = fieldslist[i].split(":");
        String fieldName = fieldSchema[0].trim().toLowerCase();
        String type = fieldSchema[1];
        this.isStore[i] = Boolean.valueOf(fieldSchema[3]);
        this.fields[i] = fieldName;
        this.isDate[i] = type.equalsIgnoreCase("tdate");
        this.isString[i] = type.equalsIgnoreCase("string");
      }
    } else {
      String[] fieldslist = custfields.split(",");
      this.fields = new String[fieldslist.length];
      this.isDate = new Boolean[fieldslist.length];
      this.isString = new Boolean[fieldslist.length];
      this.isStore = new Boolean[fieldslist.length];

      for (int i = 0; i < fieldslist.length; i++) {
        this.isStore[i] = Boolean.valueOf(false);
        this.fields[i] = fieldslist[i];
        this.isDate[i] = false;
        this.isString[i] = true;
      }
    }
  }
Ejemplo n.º 17
0
 @Override
 protected void setup(Context context) throws IOException, InterruptedException {
   // TODO Auto-generated method stub
   super.setup(context);
   String json = context.getConfiguration().get("m");
   model = new Gson().fromJson(json, OPEModel.class);
   String l = context.getConfiguration().get("l");
   String r = context.getConfiguration().get("r");
   int i = l.indexOf(":");
   left = Double.parseDouble(l.substring(0, i));
   bl = l.substring(i + 1);
   i = r.indexOf(":");
   right = Double.parseDouble(r.substring(0, i));
   br = r.substring(i + 1);
   li = model.cIndex(left);
   ri = model.cIndex(right);
 }
Ejemplo n.º 18
0
    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
      super.setup(context);
      Configuration conf = context.getConfiguration();
      Path centroids = new Path(conf.get(CENTERS_CONF_KEY));
      FileSystem fs = FileSystem.get(conf);

      SequenceFile.Reader reader = new SequenceFile.Reader(fs, centroids, conf);

      Centroid key = new Centroid();
      IntWritable value = new IntWritable();
      while (reader.next(key, value)) {
        Centroid clusterCenter = new Centroid(key);
        centers.add(clusterCenter);
      }
      reader.close();
    }
Ejemplo n.º 19
0
 protected void setup(Context context) throws IOException, InterruptedException {
   super.setup(context);
   scriptEngine = scriptEngineManager.getEngineByName("JavaScript");
   try {
     Configuration configuration = context.getConfiguration();
     mapOutputKey = MrUtils.getWritableComparableType("js.map.output.key.type", configuration);
     mapOutputValue = MrUtils.getWritableComparableType("js.map.output.value.type", configuration);
     scriptEngine.eval(
         MrUtils.getScripts(
             context.getConfiguration(), MrUtils.getPathFilter("js.map.filename", configuration)));
     scriptEngine.put("mapOutputKey", mapOutputKey);
     scriptEngine.put("mapOutputValue", mapOutputValue);
     OUTPUT_KEY_CLASS = mapOutputKey.getClass();
     OUTPUT_VALUE_CLASS = mapOutputValue.getClass();
   } catch (ScriptException se) {
     IOException ioe = new IOException(se);
     ioe.setStackTrace(se.getStackTrace());
     throw ioe;
   }
 }
Ejemplo n.º 20
0
    @SuppressWarnings("deprecation")
    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
      super.setup(context);
      _currKMeansClusters.clear();
      _currCanopyClusters.clear();

      Configuration conf = context.getConfiguration();
      Path centroids = new Path(conf.get("centers.path"));
      FileSystem fs = FileSystem.get(conf);
      SequenceFile.Reader reader = new SequenceFile.Reader(fs, centroids, conf);

      Cluster canopyCenter = new Cluster();
      Cluster kMeansCenter = new Cluster();

      while (reader.next(canopyCenter, kMeansCenter)) {
        _currKMeansClusters.add(new Cluster(kMeansCenter));
        _currCanopyClusters.add(new Cluster(canopyCenter));
      }

      reader.close();
    }
Ejemplo n.º 21
0
  @Override
  protected void setup(Context context) throws IOException, InterruptedException {
    super.setup(context);

    // read the centroids from all the files
    for (int i = 0; i < 5; i++) {
      Path path = new Path("/kmeansDM/centroid/centroid_" + i + ".txt");
      FileSystem fs = FileSystem.get(new Configuration());
      BufferedReader bf = new BufferedReader(new InputStreamReader(fs.open(path)));
      String centroidsLine = bf.readLine();
      String[] arr = centroidsLine.split("\t");
      if (initDone == false) {
        centroidsList = new double[5][arr.length];
        initDone = true;
      }
      for (int j = 0; j < arr.length; j++) {
        centroidsList[i][j] = Double.parseDouble(arr[j].trim());
      }
      bf.close();
      // fs.close();
    }
  }
  @Override
  protected void setup(Context context) throws IOException, InterruptedException {
    super.setup(context);
    // load invalid characters
    invalid = new ArrayList<String>();
    BufferedReader br =
        new BufferedReader(
            new InputStreamReader(
                SearchKeywordMapper.class.getResourceAsStream(Const.INVALID_CHARACTOR_PATH)));
    String line = null;
    while (null != (line = br.readLine())) {
      line = line.trim();
      invalid.add(line);
    }
    br.close();

    String column = context.getConfiguration().get("conf.column");
    byte[][] colkey = KeyValue.parseColumn(Bytes.toBytes(column));
    family = colkey[0];
    if (colkey.length > 1) {
      qualifier = colkey[1];
    }
  }
Ejemplo n.º 23
0
    protected void setup(Context context) throws IOException, InterruptedException {
      super.setup(context);
      this.dmIPRuleDAO = new DMIPRuleDAOImpl<Long, Map<ConstantEnum, String>>();
      this.dmOuterURLRuleDAO = new DMOuterURLRuleImpl<String, Map<ConstantEnum, String>>();
      this.dmKeywordRuleDAO = new DMKeywordRuleDAOImpl<String, Map<ConstantEnum, String>>();
      this.dmInterURLRuleDAO = new DMInterURLImpl();

      this.dmIPRuleDAO.parseDMObj(new File(ConstantEnum.IP_TABLE.name().toLowerCase()));
      this.dmOuterURLRuleDAO.parseDMObj(new File(ConstantEnum.DM_OUTER_URL.name().toLowerCase()));
      this.dmInterURLRuleDAO.parseDMObj(new File(ConstantEnum.DM_INTER_URL.name().toLowerCase()));
      this.dmKeywordRuleDAO.parseDMObj(
          new File(ConstantEnum.DM_URL_KEYWORD_2.name().toLowerCase()));

      multipleOutputs = new MultipleOutputs<Text, Text>(context);

      dateId = context.getConfiguration().get("dateid");

      keyText = new Text();
      valueText = new Text();

      FileSplit fileSplit = (FileSplit) context.getInputSplit();
      filePath = fileSplit.getPath().getParent().toString();
    }
Ejemplo n.º 24
0
  @Override
  protected void setup(final Context context) throws IOException, InterruptedException {
    super.setup(context);
    final Configuration configuration = context.getConfiguration();
    writer = new DirectHTableWriter(configuration);

    try {
      indxTblColumnMetadata = PhoenixConfigurationUtil.getUpsertColumnMetadataList(configuration);
      indxWritable.setColumnMetadata(indxTblColumnMetadata);

      final Properties overrideProps = new Properties();
      String scn = configuration.get(PhoenixConfigurationUtil.CURRENT_SCN_VALUE);
      String txScnValue = configuration.get(PhoenixConfigurationUtil.TX_SCN_VALUE);
      if (txScnValue == null) {
        overrideProps.put(PhoenixRuntime.CURRENT_SCN_ATTRIB, scn);
      }
      connection = ConnectionUtil.getOutputConnection(configuration, overrideProps);
      connection.setAutoCommit(false);
      // Get BatchSize
      ConnectionQueryServices services = ((PhoenixConnection) connection).getQueryServices();
      int maxSize =
          services
              .getProps()
              .getInt(
                  QueryServices.MAX_MUTATION_SIZE_ATTRIB,
                  QueryServicesOptions.DEFAULT_MAX_MUTATION_SIZE);
      batchSize = Math.min(((PhoenixConnection) connection).getMutateBatchSize(), maxSize);
      LOG.info("Mutation Batch Size = " + batchSize);

      final String upsertQuery = PhoenixConfigurationUtil.getUpsertStatement(configuration);
      this.pStatement = connection.prepareStatement(upsertQuery);

    } catch (SQLException e) {
      throw new RuntimeException(e.getMessage());
    }
  }
Ejemplo n.º 25
0
 @Override
 protected void setup(Context context) throws IOException, InterruptedException {
   super.setup(context);
   this.tracing = LOG.isTraceEnabled();
 }
 @Override
 protected void setup(Context context) throws IOException, InterruptedException {
   super.setup(context);
   String[] topWordsArr = context.getConfiguration().getStrings(TOP_WORDS_KEY);
   topWords = ImmutableSet.copyOf(topWordsArr);
 }
Ejemplo n.º 27
0
 @Override
 protected void setup(Context context) throws IOException, InterruptedException {
   super.setup(context);
   fileName = ((FileSplit) context.getInputSplit()).getPath().getName();
 }
Ejemplo n.º 28
0
 @Override
 protected void setup(Context context) throws IOException, InterruptedException {
   super.setup(context);
 }