@Override
 public void open() {
   String currentSchema = context.getCurrentSchema();
   String schemaName, tableName;
   ValueSource value = valueNotNull(0);
   if (value == null) schemaName = currentSchema;
   else schemaName = value.getString();
   tableName = bindings.getValue(1).getString();
   TableName groupName = new TableName(schemaName, tableName);
   Group group = context.getStore().schema().ais().getGroup(groupName);
   if (group == null) throw new NoSuchGroupException(groupName);
   StorageDescription storage = group.getStorageDescription();
   if (!(storage instanceof ProtobufStorageDescription))
     throw new InvalidParameterValueException("group does not use STORAGE_FORMAT protobuf");
   FileDescriptorProto fileProto = ((ProtobufStorageDescription) storage).getFileProto();
   try {
     tempFile = File.createTempFile("group", ".proto");
     try (FileWriter writer = new FileWriter(tempFile)) {
       new ProtobufDecompiler(writer).decompile(fileProto);
     }
     reader = new BufferedReader(new FileReader(tempFile));
   } catch (IOException ex) {
     throw new AkibanInternalException("decompiling error", ex);
   }
   messagesSent = 0;
 }
 @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);
   }
 }
示例#5
0
  protected boolean tryFromObject(TExecutionContext context, ValueSource in, ValueTarget out) {
    if (in.getType().equalsExcludingNullable(out.getType())) {
      ValueTargets.copyFrom(in, out);
      return true;
    }

    UnderlyingType underlyingType = TInstance.underlyingType(in.getType());
    if (underlyingType == UnderlyingType.STRING || underlyingType == UnderlyingType.BYTES)
      return false;
    final String asString;
    switch (underlyingType) {
      case BOOL:
        asString = Boolean.toString(in.getBoolean());
        break;
      case INT_8:
        asString = Byte.toString(in.getInt8());
        break;
      case INT_16:
        asString = Short.toString(in.getInt16());
        break;
      case UINT_16:
        asString = Integer.toString(in.getUInt16());
        break;
      case INT_32:
        asString = Integer.toString(in.getInt32());
        break;
      case INT_64:
        asString = Long.toString(in.getInt64());
        break;
      case FLOAT:
        asString = Float.toString(in.getFloat());
        break;
      case DOUBLE:
        asString = Double.toString(in.getDouble());
        break;
      case BYTES:
      case STRING:
      default:
        throw new AssertionError(underlyingType + ": " + in);
    }
    parser.parse(context, new Value(MString.varcharFor(asString), asString), out);
    return true;
  }
 /**
  * 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();
 }
示例#7
0
 /** Give a <code>ValueSource</code> whose {@link #jdbcType} claims
  * to be one of the integer types (<code>TINYINT</code>,
  * <code>SMALLINT</code>, <code>INTEGER</code>,
  * <code>BIGINT<code>), get the integer value.  Needed because of
  * <code>UNSIGNED</code> and <code>YEAR</code> types.
  */
 public long getIntegerValue(ValueSource value) {
   switch (TInstance.underlyingType(value.getType())) {
     case INT_8:
       return value.getInt8();
     case INT_16:
       return value.getInt16();
     case UINT_16:
       return value.getUInt16();
     case INT_32:
       return value.getInt32();
     case INT_64:
     default:
       return value.getInt64();
   }
 }
示例#8
0
 /**
  * Give a <code>ValueSource</code> whose {@link #jdbcType} claims to be one of the decimal types (
  * <code>DECIMAL</code>, <code>NUMERIC</code>), get the decimal value.
  */
 public BigDecimal getDecimalValue(ValueSource value) {
   return TBigDecimal.getWrapper(value, value.getType()).asBigDecimal();
 }
 private void processBinaryText(ValueSource value) {
   FormatOptions.BinaryFormatOption bfo = options.get(FormatOptions.BinaryFormatOption.class);
   String formattedString = bfo.format(value.getBytes());
   printWriter.append(formattedString);
 }
  /** Append the given value to the buffer. */
  public void appendValue(ValueSource value, ServerType type, boolean binary) throws IOException {
    if (!binary) {
      // Handle unusual text encoding of binary types.
      switch (type.getBinaryEncoding()) {
        case BINARY_OCTAL_TEXT:
          processBinaryText(value);
          break;

        default:
          type.getType().format(value, appender);
          break;
      }
    } else {
      switch (type.getBinaryEncoding()) {
        case BINARY_OCTAL_TEXT:
          getByteStream().write(value.getBytes());
          break;
        case INT_8:
          getDataStream().write((byte) typesTranslator.getIntegerValue(value));
          break;
        case INT_16:
          getDataStream().writeShort((short) typesTranslator.getIntegerValue(value));
          break;
        case INT_32:
          getDataStream().writeInt((int) typesTranslator.getIntegerValue(value));
          break;
        case INT_64:
          getDataStream().writeLong(typesTranslator.getIntegerValue(value));
          break;
        case FLOAT_32:
          getDataStream().writeFloat(value.getFloat());
          break;
        case FLOAT_64:
          getDataStream().writeDouble(value.getDouble());
          break;
        case STRING_BYTES:
          getByteStream().write(value.getString().getBytes(encoding));
          break;
        case BOOLEAN_C:
          getDataStream().write(value.getBoolean() ? 1 : 0);
          break;
        case TIMESTAMP_FLOAT64_SECS_2000_NOTZ:
          getDataStream()
              .writeDouble(
                  seconds2000NoTZ(typesTranslator.getTimestampMillisValue(value))
                      + typesTranslator.getTimestampNanosValue(value) / 1.0e9);
          break;
        case TIMESTAMP_INT64_MICROS_2000_NOTZ:
          getDataStream()
              .writeLong(
                  seconds2000NoTZ(typesTranslator.getTimestampMillisValue(value)) * 1000000L
                      + typesTranslator.getTimestampNanosValue(value) / 1000);
          break;
        case DAYS_2000:
          getDataStream().writeInt(days2000(typesTranslator.getTimestampMillisValue(value)));
          break;
        case TIME_FLOAT64_SECS_NOTZ:
          getDataStream().writeDouble(timeSecsNoTZ(typesTranslator.getTimestampMillisValue(value)));
          break;
        case TIME_INT64_MICROS_NOTZ:
          getDataStream()
              .writeLong(timeSecsNoTZ(typesTranslator.getTimestampMillisValue(value)) * 1000000L);
          break;
        case DECIMAL_PG_NUMERIC_VAR:
          for (short d : pgNumericVar(typesTranslator.getDecimalValue(value))) {
            getDataStream().writeShort(d);
          }
          break;
        case UUID:
          getDataStream().write(AkGUID.uuidToBytes((java.util.UUID) value.getObject()));
          break;
        case NONE:
        default:
          throw new UnsupportedOperationException("No binary encoding for " + type);
      }
    }
  }
示例#11
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);
 }