Package org.apache.iceberg.types
Class TypeUtil
- java.lang.Object
-
- org.apache.iceberg.types.TypeUtil
-
public class TypeUtil extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTypeUtil.CustomOrderSchemaVisitor<T>static interfaceTypeUtil.NextIDInterface for passing a function that assigns column IDs.static classTypeUtil.SchemaVisitor<T>
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SchemaassignFreshIds(int schemaId, Schema schema, TypeUtil.NextID nextId)Assigns fresh ids from thenextId functionfor all fields in a schema.static SchemaassignFreshIds(Schema schema, Schema baseSchema, TypeUtil.NextID nextId)Assigns ids to match a given schema, and fresh ids from thenextId functionfor all other fields.static SchemaassignFreshIds(Schema schema, TypeUtil.NextID nextId)Assigns fresh ids from thenextId functionfor all fields in a schema.static TypeassignFreshIds(Type type, TypeUtil.NextID nextId)Assigns fresh ids from thenextId functionfor all fields in a type.static SchemaassignIncreasingFreshIds(Schema schema)Assigns strictly increasing fresh ids for all fields in a schema, starting from 1.static intdecimalRequiredBytes(int precision)static Typefind(Schema schema, java.util.function.Predicate<Type> predicate)static java.util.Set<java.lang.Integer>getProjectedIds(Schema schema)static java.util.Set<java.lang.Integer>getProjectedIds(Type type)static java.util.Map<java.lang.Integer,Types.NestedField>indexById(Types.StructType struct)static java.util.Map<java.lang.String,java.lang.Integer>indexByLowerCaseName(Types.StructType struct)static java.util.Map<java.lang.String,java.lang.Integer>indexByName(Types.StructType struct)static java.util.Map<java.lang.Integer,java.lang.String>indexNameById(Types.StructType struct)static java.util.Map<java.lang.Integer,java.lang.Integer>indexParents(Types.StructType struct)static booleanisPromotionAllowed(Type from, Type.PrimitiveType to)static Schemajoin(Schema left, Schema right)static SchemareassignIds(Schema schema, Schema idSourceSchema)Reassigns ids in a schema from another schema.static java.util.Set<java.lang.Integer>refreshIdentifierFields(Types.StructType freshSchema, Schema baseSchema)Get the identifier fields in the fresh schema based on the identifier fields in the base schema.static Schemaselect(Schema schema, java.util.Set<java.lang.Integer> fieldIds)static Types.StructTypeselect(Types.StructType struct, java.util.Set<java.lang.Integer> fieldIds)static SchemaselectNot(Schema schema, java.util.Set<java.lang.Integer> fieldIds)static Types.StructTypeselectNot(Types.StructType struct, java.util.Set<java.lang.Integer> fieldIds)static voidvalidateWriteSchema(Schema tableSchema, Schema writeSchema, java.lang.Boolean checkNullability, java.lang.Boolean checkOrdering)Check whether we could write the iceberg table with the user-provided write schema.static <T> Tvisit(Schema schema, TypeUtil.CustomOrderSchemaVisitor<T> visitor)static <T> Tvisit(Schema schema, TypeUtil.SchemaVisitor<T> visitor)static <T> Tvisit(Type type, TypeUtil.CustomOrderSchemaVisitor<T> visitor)Used to traverse types with traversals other than pre-order.static <T> Tvisit(Type type, TypeUtil.SchemaVisitor<T> visitor)
-
-
-
Method Detail
-
select
public static Types.StructType select(Types.StructType struct, java.util.Set<java.lang.Integer> fieldIds)
-
getProjectedIds
public static java.util.Set<java.lang.Integer> getProjectedIds(Schema schema)
-
getProjectedIds
public static java.util.Set<java.lang.Integer> getProjectedIds(Type type)
-
selectNot
public static Types.StructType selectNot(Types.StructType struct, java.util.Set<java.lang.Integer> fieldIds)
-
indexByName
public static java.util.Map<java.lang.String,java.lang.Integer> indexByName(Types.StructType struct)
-
indexNameById
public static java.util.Map<java.lang.Integer,java.lang.String> indexNameById(Types.StructType struct)
-
indexByLowerCaseName
public static java.util.Map<java.lang.String,java.lang.Integer> indexByLowerCaseName(Types.StructType struct)
-
indexById
public static java.util.Map<java.lang.Integer,Types.NestedField> indexById(Types.StructType struct)
-
indexParents
public static java.util.Map<java.lang.Integer,java.lang.Integer> indexParents(Types.StructType struct)
-
assignFreshIds
public static Type assignFreshIds(Type type, TypeUtil.NextID nextId)
Assigns fresh ids from thenextId functionfor all fields in a type.- Parameters:
type- a typenextId- an id assignment function- Returns:
- an structurally identical type with new ids assigned by the nextId function
-
assignFreshIds
public static Schema assignFreshIds(Schema schema, TypeUtil.NextID nextId)
Assigns fresh ids from thenextId functionfor all fields in a schema.- Parameters:
schema- a schemanextId- an id assignment function- Returns:
- a structurally identical schema with new ids assigned by the nextId function
-
assignFreshIds
public static Schema assignFreshIds(int schemaId, Schema schema, TypeUtil.NextID nextId)
Assigns fresh ids from thenextId functionfor all fields in a schema.- Parameters:
schemaId- an ID assigned to this schemaschema- a schemanextId- an id assignment function- Returns:
- a structurally identical schema with new ids assigned by the nextId function
-
assignFreshIds
public static Schema assignFreshIds(Schema schema, Schema baseSchema, TypeUtil.NextID nextId)
Assigns ids to match a given schema, and fresh ids from thenextId functionfor all other fields.- Parameters:
schema- a schemabaseSchema- a schema with existing IDs to copy by namenextId- an id assignment function- Returns:
- a structurally identical schema with new ids assigned by the nextId function
-
refreshIdentifierFields
public static java.util.Set<java.lang.Integer> refreshIdentifierFields(Types.StructType freshSchema, Schema baseSchema)
Get the identifier fields in the fresh schema based on the identifier fields in the base schema.- Parameters:
freshSchema- fresh schemabaseSchema- base schema- Returns:
- identifier fields in the fresh schema
-
assignIncreasingFreshIds
public static Schema assignIncreasingFreshIds(Schema schema)
Assigns strictly increasing fresh ids for all fields in a schema, starting from 1.- Parameters:
schema- a schema- Returns:
- a structurally identical schema with new ids assigned strictly increasing from 1
-
reassignIds
public static Schema reassignIds(Schema schema, Schema idSourceSchema)
Reassigns ids in a schema from another schema.Ids are determined by field names. If a field in the schema cannot be found in the source schema, this will throw IllegalArgumentException.
This will not alter a schema's structure, nullability, or types.
- Parameters:
schema- the schema to have ids reassignedidSourceSchema- the schema from which field ids will be used- Returns:
- an structurally identical schema with field ids matching the source schema
- Throws:
java.lang.IllegalArgumentException- if a field cannot be found (by name) in the source schema
-
isPromotionAllowed
public static boolean isPromotionAllowed(Type from, Type.PrimitiveType to)
-
validateWriteSchema
public static void validateWriteSchema(Schema tableSchema, Schema writeSchema, java.lang.Boolean checkNullability, java.lang.Boolean checkOrdering)
Check whether we could write the iceberg table with the user-provided write schema.- Parameters:
tableSchema- the table schema written in iceberg meta data.writeSchema- the user-provided write schema.checkNullability- If true, not allow to write optional values to a required field.checkOrdering- If true, not allow input schema to have different ordering than table schema.
-
visit
public static <T> T visit(Schema schema, TypeUtil.SchemaVisitor<T> visitor)
-
visit
public static <T> T visit(Type type, TypeUtil.SchemaVisitor<T> visitor)
-
visit
public static <T> T visit(Schema schema, TypeUtil.CustomOrderSchemaVisitor<T> visitor)
-
visit
public static <T> T visit(Type type, TypeUtil.CustomOrderSchemaVisitor<T> visitor)
Used to traverse types with traversals other than pre-order.This passes a
Supplierto eachvisitormethod that returns the result of traversing child types. Structs are passed anIterablethat traverses child fields during iteration.An example use is assigning column IDs, which should be done with a post-order traversal.
- Type Parameters:
T- the type returned by the visitor- Parameters:
type- a type to traverse with a visitorvisitor- a custom order visitor- Returns:
- the result of traversing the given type with the visitor
-
decimalRequiredBytes
public static int decimalRequiredBytes(int precision)
-
-