Package com.twitter.elephantbird.thrift.TStructDescriptor

Examples of com.twitter.elephantbird.thrift.TStructDescriptor.Field


        pObj = tuple.get(i);
      } catch (ExecException e) {
        throw new RuntimeException(e);
      }
      if (pObj != null) {
        Field field = tDesc.getFieldAt(i);
        try {
          tObj.setFieldValue(field.getFieldIdEnum(), toThriftValue(field, pObj));
        } catch (Exception e) {
          String value = String.valueOf(tObj);
          final int max_length = 100;
          if (max_length < value.length()) {
            value = value.substring(0, max_length - 3) + "...";
          }
          String type = tObj == null ? "unknown" : tObj.getClass().getName();
          throw new RuntimeException(String.format(
              "Failed to set field '%s' using tuple value '%s' of type '%s' at index %d",
              field.getName(), value, type, i), e);
        }
      }
      // if tDesc is a union, at least one field needs to be non-null.
      // user is responsible for ensuring that.
    }
View Full Code Here


    }
    return null;
  }

  private static Map<Object, Object> toThriftMap(Field field, Map<String, Object> map) {
    Field keyField   = field.getMapKeyField();
    Field valueField = field.getMapValueField();
    HashMap<Object, Object> out = new HashMap<Object, Object>(map.size());
    for(Entry<String, Object> e : map.entrySet()) {
      String s = e.getKey();
      Object key;
      switch (keyField.getType()) {
View Full Code Here

  @SuppressWarnings("rawtypes")
  private static <T extends TBase>Tuple toTuple(TStructDescriptor tDesc, T tObj) {
    int size = tDesc.getFields().size();
    Tuple tuple = tupleFactory.newTuple(size);
    for (int i=0; i<size; i++) {
      Field field = tDesc.getFieldAt(i);
      Object value = tDesc.getFieldValue(i, tObj);
      try {
        tuple.set(i, toPigObject(field, value, false));
      } catch (ExecException e) { // not expected
        throw new RuntimeException(e);
View Full Code Here

                                              Map<Object, Object> map,
                                              boolean lazy) {
    // PIG map's key always a String. just use toString() and hope
    // things would work out ok.
    HashMap<String, Object> out = new HashMap<String, Object>(map.size());
    Field valueField = field.getMapValueField();
    for(Entry<Object, Object> e : map.entrySet()) {
      String key = e.getKey() == null ? null : e.getKey().toString();
      Object prev = out.put(key, toPigObject(valueField, e.getValue(), lazy));
      if (prev != null) {
        String msg = "Duplicate keys while converting to String while "
View Full Code Here

      this.desc = desc;
    }

    @Override
    protected Object getObjectAt(int index) {
      Field field = desc.getFieldAt(index);
      return toPigObject(field, desc.getFieldValue(index, tObject), true);
    }
View Full Code Here

          descriptorBuilderMap.put(typeName, mapBuilder);
          addProtoField(desBuilder, tField.getName(), tField.getFieldId() + 1, typeName, true);
        }
      } else {
        Field field = resolveField(tField);
        Type protoType = thriftTypeToProtoType(field);
        boolean isContainer = isContainer(tField);

        if (supportNestedObjects && protoType == Type.TYPE_MESSAGE) {
          String typeName = resolveMessageTypeName(field.gettStructDescriptor());

          // Protobuf field ids start at 1. Thrift starts at 0.
          addProtoField(desBuilder,
                        tField.getName(),
                        tField.getFieldId() + 1,
View Full Code Here

  private DescriptorProtos.DescriptorProto.Builder mapDescriptorProtoBuilder(
    Field field, String typeName) throws DescriptorValidationException {
    DescriptorProtos.DescriptorProto.Builder mapBuilder =
      DescriptorProtos.DescriptorProto.newBuilder().setName(typeName);

    Field keyField = field.getMapKeyField();
    Field valueField = field.getMapValueField();

    DescriptorProtos.FieldDescriptorProto.Builder keyBuilder = mapKeyProtoBuilder();
    DescriptorProtos.FieldDescriptorProto.Builder valueBuilder = mapValueProtoBuilder();

    setBuilderTypeFromField(keyField, keyBuilder);
View Full Code Here

                                     Object value) throws TException {
    if (value == null) {
      return;
    }

    Field innerField = null;

    switch (field.getType()) {

    case TType.LIST:
      innerField = field.getListElemField();    break;
    case TType.SET:
      innerField = field.getSetElemField();     break;
    case TType.MAP:
      innerField = field.getMapKeyField();      break;

    default:
      writeSingleFieldNoTag(proto, field, value);
      return;
    }

    // a map or a collection:

    if (field.getType() == TType.MAP) {

      Field valueField = field.getMapValueField();
      Map<?, ?> map = (Map<?, ?>)value;

      proto.writeByte(innerField.getType());
      proto.writeByte(valueField.getType());
      proto.writeI32(map.size());

      for(Entry<?, ?> entry : map.entrySet()) {
        writeSingleFieldNoTag(proto, innerField, entry.getKey());
        writeSingleFieldNoTag(proto, valueField, entry.getValue());
View Full Code Here

  public static Object readFieldNoTag(TProtocol   proto,
                                      Field       field)
                                      throws TException {

    Collection<Object> coll = null;
    Field innerField = null;

    switch (field.getType()) {

    case TType.LIST:
      innerField = field.getListElemField();
      coll = Lists.newArrayList();              break;
    case TType.SET:
      innerField = field.getSetElemField();
      coll = Sets.newHashSet();                 break;
    case TType.MAP:
      innerField = field.getMapKeyField();      break;

    default:
      return readSingleFieldNoTag(proto, field);
    }

    // collection or a map:


    if (field.getType() == TType.MAP) {

      proto.readByte();
      proto.readByte();
      int nEntries = proto.readI32();

      Map<Object, Object> map = Maps.newHashMap();
      Field valueField = field.getMapValueField();

      for (int i=0; i<nEntries; i++) {
        map.put(readFieldNoTag(proto, innerField),
                readFieldNoTag(proto, valueField));
      }
View Full Code Here

      // top level fields are split across the columns.
      for (int i=0; i < numColumns; i++) {

        if (i < (numColumns - 1)) {

          Field fd = tFields.get(i);
          ThriftUtils.writeFieldNoTag(tProto, fd, tDesc.getFieldValue(i, tObj));

        } // else { }  : no 'unknown fields' in thrift object

        colValRefs[i].set(byteStream.getData(),
View Full Code Here

TOP

Related Classes of com.twitter.elephantbird.thrift.TStructDescriptor.Field

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.