Class Select


  • @Experimental(SCHEMAS)
    public class Select
    extends java.lang.Object
    A PTransform for selecting a subset of fields from a schema type.

    This transforms allows projecting out a subset of fields from a schema type. The output of this transform is of type Row, though that can be converted into any other type with matching schema using the Convert transform.

    For example, consider the following POJO type:

    @DefaultSchema(JavaFieldSchema.class)
     public class UserEvent {
       public String userId;
       public String eventId;
       public int eventType;
       public Location location;
     }
    @DefaultSchema(JavaFieldSchema.class)
     public class Location {
       public double latitude;
       public double longtitude;
     }
    Say you want to select just the set of userId, eventId pairs from each element, you would write the following:
    
     PCollection<UserEvent> events = readUserEvents();
     PCollection<Row> rows = event.apply(Select.fieldNames("userId", "eventId"));
     
    It's possible to select a nested field as well. For example, if you want just the location information from each element:
    
     PCollection<UserEvent> events = readUserEvents();
     PCollection<Location> rows = event.apply(Select.fieldNames("location")
                                  .apply(Convert.to(Location.class));