/** * Builds a {@link Type} and returns the parent builder, if given, or the * {@code Type} that was built. If returning a parent object that is a * GroupBuilder, the constructed type will be added to it as a field. * <p> * <em>Note:</em> Any configuration for this type builder should be done * before calling this method. * * @param name a name for the constructed type * @return the parent {@code GroupBuilder} or the constructed {@code Type} */ public P named(String name) { Preconditions.checkNotNull(name, "Name is required"); Preconditions.checkNotNull(repetition, "Repetition is required"); Type type = build(name); if (parent != null) { // if the parent is a BaseGroupBuilder, add type to it if (BaseGroupBuilder.class.isAssignableFrom(parent.getClass())) { BaseGroupBuilder.class.cast(parent).addField(type); } return parent; } else if (returnClass != null) { // no parent indicates that the Type object should be returned // the constructor check guarantees that returnClass is a Type return returnClass.cast(type); } else { throw new IllegalStateException( "[BUG] Parent and return type are null: must override named"); } }
/** * Adds a type annotation ({@link OriginalType}) to the type being built. * <p> * Type annotations are used to extend the types that parquet can store, by * specifying how the primitive types should be interpreted. This keeps the * set of primitive types to a minimum and reuses parquet's efficient * encodings. For example, strings are stored as byte arrays (binary) with * a UTF8 annotation. * * @param type an {@code OriginalType} * @return this builder for method chaining * * @deprecated use {@link #as(LogicalTypeAnnotation)} with the corresponding logical type instead */ @Deprecated public THIS as(OriginalType type) { this.logicalTypeAnnotation = LogicalTypeAnnotation.fromOriginalType(type, null); return self(); }
/** * Builds a {@link Type} and returns the parent builder, if given, or the * {@code Type} that was built. If returning a parent object that is a * GroupBuilder, the constructed type will be added to it as a field. * <p> * <em>Note:</em> Any configuration for this type builder should be done * before calling this method. * * @param name a name for the constructed type * @return the parent {@code GroupBuilder} or the constructed {@code Type} */ public P named(String name) { Preconditions.checkNotNull(name, "Name is required"); Preconditions.checkNotNull(repetition, "Repetition is required"); Type type = build(name); if (parent != null) { // if the parent is a BaseGroupBuilder, add type to it if (BaseGroupBuilder.class.isAssignableFrom(parent.getClass())) { BaseGroupBuilder.class.cast(parent).addField(type); } return parent; } else if (returnClass != null) { // no parent indicates that the Type object should be returned // the constructor check guarantees that returnClass is a Type return returnClass.cast(type); } else { throw new IllegalStateException( "[BUG] Parent and return type are null: must override named"); } }
/** * Adds a type annotation ({@link LogicalTypeAnnotation}) to the type being built. * <p> * Type annotations are used to extend the types that parquet can store, by * specifying how the primitive types should be interpreted. This keeps the * set of primitive types to a minimum and reuses parquet's efficient * encodings. For example, strings are stored as byte arrays (binary) with * a UTF8 annotation. * * @param type an {@code {@link LogicalTypeAnnotation}} * @return this builder for method chaining */ public THIS as(LogicalTypeAnnotation type) { this.logicalTypeAnnotation = type; this.newLogicalTypeSet = true; return self(); }
/** * Adds a type annotation ({@link OriginalType}) to the type being built. * <p> * Type annotations are used to extend the types that parquet can store, by * specifying how the primitive types should be interpreted. This keeps the * set of primitive types to a minimum and reuses parquet's efficient * encodings. For example, strings are stored as byte arrays (binary) with * a UTF8 annotation. * * @param type an {@code OriginalType} * @return this builder for method chaining */ public THIS as(OriginalType type) { this.originalType = type; return self(); }
/** * adds an id annotation to the type being built. * <p> * ids are used to capture the original id when converting from models using ids (thrift, protobufs) * * @param id the id of the field * @return this builder for method chaining */ public THIS id(int id) { this.id = new ID(id); return self(); }
/** * adds an id annotation to the type being built. * <p> * ids are used to capture the original id when converting from models using ids (thrift, protobufs) * * @param id the id of the field * @return this builder for method chaining */ public THIS id(int id) { this.id = new ID(id); return self(); }
protected final THIS repetition(Type.Repetition repetition) { Preconditions.checkArgument(!repetitionAlreadySet, "Repetition has already been set"); Preconditions.checkNotNull(repetition, "Repetition cannot be null"); this.repetition = repetition; this.repetitionAlreadySet = true; return self(); }
private <T> GroupBuilder<T> convertFields(GroupBuilder<T> groupBuilder, List<Descriptors.FieldDescriptor> fieldDescriptors) { for (Descriptors.FieldDescriptor fieldDescriptor : fieldDescriptors) { groupBuilder = addField(fieldDescriptor, groupBuilder) .id(fieldDescriptor.getNumber()) .named(fieldDescriptor.getName()); } return groupBuilder; }
protected final THIS repetition(Type.Repetition repetition) { Preconditions.checkArgument(!repetitionAlreadySet, "Repetition has already been set"); Preconditions.checkNotNull(repetition, "Repetition cannot be null"); this.repetition = repetition; this.repetitionAlreadySet = true; return self(); }