@Override
 public void open() {
   TAP_OPEN.in();
   try {
     if (isSkipBinding()) {
       ValueSource value = bindings.getValue(skip());
       if (!value.isNull()) this.skipLeft = value.getInt32();
     } else {
       this.skipLeft = skip();
     }
     if (skipLeft < 0) throw new NegativeLimitException("OFFSET", skipLeft);
     if (isLimitBinding()) {
       ValueSource value = bindings.getValue(limit());
       if (value.isNull()) this.limitLeft = Integer.MAX_VALUE;
       else {
         TInstance type = MNumeric.INT.instance(true);
         TExecutionContext executionContext = new TExecutionContext(null, type, context);
         Value ivalue = new Value(MNumeric.INT.instance(true));
         MNumeric.INT.fromObject(executionContext, value, ivalue);
         this.limitLeft = ivalue.getInt32();
       }
     } else {
       this.limitLeft = limit();
     }
     if (limitLeft < 0) throw new NegativeLimitException("LIMIT", limitLeft);
     super.open();
   } finally {
     TAP_OPEN.out();
   }
 }
 protected ValueSource valueNotNull(int index) {
   try {
     ValueSource value = bindings.getValue(index);
     if (value.isNull()) return null;
     else return value;
   } catch (BindingNotSetException ex) {
     return null;
   }
 }
 public ConstantExpression evalNow(PlanContext planContext, ExpressionNode node) {
   if (node instanceof ConstantExpression) return (ConstantExpression) node;
   TPreparedExpression expr = assembleExpression(node, null, null);
   TPreptimeValue preptimeValue = expr.evaluateConstant(planContext.getQueryContext());
   if (preptimeValue == null)
     throw new AkibanInternalException("required constant expression: " + expr);
   ValueSource valueSource = preptimeValue.value();
   if (valueSource == null)
     throw new AkibanInternalException("required constant expression: " + expr);
   if (node instanceof ConditionExpression) {
     Boolean value = valueSource.isNull() ? null : valueSource.getBoolean();
     return new BooleanConstantExpression(value);
   } else {
     return new ConstantExpression(preptimeValue);
   }
 }
 /**
  * Encode the given value into a stream that can then be passed to <code>writeByteStream</code>.
  */
 public ByteArrayOutputStream encodeValue(ValueSource value, ServerType type, boolean binary)
     throws IOException {
   if (value.isNull()) return null;
   if ((zeroDateTimeBehavior != ZeroDateTimeBehavior.NONE)
       && (((type.getType().typeClass() == MDateAndTime.DATE) && (value.getInt32() == 0))
           || ((type.getType().typeClass() == MDateAndTime.DATETIME)
               && (value.getInt64() == 0)))) {
     switch (zeroDateTimeBehavior) {
       case EXCEPTION:
         throw new ZeroDateTimeException();
       case ROUND:
         value =
             (type.getType().typeClass() == MDateAndTime.DATETIME)
                 ? ROUND_ZERO_DATETIME_SOURCE
                 : ROUND_ZERO_DATE_SOURCE;
         break;
       case CONVERT_TO_NULL:
         return null;
     }
   }
   reset();
   appendValue(value, type, binary);
   return getByteStream();
 }
Example #5
0
 @Override
 public void fromObject(TExecutionContext context, ValueSource in, ValueTarget out) {
   if (in.isNull()) out.putNull();
   else if (!tryFromObject(context, in, out)) parser.parse(context, in, out);
 }