@JRubyMethod public IRubyObject concat(ThreadContext context, IRubyObject list) { if (list instanceof RubyArray) { checkArrayElementType(context, (RubyArray) list); this.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."); this.storage.addAll((RubyArray) repeatedField.toArray(context)); } return this.storage; }
@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; }
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 {
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);
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);
/** * 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"); } } } };
/** * @return whether the field is a byte string. */ public boolean isBlob() { return field.getType().equals(FieldDescriptor.Type.BYTES); }
/** * @return whether the field is an enum */ public boolean isEnum() { return field.getType().equals(FieldDescriptor.Type.ENUM); }
static void setNestedMessages(Descriptors.Descriptor resMessage, MessageRegistry messageRegistry) { for (Descriptors.Descriptor nestedType : resMessage.getNestedTypes()) { messageRegistry.addMessageDescriptor(nestedType.getName(), nestedType); } for (Descriptors.FieldDescriptor msgField : resMessage.getFields()) { if (Descriptors.FieldDescriptor.Type.MESSAGE.equals(msgField.getType())) { Descriptors.Descriptor msgType = msgField.getMessageType(); messageRegistry.addMessageDescriptor(msgType.getName(), msgType); } } }
/** * @return whether the field is a message */ public boolean isMessage() { return field.getType().equals(FieldDescriptor.Type.MESSAGE); }