@Test public void buildRowValuesIndexed() { DynamicMessage message = DynamicMessage.newBuilder(SINGLE_DESC) .setField(SINGLE_DESC.findFieldByName("boolean"), true) .build(); List<Object> results = ProtobufUtils.buildRowValues(SINGLE_DESC, message, SINGLE_SCHEMA); assertThat(results, containsInRelativeOrder((Object) true, null)); assertThat(results.size(), is(24)); assertThat(results.indexOf((Object) true), is(13)); }
public static List<Object> buildRowValues(Descriptors.Descriptor dsc, Message msg, StructType schema) { List<Object> values = new ArrayList<>(); Object val; for (Descriptors.FieldDescriptor fd : dsc.getFields()) { if ( (!fd.isRepeated() && msg.hasField(fd)) || (fd.isRepeated() && msg.getRepeatedFieldCount(fd) > 0) ) { val = getFieldValue(fd, msg.getField(fd), schema.apply(fd.getName()).dataType()); } else { LOG.trace("FieldDescriptor[{}] => not found", fd.getFullName()); val = null; } values.add(val); } return values; }
ProtobufUtils { public static List<Object> buildRowValues(Descriptors.Descriptor dsc, Message msg, StructType schema) { List<Object> values = new ArrayList<>(); Object val; for (Descriptors.FieldDescriptor fd : dsc.getFields()) { if ( (!fd.isRepeated() && msg.hasField(fd)) || (fd.isRepeated() && msg.getRepeatedFieldCount(fd) > 0) ) { val = getFieldValue(fd, msg.getField(fd), schema.apply(fd.getName()).dataType()); } else { LOG.trace("FieldDescriptor[{}] => not found", fd.getFullName()); val = null; } values.add(val); } return values; } }
ProtobufUtils { public static List<Object> buildRowValues(Descriptors.Descriptor dsc, Message msg, StructType schema) { List<Object> values = new ArrayList<>(); Object val; for (Descriptors.FieldDescriptor fd : dsc.getFields()) { if ( (!fd.isRepeated() && msg.hasField(fd)) || (fd.isRepeated() && msg.getRepeatedFieldCount(fd) > 0) ) { val = getFieldValue(fd, msg.getField(fd), schema.apply(fd.getName()).dataType()); } else { LOG.trace("FieldDescriptor[{}] => not found", fd.getFullName()); val = null; } values.add(val); } return values; }  }
ProtobufUtils { public static List<Object> buildRowValues(Descriptors.Descriptor dsc, Message msg, StructType schema) { List<Object> values = new ArrayList<>(); Object val; for (Descriptors.FieldDescriptor fd : dsc.getFields()) { if ( (!fd.isRepeated() && msg.hasField(fd)) || (fd.isRepeated() && msg.getRepeatedFieldCount(fd) > 0) ) { val = getFieldValue(fd, msg.getField(fd), schema.apply(fd.getName()).dataType()); } else { LOG.trace("FieldDescriptor[{}] => not found", fd.getFullName()); val = null; } values.add(val); } return values; }  static List<Object> buildRowValues(Descriptors.Descriptor dsc, Message msg, StructType schema); static StructType buildSchema(Descriptors.Descriptor descriptor); static Descriptors.Descriptor buildDescriptor(String filePath, String messageName); static Descriptors.Descriptor buildDescriptor(String filePath); static boolean isGzipped(InputStream inputStream); }
ProtobufUtils { public static List<Object> buildRowValues(Descriptors.Descriptor dsc, Message msg, StructType schema) { List<Object> values = new ArrayList<>(); Object val; for (Descriptors.FieldDescriptor fd : dsc.getFields()) { if ( (!fd.isRepeated() && msg.hasField(fd)) || (fd.isRepeated() && msg.getRepeatedFieldCount(fd) > 0) ) { val = getFieldValue(fd, msg.getField(fd), schema.apply(fd.getName()).dataType()); } else { LOG.trace("FieldDescriptor[{}] => not found", fd.getFullName()); val = null; } values.add(val); } return values; }  static List<Object> buildRowValues(Descriptors.Descriptor dsc, Message msg, StructType schema); static StructType buildSchema(Descriptors.Descriptor descriptor); static Descriptors.Descriptor buildDescriptor(String filePath, String messageName); static Descriptors.Descriptor buildDescriptor(String filePath); static boolean isGzipped(InputStream inputStream);  }