コード例 #1
0
 @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;
 }
コード例 #2
0
  /** 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);
      }
    }
  }