예제 #1
0
 public MultiplyExpression(List<Expression> children) {
   super(children);
   for (int i = 0; i < children.size(); i++) {
     Expression childExpr = children.get(i);
     if (i == 0) {
       maxLength = childExpr.getMaxLength();
       scale = childExpr.getScale();
     } else {
       maxLength = getPrecision(maxLength, childExpr.getMaxLength(), scale, childExpr.getScale());
       scale = getScale(maxLength, childExpr.getMaxLength(), scale, childExpr.getScale());
     }
   }
 }
예제 #2
0
 public DecimalDivideExpression(List<Expression> children) {
   super(children);
   for (int i = 0; i < children.size(); i++) {
     Expression childExpr = children.get(i);
     if (i == 0) {
       maxLength = childExpr.getMaxLength();
       scale = childExpr.getScale();
     } else if (maxLength != null
         && scale != null
         && childExpr.getMaxLength() != null
         && childExpr.getScale() != null) {
       maxLength = getPrecision(maxLength, childExpr.getMaxLength(), scale, childExpr.getScale());
       scale = getScale(maxLength, childExpr.getMaxLength(), scale, childExpr.getScale());
     }
   }
 }
예제 #3
0
 int getScale() {
   switch (dataType) {
     case SQLTokenizer.DECIMAL:
     case SQLTokenizer.NUMERIC:
       return scale;
     default:
       return Expression.getScale(dataType);
   }
 }
예제 #4
0
 @Override
 public Expression[] getExpressionColumns(Session session) {
   ExpressionColumn[] expr = new ExpressionColumn[list.length];
   for (int i = 0; i < list.length; i++) {
     Expression e = list[i];
     Column col =
         new Column(
             "C" + (i + 1), e.getType(), e.getPrecision(), e.getScale(), e.getDisplaySize());
     expr[i] = new ExpressionColumn(session.getDatabase(), col);
   }
   return expr;
 }
예제 #5
0
 @Override
 public Expression optimize(Session session) {
   if (on != null) {
     on = on.optimize(session);
     dataType = on.getType();
     scale = on.getScale();
     precision = on.getPrecision();
     displaySize = on.getDisplaySize();
   }
   if (groupConcatOrderList != null) {
     for (SelectOrderBy o : groupConcatOrderList) {
       o.expression = o.expression.optimize(session);
     }
     groupConcatSort = initOrder(session);
   }
   if (groupConcatSeparator != null) {
     groupConcatSeparator = groupConcatSeparator.optimize(session);
   }
   switch (type) {
     case GROUP_CONCAT:
       dataType = Value.STRING;
       scale = 0;
       precision = displaySize = Integer.MAX_VALUE;
       break;
     case COUNT_ALL:
     case COUNT:
       dataType = Value.LONG;
       scale = 0;
       precision = ValueLong.PRECISION;
       displaySize = ValueLong.DISPLAY_SIZE;
       break;
     case SELECTIVITY:
       dataType = Value.INT;
       scale = 0;
       precision = ValueInt.PRECISION;
       displaySize = ValueInt.DISPLAY_SIZE;
       break;
     case HISTOGRAM:
       dataType = Value.ARRAY;
       scale = 0;
       precision = displaySize = Integer.MAX_VALUE;
       break;
     case SUM:
       if (dataType == Value.BOOLEAN) {
         // example: sum(id > 3) (count the rows)
         dataType = Value.LONG;
       } else if (!DataType.supportsAdd(dataType)) {
         throw DbException.get(ErrorCode.SUM_OR_AVG_ON_WRONG_DATATYPE_1, getSQL());
       } else {
         dataType = DataType.getAddProofType(dataType);
       }
       break;
     case AVG:
       if (!DataType.supportsAdd(dataType)) {
         throw DbException.get(ErrorCode.SUM_OR_AVG_ON_WRONG_DATATYPE_1, getSQL());
       }
       break;
     case MIN:
     case MAX:
       break;
     case STDDEV_POP:
     case STDDEV_SAMP:
     case VAR_POP:
     case VAR_SAMP:
       dataType = Value.DOUBLE;
       precision = ValueDouble.PRECISION;
       displaySize = ValueDouble.DISPLAY_SIZE;
       scale = 0;
       break;
     case BOOL_AND:
     case BOOL_OR:
       dataType = Value.BOOLEAN;
       precision = ValueBoolean.PRECISION;
       displaySize = ValueBoolean.DISPLAY_SIZE;
       scale = 0;
       break;
     default:
       DbException.throwInternalError("type=" + type);
   }
   return this;
 }