updated the fix for issue 412: now the test is working in both integration test and web ui.
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/scalar/AbstractScalarAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/scalar/AbstractScalarAggregateDescriptor.java
index 3de05f8..232eace 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/scalar/AbstractScalarAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/scalar/AbstractScalarAggregateDescriptor.java
@@ -20,21 +20,23 @@
 
     @Override
     public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+
+        // The aggregate function will get a SingleFieldFrameTupleReference that points to the result of the ScanCollection.
+        // The list-item will always reside in the first field (column) of the SingleFieldFrameTupleReference.
+        ICopyEvaluatorFactory[] aggFuncArgs = new ICopyEvaluatorFactory[1];
+        aggFuncArgs[0] = new ColumnAccessEvalFactory(0);
+        // Create aggregate function from this scalar version.
+        FunctionIdentifier fid = AsterixBuiltinFunctions.getAggregateFunction(getIdentifier());
+        IFunctionManager mgr = FunctionManagerHolder.getFunctionManager();
+        IFunctionDescriptor fd = mgr.lookupFunction(fid);
+        AbstractAggregateFunctionDynamicDescriptor aggFuncDesc = (AbstractAggregateFunctionDynamicDescriptor) fd;
+        final ICopyAggregateFunctionFactory aggFuncFactory = aggFuncDesc.createAggregateFunctionFactory(aggFuncArgs);
+
         return new ICopyEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
             public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
-                // The aggregate function will get a SingleFieldFrameTupleReference that points to the result of the ScanCollection.
-                // The list-item will always reside in the first field (column) of the SingleFieldFrameTupleReference.
-                ICopyEvaluatorFactory[] aggFuncArgs = new ICopyEvaluatorFactory[1];
-                aggFuncArgs[0] = new ColumnAccessEvalFactory(0);
-                // Create aggregate function from this scalar version.
-                FunctionIdentifier fid = AsterixBuiltinFunctions.getAggregateFunction(getIdentifier());
-                IFunctionManager mgr = FunctionManagerHolder.getFunctionManager();
-                IFunctionDescriptor fd = mgr.lookupFunction(fid);
-                AbstractAggregateFunctionDynamicDescriptor aggFuncDesc = (AbstractAggregateFunctionDynamicDescriptor) fd;
-                ICopyAggregateFunctionFactory aggFuncFactory = aggFuncDesc.createAggregateFunctionFactory(aggFuncArgs);
                 // Use ScanCollection to iterate over list items.
                 ScanCollectionUnnestingFunctionFactory scanCollectionFactory = new ScanCollectionUnnestingFunctionFactory(
                         args[0]);