Package io.delta.kernel.internal.util
Class SchemaIterable
Object
io.delta.kernel.internal.util.SchemaIterable
- All Implemented Interfaces:
Iterable<SchemaIterable.SchemaElement>
Utility class for iterating over schema structures and modifying them.
Sample usage for iterating schemas:
StructType schema = ...;
for (SchemaIterable.SchemaElement element : new SchemaIterable(schema)) {
StructField field = element.getField();
// Get info from field in some way.
}
Sample usage for mutating schemas:
StructType schema = ...;
SchemaIterable schemaIterable = new SchemaIterable(schema);
Iterator<SchemaIterable.MutableSchemaElement> iterator = schemaIterable.newMutableIterator();
while (iterator.hasNext()) {
SchemaIterable.MutableSchemaElement element = iterator.next();
// Calculate a new field in some way then call updateField.
element.updateField(...)
}
updatedSchema = schemaIterable.getSchema();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface for manipulating Schema elements.static classContainer for parent StructField information returned bySchemaIterable.SchemaElement.getParentStructFieldAndPath().static interfaceInterface for representing a schema element as part of a traversal. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the latest schema (either the initial schema or the one set after a mutable iterator is fully consumed).iterator()Returns a new iterator that can be used to iterate and update elements in the schema.static SchemaIterablenewSchemaIterableWithIgnoredRecursion(StructType schema, Class<?>[] typesToSkipRecursion) Constructs a new iterable that skips recursion for some data types.stream()Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
SchemaIterable
Construct a new Iterable for the schema.
-
-
Method Details
-
newSchemaIterableWithIgnoredRecursion
public static SchemaIterable newSchemaIterableWithIgnoredRecursion(StructType schema, Class<?>[] typesToSkipRecursion) Constructs a new iterable that skips recursion for some data types.No recursion will be done on any type that is an instance of a class in typesToSkipRecursion.
For example with schema:
a: Map<String, Int> b: Array<Int>If
typesToSkipRecursion = {MapType.class}is provided then the iterator will only visit "a", "b.element", and "b".If
typesToSkipRecursion = {ArrayType.class}is provided then the iterator wil only visit "a.key", "a.value", "a" and "b". -
getSchema
Gets the latest schema (either the initial schema or the one set after a mutable iterator is fully consumed). -
iterator
- Specified by:
iteratorin interfaceIterable<SchemaIterable.SchemaElement>
-
stream
-
mutableStream
-
newMutableIterator
Returns a new iterator that can be used to iterate and update elements in the schema. The current schema on this iterable is updated once the returned iterator is fully consumed.Consuming multiple iterators across different threads concurrently is not thread safe.
Example usage:
Iterator<SchemaIterable.MutableSchemaElement> iterator = schemaIterable.newMutableIterator(); while (iterator.hasNext()) { SchemaIterable.MutableSchemaElement element = iterator.next(); element.updateField(...) } updatedSchema = schemaIterable.getSchema();
-