Examples of AggregateFunction


Examples of org.teiid.language.AggregateFunction

     * @since 4.3
     */
    @Override
    public List<?> translate(LanguageObject obj, ExecutionContext context) {
      if (obj instanceof AggregateFunction) {
        AggregateFunction agg = (AggregateFunction)obj;
        if (agg.getExpression() != null && TypeFacility.RUNTIME_TYPES.BOOLEAN.equals(agg.getExpression().getType())) {
              if (agg.getName().equalsIgnoreCase(NonReserved.MIN)) {
                agg.setName("bool_and"); //$NON-NLS-1$
              } else if (agg.getName().equalsIgnoreCase(NonReserved.MAX)) {
                agg.setName("bool_or"); //$NON-NLS-1$
              }
            }
      }
      return super.translate(obj, context);
    }
View Full Code Here

Examples of org.teiid.language.AggregateFunction

        assertTrue(example("testName", NonReserved.COUNT, true, 42).isDistinct()); //$NON-NLS-1$
        assertFalse(example("testName", NonReserved.COUNT, false, 42).isDistinct()); //$NON-NLS-1$
    }

    public void testGetExpression() throws Exception {
        AggregateFunction agg = example("testName", NonReserved.COUNT, true, 42); //$NON-NLS-1$
        assertNotNull(agg.getExpression());
        assertTrue(agg.getExpression() instanceof Literal);
        assertEquals(new Integer(42), ((Literal)agg.getExpression()).getValue());
    }
View Full Code Here

Examples of org.teiid.language.AggregateFunction

        }
        return element;
    }

    AggregateFunction translate(AggregateSymbol symbol) {
        return new AggregateFunction(symbol.getAggregateFunction().name(),
                                symbol.isDistinct(),
                                translate(symbol.getExpression()),
                                symbol.getType());
    }
View Full Code Here

Examples of org.teiid.language.AggregateFunction

    }
   
    @Override
    public List<?> translate(LanguageObject obj, ExecutionContext context) {
      if (obj instanceof AggregateFunction) {
        AggregateFunction af = (AggregateFunction)obj;
        if (af.getName().equals(AggregateFunction.STDDEV_POP)) {
          af.setName("StDevP"); //$NON-NLS-1$
        } else if (af.getName().equals(AggregateFunction.STDDEV_SAMP)) {
          af.setName("StDev"); //$NON-NLS-1$
        } else if (af.getName().equals(AggregateFunction.VAR_POP)) {
          af.setName("VarP"); //$NON-NLS-1$
        } else if (af.getName().equals(AggregateFunction.VAR_SAMP)) {
          af.setName("Var"); //$NON-NLS-1$
        }
      }
      return super.translate(obj, context);
    }
View Full Code Here

Examples of org.teiid.query.function.aggregate.AggregateFunction

       
        helpProcess(mgr, node, context, expected, null);
       
        //ensure that the distinct input type is correct
        AggregateFunction[] functions = node.getFunctions();
        AggregateFunction countDist = functions[5];
        SortingFilter dup = (SortingFilter)countDist;
        assertEquals(DataTypeManager.DefaultDataClasses.INTEGER, ((ElementSymbol)dup.getElements().get(0)).getType());
  }
View Full Code Here

