public int run(String[] args) throws Exception {
    if (args.length < 1) {
      args = new String[] {DateStringUtils.now()};
      System.out.println(
          "ERROR: Please Enter Date , eg. 20101010 ! now use default => " + DateStringUtils.now());
    }

    JobConf config = new JobConf(getConf(), getClass());
    config.set("user.args", Utils.asString(args));

    config.setJobName(getClass() + "-" + System.currentTimeMillis());
    config.setNumReduceTasks(100);
    config.setMapperClass(getClass());
    config.setReducerClass(getClass());
    config.setInputFormat(getInputFormat());
    config.setMapOutputKeyClass(Text.class);
    config.setMapOutputValueClass(Text.class);

    // add input paths
    for (String path : getInputPath(args)) {
      if (TextInputFormat.class.equals(getInputFormat())) {
        TextInputFormat.addInputPath(config, new Path(path));
      } else if (SequenceFileInputFormat.class.equals(getInputFormat())) {
        SequenceFileInputFormat.addInputPath(config, new Path(path));
      }
    }

    config.setOutputKeyClass(Text.class);
    config.setOutputValueClass(Text.class);

    // if output path exists then return
    FileSystem fs = FileSystem.get(config);
    Path outputPath = new Path(getOutputPath(args));
    FileOutputFormat.setOutputPath(config, outputPath);

    if (!fs.exists(outputPath)) {
      JobClient.runJob(config);
    } else {
      System.out.println("You has finished this job today ! " + outputPath);
    }

    return JobClient.SUCCESS;
  }
Exemple #2
0
  @Override
  protected void doWork(String line, OutputCollector<Text, LongWritable> output)
      throws IOException {
    String[] _allCols = StringUtils.splitPreserveAllTokens(line, TAB);
    if (_allCols.length < 47) {
      return;
    }
    String queryDate = DateStringUtils.format(inputArgs[0]);
    String gmtCreated = _allCols[TcBizOrder.GMT_CREATE];
    String payTime = _allCols[TcBizOrder.PAY_TIME];
    String gmtModified = _allCols[TcBizOrder.GMT_MODIFIED];
    if (Utils.isSameDay(queryDate, gmtCreated)) {
      output.collect(Utils.mergeKey("t", "sys", "created"), ONE);
      output.collect(Utils.mergeKey("d", "sys", "created", "m", getMinutes(gmtCreated)), ONE);
      output.collect(Utils.mergeKey("d", "sys", "created", "s", gmtCreated), ONE);
    }
    if (Utils.isSameDay(queryDate, gmtModified)) {
      output.collect(Utils.mergeKey("t", "sys", "modified"), ONE);
    }

    // filter not effective order
    if (!TcBizOrder.isEffective(_allCols)) {
      return;
    }

    if (TcBizOrder.isMain(_allCols)) {
      commonMonitor("all", _allCols, output, queryDate);
      if (TcBizOrder.isB2C(_allCols)) {
        commonMonitor("b2c", _allCols, output, queryDate);
      } else {
        commonMonitor("c2c", _allCols, output, queryDate);
      }
      if (TcBizOrder.isFromTgroupon(_allCols)) {
        commonMonitor("jhs", _allCols, output, queryDate);
      }
      if (Utils.isSameDay(payTime, queryDate)) {
        long fee = TcBizOrder.getTotalFee(_allCols);
        String key = alipayTradeArea.getArea(fee);
        output.collect(Utils.mergeKey("t", "alipay_area", key), ONE);
      }
    }
    if (TcBizOrder.isDetail(_allCols)) {
      String rootCatId = Utils.getValue(_allCols[TcBizOrder.ATTRIBUTES], "realRootCat", "NULL");
      commonTotalMonitor("cat", rootCatId, _allCols, output, queryDate);
    }
  }
 public static boolean isSameTime(String begin, String end) {
   long s = Math.abs(DateStringUtils.second(begin, end, DATETIME_STYLE));
   return s <= 1800;
 }