@Override public final void addBinary(Binary value) { try { ProtobufDatumFactory factory = ProtobufDatumFactory.get(dataType.getCode()); Message.Builder builder = factory.newBuilder(); builder.mergeFrom(value.getBytes()); parent.add(factory.createDatum(builder)); } catch (InvalidProtocolBufferException e) { throw new RuntimeException(e); } }
public static Datum createFromBytes(DataType dataType, byte[] bytes) { switch (dataType.getType()) { case BOOLEAN: return createBool(bytes[0]); case INT2: return createInt2(NumberUtil.toShort(bytes)); case INT4: return createInt4(NumberUtil.toInt(bytes)); case INT8: return createInt8(NumberUtil.toLong(bytes)); case FLOAT4: return createFloat4(NumberUtil.toFloat(bytes)); case FLOAT8: return createFloat8(NumberUtil.toDouble(bytes)); case CHAR: return createChar(bytes); case TEXT: return createText(bytes); case DATE: return new DateDatum(NumberUtil.toInt(bytes)); case TIME: return new TimeDatum(NumberUtil.toLong(bytes)); case TIMESTAMP: return new TimestampDatum(NumberUtil.toLong(bytes)); case BIT: return createBit(bytes[0]); case BLOB: return createBlob(bytes); case INET4: return createInet4(bytes); case PROTOBUF: try { return ProtobufDatumFactory.createDatum(dataType, bytes); } catch (IOException e) { throw new TajoInternalError(e); } default: throw new TajoRuntimeException(new UnsupportedDataTypeException(dataType.toString())); } }