Examples of reportgen.math.agregate.agregate.AggregateFunction

    private void initGroup(List<AggregateFunction> cols, boolean clearAsis) throws ReportException {
        //init normalizer
        normalizeScaler = new HashMap<Integer, Integer>();
        //init columns
        for(int i=0; i<cols.size(); i ++) {
            AggregateFunction col = cols.get(i);

            if(col.equals(AggregateFunction.COUNT)) {
                if(values[i] != null) {
                    values[i] = new Long(1);
                } else {
                    values[i] = new Long(0);
                }

            } else if(col.equals(AggregateFunction.COUNT_DISTINCT)) {
                if(distinct == null) {
                    distinct = new HashMap<Integer, Set>();
                }
                Set set = new HashSet();
                if(values[i] != null) {
                    set.add(values[i]);
                    values[i] = new Long(1);
                } else {
                    values[i] = new Long(0);
                }
                distinct.put(i, set);

            } else if(col.equals(AggregateFunction.AVG)) {
                Object value = values[i]; //always be Long or Double
               
                if(value instanceof Long) {
                    values[i] = new Double(((Long)value).doubleValue());
               
                } else if (value instanceof Double) {
                    //fit, do nothing
               
                } else {
                    throw new ReportException("Невозможно инициализировать группу при рассчете среднего значения для класса "
                            + value.getClass().getSimpleName());
                }
                normalizeScaler.put(i, 1);

            } else if(clearAsis
                    && col.equals(AggregateFunction.ASIS)) {
                values[i] = new String("-");
            }
        }
    }
View Full Code Here

Examples of reportgen.math.agregate.agregate.AggregateFunction

                    || !canGroupWith(newRow, groupIndicies))) {
            return false;
        }

        for(int i=0; i< cols.size(); i++) {
            AggregateFunction col = cols.get(i);
            Object value = newRow.values[i];
            //null values not take apart in group merging
            if(value == null) {
                continue;
            }

            if(col.equals(AggregateFunction.SUM)) {
                values[i] = sum(values[i], value);

            } else if(col.equals(AggregateFunction.AVG)) {
                Double dval = null;
                if(value instanceof Long) {
                    dval = new Double(((Long) value).doubleValue());
                } else if(value instanceof Double) {
                    dval = (Double) value;
                } else {
                    throw new ReportException("Невозможно рассчитать среднее значение для класса "
                            + value.getClass().getSimpleName());
                }
                values[i] = (Double) sum(values[i], dval);

                //update scaler
                Integer scaler = normalizeScaler.get(i);
                normalizeScaler.put(i, scaler+1);

            } else if(col.equals(AggregateFunction.COUNT)) {
                values[i] = (Long) values[i] + 1;

            } else if(col.equals(AggregateFunction.COUNT_DISTINCT)) {
                Set set = distinct.get(i);
                if(!set.contains(value)) {
                    set.add(value);
                    values[i] = (Long) values[i] + 1;
                }

            } else if(col.equals(AggregateFunction.MAX)) {
                if(compare(values[i], value) < 0) {
                    values[i] = value;
                }

            } else if(col.equals(AggregateFunction.MIN)) {
                if(compare(values[i], value) > 0) {
                    values[i] = value;
                }
            }
        }     
View Full Code Here

Examples of reportgen.math.agregate.agregate.AggregateFunction

     * @param value
     * @return
     * @throws ReportException
     */
    public static AggregateFunction fromName(String value) throws ReportException {
        AggregateFunction func = mnemonics.get(value);
        if (func == null) {
            throw new ReportException("Неизвестный тип агрегатной функции: " + value);
        }
        return func;
    }
View Full Code Here

Examples of reportgen.math.agregate.agregate.AggregateFunction

        //header
        if (showHeader) {
            String head = "<tr>";
            for (int columnIndex : visible) {
                String colTitle = data.getColumnTitle(columnIndex);
                AggregateFunction mode = data.getModes().get(columnIndex);
                if (includeFunc && !mode.equals(AggregateFunction.ASIS)) {
                    colTitle = mode.toString() + "(" + colTitle + ")";
                }
                head += "<th>" + colTitle + "</th>";
            }
            stream.print(head + "</tr>");
        }
View Full Code Here

Examples of reportgen.math.agregate.agregate.AggregateFunction

            aValue = new MathExpressionGeneric(child, context);
        } else {
            aValue = new MathExpressionGeneric(context);
        }

        AggregateFunction aFunction = null;
        String mnemonic = getStringAttribute(element, ATTR_FUNC, null, false);
        if(mnemonic == null) {
            aFunction = AggregateFunction.ASIS;
        } else {
            aFunction = context.getAggregFunction(mnemonic, aValue.getCls());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.