1 package com.daffodilwoods.daffodildb.server.sql99.dql.execution; 2 3 import java.util.*; 4 5 import com.daffodilwoods.daffodildb.server.sql99.common.*; 6 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 7 import com.daffodilwoods.daffodildb.server.sql99.expression.*; 8 import com.daffodilwoods.daffodildb.utils.field.*; 9 import com.daffodilwoods.database.resource.*; 10 import com.daffodilwoods.daffodildb.server.sql99.expression.valueexpression; 11 12 22 public class AggregateCountDistinct implements _Aggregate, Datatypes { 23 24 27 private long count = 0; 28 31 private ArrayList aList; 32 36 private valueexpression column; 37 38 46 public AggregateCountDistinct(valueexpression column0) throws DException { 47 column = column0; 48 GeneralPurposeStaticClass.checkForValidColumnsInAggregatesMaxMinAndCount(column0.getColumnDetails(), "COUNT"); 49 if (column0.getCardinality() != 1) { 50 throw new DException("DSE4119", new Object [] {"AGGREGATE FUNCTION COUNT"}); 51 } 52 aList = new ArrayList(); 53 } 54 55 60 public void initialize() throws DException { 61 count = 0; 62 aList.clear(); 63 } 64 65 71 public Object getResult() throws DException { 72 return new FieldLiteral(new Long (count), LONG); 73 } 74 75 public void releaseResource() throws DException { 76 } 77 public valueexpression getValueExpression() { 78 return column; 79 } 80 81 89 public void addRecord(Object newObject) throws DException{ 90 if (((FieldBase)newObject).isNull()) { 91 return; 92 } 93 if (!aList.contains(((FieldBase)newObject).getObject())) { 94 count++; 95 aList.add(((FieldBase)newObject).getObject()); 96 } 97 } 98 } 99 | Popular Tags |