Exemplo n.º 1
0
    private final void populateFieldFromFullyQualifiedColumn(
        T entity, Field field, KijiColumn column, KijiRowData row)
        throws IOException, IllegalAccessException {

      if (column.maxVersions() == 1) {
        // Field represents a single value from a fully-qualified column:
        LOG.debug(
            "Populating field '{}' from column '{}:{}'.",
            field,
            column.family(),
            column.qualifier());
        KijiCell<?> cell = row.getMostRecentCell(column.family(), column.qualifier());
        if (cell == null) return;
        Object value = cell.getData();

        if (field.getType() == KijiCell.class) {
          value = cell;
        } else if (field.getType() == String.class && value != null) {
          value = value.toString();
        }

        // If there is no cell for a field with a primitive type, use the default value:
        if ((null == value) && field.getType().isPrimitive()) {
          value = Defaults.defaultValue(field.getType());
        }

        field.set(entity, value);
      } else {
        // Field represents a time-series from a fully-qualified column:
        if (column.pageSize() > 0) {
          final ColumnVersionIterator<?> iterator =
              new ColumnVersionIterator<Object>(
                  row, column.family(), column.qualifier(), column.pageSize());
          field.set(entity, iterator);
        } else {
          Object value = null;
          if (field.getType() == KijiCellValueIterator.class) {
            value =
                new KijiCellValueIterator<Object>(
                    row.iterator(column.family(), column.qualifier()));
          } else if (field.getType() == TimeSeries.class) {
            final TimeSeries<Object> timeseries = new TimeSeries<Object>();
            for (final KijiCell<Object> cell :
                row.asIterable(column.family(), column.qualifier())) {
              timeseries.put(cell.getTimestamp(), cell.getData());
            }
            value = timeseries;
          }
          field.set(entity, value);
        }
      }
    }
Exemplo n.º 2
0
  @Override
  public void gather(KijiRowData kijiRowData, GathererContext gathererContext) throws IOException {
    rows++;
    if (rows % 5000 == 0) {
      LOG.info("Processed row: " + rows);
    }
    try {
      // After 2005, before the future plus 10 minutes to allow for clock misalignments
      checkLong(
          kijiRowData.getMostRecentCell("data", "match_id").getTimestamp(),
          "start_time",
          1104537600,
          System.currentTimeMillis() + 60000);
      for (String team : TEAMS) {
        Integer towerStatus = kijiRowData.getMostRecentValue("data", team + "_towers_status");
        checkInt(towerStatus, team + "_tower_status", 0, ((Double) Math.pow(2, 11)).intValue());
      }
      for (String team : TEAMS) {
        Integer raxStatus = kijiRowData.getMostRecentValue("data", team + "_barracks_status");
        checkInt(raxStatus, team + "_barracks_status", 0, ((Double) Math.pow(2, 6)).intValue());
      }
      checkInt(
          (Integer) kijiRowData.getMostRecentValue("data", "human_players"),
          "human_players",
          0,
          10);

      DotaValues.LobbyType.fromInt((Integer) kijiRowData.getMostRecentValue("data", "lobby_type"));
      DotaValues.GameMode.fromInt((Integer) kijiRowData.getMostRecentValue("data", "game_mode"));
      for (String s :
          new String[] {"cluster", "season", "duration", "negative_votes", "positive_votes"}) {
        Integer n = kijiRowData.getMostRecentValue("data", s);
        checkInt(n, s, 0, Integer.MAX_VALUE / 2);
      }
      checkInt(
          (Integer) kijiRowData.getMostRecentValue("data", "league_id"),
          "league_id",
          0,
          Integer.MAX_VALUE);
      Players players = kijiRowData.getMostRecentValue("data", "player_data");
      for (Player player : players.getPlayers()) {
        Integer n = player.getAccountId();
        if (n != null) {
          if (n != -1) {
            checkInt(n, "account_id", 0, Integer.MAX_VALUE);
          }
        }
        DotaValues.LeaverStatus.fromInt(player.getLeaverStatus());
        checkInt(player.getAssists(), "assists", 0, 1000);
        checkInt(player.getDeaths(), "deaths", 0, 1000);
        checkInt(player.getDenies(), "denies", 0, 5000);
        checkInt(player.getGold(), "gold", 0, 10000);
        checkInt(player.getGoldSpent(), "gold_spent", 0, 1000000);
        checkInt(player.getHeroDamage(), "hero_damage");
        checkInt(player.getHeroHealing(), "hero_healing");
        checkInt(player.getHeroId(), "hero_id", 0, 200);
        checkInt(player.getKills(), "kills", 0, 1000);
        checkInt(player.getLastHits(), "last_hits", 0, 10000);
        checkInt(player.getPlayerSlot(), "player_slot", 0, 256);
        checkInt(player.getLevel(), "level", 0, 25);
        checkDouble(player.getGoldPerMinute(), "gold_per_minute", 0, 200000);
        checkDouble(player.getExpPerMinute(), "exp_per_minute", 0, 200000);
        List<AbilityUpgrade> aus = player.getAbilityUpgrades();
        checkInt(aus.size(), "ability upgrade size", 0, 25);
        for (AbilityUpgrade au : aus) {
          checkInt(au.getLevel(), "ability upgrade level", 0, 25);
          checkInt(au.getTime(), "ability upgrade time", 0, 1000000);
          checkInt(au.getAbilityId(), "ability id");
        }
      }
    } catch (RuntimeException re) {
      gathererContext.write(new Text(re.getMessage()), ONE);
    }
  }