Source:
<code>public Tuple exec(Tuple input) throws IOException { if (input == null || input.size() == 0) { return null; } Tuple groupInfo = (Tuple) input.get(0); DataBag bag = (DataBag) input.get(1); Integer columnId = (Integer) groupInfo.get(1); String groupStr = ""; for(int i = 0; i < groupInfo.size(); i++){ groupStr += groupInfo.get(i) + ","; } ColumnConfig columnConfig = columnConfigList.get(columnId); logger.info("PopulationCounterSaltUDF: Start to count bin value count for {}, bag size {}, group info {}", columnConfig.getColumnName(), bag.size(), groupStr); if ( columnConfig.isCategorical() && CollectionUtils.isNotEmpty(columnConfig.getBinCategory()) ) { this.counter = new CategoryCounter(modelConfig.getMissingOrInvalidValues(), columnConfig.getBinCategory(), columnConfig.getBinPosRate()); } else if (columnConfig.isNumerical() && CollectionUtils.isNotEmpty(columnConfig.getBinBoundary()) ) { this.counter = new NumericCounter(modelConfig.getMissingOrInvalidValues(), columnConfig.getColumnName(), columnConfig.getBinBoundary()); } else { return null; } Iterator<Tuple> iter = bag.iterator(); while (iter.hasNext()) { Tuple tuple = iter.next(); if (tuple != null && tuple.size() != 0) { Object value = tuple.get(index); Boolean tag = (Boolean) tuple.get(index + 1); counter.addData(tag, (value == null) ? null : value.toString()); } } Tuple output = TupleFactory.getInstance().newTuple(5); output.set(0, columnId); output.set(1, counter.getBinLen()); output.set(2, counter.getUnitSum()); output.set(3, StringUtils.join(Longs.asList(counter.getPositiveCounter()), CalculateStatsUDF.CATEGORY_VAL_SEPARATOR)); output.set(4, StringUtils.join(Longs.asList(counter.getNegativeCounter()), CalculateStatsUDF.CATEGORY_VAL_SEPARATOR)); String outputStr = ""; for(int i = 0; i < output.size(); i++){ <START> outputStr += output.get(i).toString() + ","; <END> } return output; }</code><technical_language>For string list of counter, large ~10k categories, Stringbuilder</technical_language>

Target:
public Tuple exec(Tuple input) throws IOException { if (input == null || input.size() == 0) { return null; } Tuple groupInfo = (Tuple) input.get(0); DataBag bag = (DataBag) input.get(1); Integer columnId = (Integer) groupInfo.get(1); ColumnConfig columnConfig = columnConfigList.get(columnId); logger.info("PopulationCounterSaltUDF: Start to count bin value count for {}, bag size {}", columnConfig.getColumnName(), bag.size()); if ( columnConfig.isCategorical() && CollectionUtils.isNotEmpty(columnConfig.getBinCategory()) ) { this.counter = new CategoryCounter(modelConfig.getMissingOrInvalidValues(), columnConfig.getBinCategory(), columnConfig.getBinPosRate()); } else if (columnConfig.isNumerical() && CollectionUtils.isNotEmpty(columnConfig.getBinBoundary()) ) { this.counter = new NumericCounter(modelConfig.getMissingOrInvalidValues(), columnConfig.getColumnName(), columnConfig.getBinBoundary()); } else { return null; } Iterator<Tuple> iter = bag.iterator(); while (iter.hasNext()) { Tuple tuple = iter.next(); if (tuple != null && tuple.size() != 0) { Object value = tuple.get(index); Boolean tag = (Boolean) tuple.get(index + 1); counter.addData(tag, (value == null) ? null : value.toString()); } } Tuple output = TupleFactory.getInstance().newTuple(5); output.set(0, columnId); output.set(1, counter.getBinLen()); output.set(2, counter.getUnitSum()); output.set(3, StringUtils.join(Longs.asList(counter.getPositiveCounter()), CalculateStatsUDF.CATEGORY_VAL_SEPARATOR)); output.set(4, StringUtils.join(Longs.asList(counter.getNegativeCounter()), CalculateStatsUDF.CATEGORY_VAL_SEPARATOR)); return output; }