public FieldAccessDescriptor resolve(Schema schema) { Set<Integer> resolvedFieldIdsAccessed = resolveFieldIdsAccessed(schema); Map<Integer, FieldAccessDescriptor> resolvedNestedFieldsAccessed = resolveNestedFieldsAccessed(schema); checkState( !getAllFields() || resolvedNestedFieldsAccessed.isEmpty(), "nested fields cannot be set if allFields is also set"); // If a recursive access is set for any nested fields, remove those fields from // fieldIdsAccessed. resolvedFieldIdsAccessed.removeAll(resolvedNestedFieldsAccessed.keySet()); return builder() .setAllFields(getAllFields()) .setFieldIdsAccessed(resolvedFieldIdsAccessed) .setNestedFieldsAccessedById(resolvedNestedFieldsAccessed) .build(); }
static Builder builder() { return new AutoValue_FieldAccessDescriptor.Builder() .setAllFields(false) .setFieldInsertionOrder(false) .setFieldIdsAccessed(Collections.emptySet()) .setFieldNamesAccessed(Collections.emptySet()) .setNestedFieldsAccessedById(Collections.emptyMap()) .setNestedFieldsAccessedByName(Collections.emptyMap()); }
/** * Return a descriptor that access the specified nested field. The nested field must be of type * {@link Schema.TypeName#ROW}, and the fieldAccess argument specifies what fields of the nested * type will be accessed. */ public FieldAccessDescriptor withNestedField( String nestedFieldName, FieldAccessDescriptor fieldAccess) { Map<String, FieldAccessDescriptor> newNestedFieldAccess = ImmutableMap.<String, FieldAccessDescriptor>builder() .putAll(getNestedFieldsAccessedByName()) .put(nestedFieldName, fieldAccess) .build(); return toBuilder().setNestedFieldsAccessedByName(newNestedFieldAccess).build(); }
/** Return an empty {@link FieldAccessDescriptor}. */ public static FieldAccessDescriptor create() { return builder().build(); }
/** * Return a descriptor that access the specified nested field. The nested field must be of type * {@link Schema.TypeName#ROW}, and the fieldAccess argument specifies what fields of the nested * type will be accessed. */ public FieldAccessDescriptor withNestedField( int nestedFieldId, FieldAccessDescriptor fieldAccess) { Map<Integer, FieldAccessDescriptor> newNestedFieldAccess = ImmutableMap.<Integer, FieldAccessDescriptor>builder() .putAll(getNestedFieldsAccessedById()) .put(nestedFieldId, fieldAccess) .build(); return toBuilder().setNestedFieldsAccessedById(newNestedFieldAccess).build(); }
public static FieldAccessDescriptor withAllFields() { return builder().setAllFields(true).build(); }
/** * By default, fields are sorted by name. If this is set, they will instead be sorted by insertion * order. All sorting happens in the {@link #resolve(Schema)} method. */ public FieldAccessDescriptor withOrderByFieldInsertionOrder() { return toBuilder().setFieldInsertionOrder(true).build(); }
/** * Return a descriptor that access the specified fields. * * <p>By default, if the field is a nested row (or a container containing a row), all fields of * said rows are accessed. For finer-grained acccess to nested rows, call withNestedField and pass * in a recursive {@link FieldAccessDescriptor}. */ public static FieldAccessDescriptor withFieldIds(Iterable<Integer> ids) { return builder().setFieldIdsAccessed(Sets.newLinkedHashSet(ids)).build(); }
/** * Return a descriptor that access the specified fields. * * <p>By default, if the field is a nested row (or a container containing a row), all fields of * said rows are accessed. For finer-grained acccess to nested rows, call withNestedField and pass * in a recursive {@link FieldAccessDescriptor}. */ public static FieldAccessDescriptor withFieldNames(Iterable<String> fieldNames) { return builder().setFieldNamesAccessed(Sets.newLinkedHashSet(fieldNames)).build(); }