コード例 #1
0
 SelectListColumnResolver(Select select) {
   this.select = select;
   int columnCount = select.getColumnCount();
   columns = new Column[columnCount];
   expressions = new Expression[columnCount];
   ArrayList<Expression> columnList = select.getExpressions();
   for (int i = 0; i < columnCount; i++) {
     Expression expr = columnList.get(i);
     Column column = new Column(expr.getAlias(), Value.NULL);
     column.setTable(null, i);
     columns[i] = column;
     expressions[i] = expr.getNonAliasExpression();
   }
 }
コード例 #2
0
  @Override
  public void updateAggregate(Session session) {
    HashMap<Expression, Object> group = select.getCurrentGroup();
    if (group == null) {
      // this is a different level (the enclosing query)
      return;
    }

    int groupRowId = select.getCurrentGroupRowId();
    if (lastGroupRowId == groupRowId) {
      // already visited
      return;
    }
    lastGroupRowId = groupRowId;

    Aggregate agg = (Aggregate) group.get(this);
    try {
      if (agg == null) {
        agg = getInstance();
        group.put(this, agg);
      }
      Object[] argValues = new Object[args.length];
      Object arg = null;
      for (int i = 0, len = args.length; i < len; i++) {
        Value v = args[i].getValue(session);
        v = v.convertTo(argTypes[i]);
        arg = v.getObject();
        argValues[i] = arg;
      }
      if (args.length == 1) {
        agg.add(arg);
      } else {
        agg.add(argValues);
      }
    } catch (SQLException e) {
      throw DbException.convert(e);
    }
  }
コード例 #3
0
 @Override
 public Value getValue(Session session) {
   HashMap<Expression, Object> group = select.getCurrentGroup();
   if (group == null) {
     throw DbException.get(ErrorCode.INVALID_USE_OF_AGGREGATE_FUNCTION_1, getSQL());
   }
   try {
     Aggregate agg = (Aggregate) group.get(this);
     if (agg == null) {
       agg = getInstance();
     }
     Object obj = agg.getResult();
     if (obj == null) {
       return ValueNull.INSTANCE;
     }
     return DataType.convertToValue(session, obj, dataType);
   } catch (SQLException e) {
     throw DbException.convert(e);
   }
 }