@JRubyMethod(name = {"+"}) public IRubyObject plus(ThreadContext context, IRubyObject list) { RubyRepeatedField dup = (RubyRepeatedField) dup(context); if (list instanceof RubyArray) { checkArrayElementType(context, (RubyArray) list); dup.storage.addAll((RubyArray) list); } else { RubyRepeatedField repeatedField = (RubyRepeatedField) list; if (! fieldType.equals(repeatedField.fieldType) || (typeClass != null && ! typeClass.equals(repeatedField.typeClass))) throw context.runtime.newArgumentError("Attempt to append RepeatedField with different element type."); dup.storage.addAll((RubyArray) repeatedField.toArray(context)); } return dup; }
@Override public void accept(Descriptors.FieldDescriptor fieldDescriptor) { protoBufParsingInfos.add(new ProtoBufParsingInfo(fieldDescriptor.getNumber(), fieldDescriptor.getName(), fieldDescriptor.getType().name(), fieldDescriptor.toProto().getLabel().name(), null)); } });
public static Descriptors.FieldDescriptor.Type rubyToFieldType(IRubyObject typeClass) { return Descriptors.FieldDescriptor.Type.valueOf(typeClass.asJavaString().toUpperCase()); }
else if (field.getType().equals(Descriptors.FieldDescriptor.Type.MESSAGE)) { LOG.trace("FieldDescriptor[{}] is a Message, unrolling", field.getFullName()); val = RowFactory.create(buildRowValues(field.getMessageType(), (DynamicMessage) value, else if (field.getType().equals(Descriptors.FieldDescriptor.Type.ENUM)) { val = RowUtils.toRowValue(((Descriptors.EnumValueDescriptor) value).getName(), dataType); else if (field.getType().equals(Descriptors.FieldDescriptor.Type.BYTES)) { val = RowUtils.toRowValue(((ByteString) value).toByteArray(), dataType);
break; default: throw new IllegalArgumentException("Type " + protobufType.name() + " cannot be converted to Any type.");
break; default: throw new IllegalArgumentException("Type " + protobufType.name() + " cannot be converted to Any type.");
type = Type.valueOf(proto.getType());
if (protobufType.equals(Type.MESSAGE)) { Builder<?> subbuilder = DynamicMessage.newBuilder(protobufField.getMessageType()); builder.addRepeatedField(protobufField, recursiveConvert(tpl, subbuilder)); throw new ExecException("Data type not compatible: " + protobufType + ", " + tplObj.getClass().getName()); if (protobufType.equals(Type.ENUM)) { EnumDescriptor enumDescr = protobufField.getEnumType(); EnumValueDescriptor enumValueDescr = enumDescr.findValueByName((String) tplObj); if (protobufType.equals(Type.MESSAGE)) { Builder<?> subbuilder = DynamicMessage.newBuilder(protobufField.getMessageType()); builder.setField(protobufField, recursiveConvert((Tuple) tupleField, subbuilder)); } else if (protobufType.equals(Type.ENUM)) { EnumDescriptor enumDescr = protobufField.getEnumType(); EnumValueDescriptor enumValueDescr = enumDescr.findValueByName((String) tupleField);
type = Type.valueOf(proto.getType());
if (descriptor.getType().equals(Type.MESSAGE)) { out.append(descriptor.getMessageType().getFullName() + " "); Descriptor messageType = descriptor.getMessageType(); descriptors.put(messageType, false); } else if (descriptor.getType().equals(Type.ENUM)) { out.append(descriptor.getEnumType().getFullName() + " "); } else { out.append(descriptor.getType().toString().toLowerCase() + " ");
/** * Adds one field to pig schema generated from protobuf FieldDescriptor * * @param schema * @param fd * @throws FrontendException */ private static void addFieldToSchema(Schema schema, FieldDescriptor fd) throws FrontendException, IllegalArgumentException { Type protobufType = fd.getType(); String fieldName = fd.getName().toLowerCase(Locale.ENGLISH); Byte pigType; if (typesMap.containsKey(protobufType)) { pigType = typesMap.get(protobufType); } else { throw new IllegalArgumentException(); } if (protobufType.equals(Type.MESSAGE)) { Schema messageSchema = protoDescriptorToSchema(fd.getMessageType()); schema.add(new FieldSchema(fieldName, messageSchema)); } else { schema.add(new FieldSchema(fieldName, pigType)); } }
private static Object messageFieldToTupleField(Object messageField, Type type, boolean enforceTuple) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, ExecException { if (type.equals(Type.MESSAGE)) { return messageToTuple((Message) messageField); } else { Object retObject = null; if (type.equals(Type.BYTES)) { retObject = new DataByteArray(((ByteString) messageField).toByteArray()); } else if (type.equals(Type.ENUM)) { retObject = ((EnumValueDescriptor) messageField).getName(); } else if (typesMap.containsKey(type)) { retObject = messageField; } if (retObject != null && enforceTuple) { retObject = TupleFactory.getInstance().newTuple(retObject); } return retObject; } } }
private boolean typesMatch(FieldDescriptor protoFieldDesc, FieldValueMetaData thriftMetadata) { if (thriftMetadata.isStruct()) { // TODO: Handle structs return false; } byte thriftType = thriftMetadata.type; // TODO: Handle Lists that are more than 1 level deep. Be all pro-style with the recursion. if (thriftMetadata.type == TType.LIST && protoFieldDesc.isRepeated()) { FieldValueMetaData listMeta = ((ListMetaData) thriftMetadata).elemMetaData; if (listMeta.isStruct() || listMeta.isContainer()) { return false; } thriftType = listMeta.type; } return (protoFieldDesc.getType().equals(thriftTypeToProtoType(thriftType)) || thriftBinSucks(protoFieldDesc.getType(), thriftType)); }
@Override public void validateIndexForRecordType(@Nonnull RecordType recordType, @Nonnull MetaDataValidator metaDataValidator) { final List<Descriptors.FieldDescriptor> fields = metaDataValidator.validateIndexForRecordType(index, recordType); int textFieldPosition = TextIndexMaintainer.textFieldPosition(index.getRootExpression()); if (textFieldPosition > fields.size()) { throw new KeyExpression.InvalidExpressionException("text index does not have text field after grouped fields"); } else { Descriptors.FieldDescriptor textFieldDescriptor = fields.get(textFieldPosition); if (!textFieldDescriptor.getType().equals(Descriptors.FieldDescriptor.Type.STRING)) { throw new KeyExpression.InvalidExpressionException(String.format("text index has non-string type %s as text field", textFieldDescriptor.getLiteJavaType())); } if (textFieldDescriptor.isRepeated()) { throw new KeyExpression.InvalidExpressionException("text index does not allow a repeated field for text body"); } } } };
/** For internal use only. */ public WireFormat.FieldType getLiteType() { return table[type.ordinal()]; }
public static Type valueOf(final FieldDescriptorProto.Type type) { return values()[type.getNumber() - 1]; } }
public FieldDescriptorProto.Type toProto() { return FieldDescriptorProto.Type.forNumber(ordinal() + 1); } public JavaType getJavaType() { return javaType; }
public static Type valueOf(final FieldDescriptorProto.Type type) { return values()[type.getNumber() - 1]; } }
/** * Get the field's java type. This is just for convenience. Every * {@code FieldDescriptorProto.Type} maps to exactly one Java type. */ public JavaType getJavaType() { return type.getJavaType(); }