1 package com.calipso.reportgenerator.reportcalculator; 2 3 import com.calipso.reportgenerator.common.ReportMetricSpec; 4 import com.calipso.reportgenerator.common.InfoException; 5 6 import java.util.Set ; 7 import java.util.HashSet ; 8 9 15 public class CountDistinctStrategy extends MetricCalculationStrategy { 16 private ReportMetricSpec metricSpec; 17 int dimensionIndex; 18 19 public CountDistinctStrategy(ReportMetricSpec metricSpec) { 20 this.metricSpec = metricSpec; 21 dimensionIndex = Integer.valueOf(metricSpec.getAggregateFunction()).intValue(); 22 } 23 24 public Object operate(Object [] node, int index, Object measure, Object [] row) { 25 if(node[index]!=null){ 26 if(node[index] instanceof SharedFloat && ((Float )((SharedFloat)node[index]).getValue()).isNaN()){ 27 node[index] = new HashSet (); 28 } 29 ((Set )node[index]).add(row[dimensionIndex]); 30 return node[index]; }else{ 32 measure = new HashSet (); 33 ((Set )measure).add(row[dimensionIndex]); 34 return measure; 35 } 36 } 37 38 public String getSQLFunction() throws InfoException { 39 return BasicSQLConstants.COUNT_DISTINCT; 40 } 41 42 } 43 | Popular Tags |