public class Schema
extends java.lang.Object
implements java.io.Serializable
Schema ID will only be populated when reading from/writing to table metadata, otherwise it will be default to 0.
Constructor and Description |
---|
Schema(int schemaId,
java.util.List<Types.NestedField> columns) |
Schema(int schemaId,
java.util.List<Types.NestedField> columns,
java.util.Map<java.lang.String,java.lang.Integer> aliases,
java.util.Set<java.lang.Integer> identifierFieldIds) |
Schema(int schemaId,
java.util.List<Types.NestedField> columns,
java.util.Set<java.lang.Integer> identifierFieldIds) |
Schema(int schemaId,
Types.NestedField... columns) |
Schema(java.util.List<Types.NestedField> columns) |
Schema(java.util.List<Types.NestedField> columns,
java.util.Map<java.lang.String,java.lang.Integer> aliases) |
Schema(java.util.List<Types.NestedField> columns,
java.util.Map<java.lang.String,java.lang.Integer> aliases,
java.util.Set<java.lang.Integer> identifierFieldIds) |
Schema(java.util.List<Types.NestedField> columns,
java.util.Set<java.lang.Integer> identifierFieldIds) |
Schema(Types.NestedField... columns) |
Modifier and Type | Method and Description |
---|---|
Accessor<StructLike> |
accessorForField(int id)
Returns an accessor for retrieving the data from
StructLike . |
java.lang.Integer |
aliasToId(java.lang.String alias)
Returns the column id for the given column alias.
|
Types.StructType |
asStruct()
Returns the underlying
struct type for this schema. |
Types.NestedField |
caseInsensitiveFindField(java.lang.String name)
Returns a sub-field by name as a
Types.NestedField . |
Schema |
caseInsensitiveSelect(java.util.Collection<java.lang.String> names)
Creates a projection schema for a subset of columns, selected by case insensitive names
|
Schema |
caseInsensitiveSelect(java.lang.String... names)
Creates a projection schema for a subset of columns, selected by case insensitive names
|
java.util.List<Types.NestedField> |
columns()
Returns a List of the
columns in this Schema. |
java.lang.String |
findColumnName(int id)
Returns the full column name for the given id.
|
Types.NestedField |
findField(int id)
Returns the sub-field identified by the field id as a
Types.NestedField . |
Types.NestedField |
findField(java.lang.String name)
Returns a sub-field by name as a
Types.NestedField . |
Type |
findType(int id)
Returns the
Type of a sub-field identified by the field id. |
Type |
findType(java.lang.String name)
Returns the
Type of a sub-field identified by the field name. |
java.util.Map<java.lang.String,java.lang.Integer> |
getAliases()
Returns an alias map for this schema, if set.
|
int |
highestFieldId()
Returns the highest field ID in this schema, including nested fields.
|
java.util.Set<java.lang.Integer> |
identifierFieldIds()
The set of identifier field IDs.
|
java.util.Set<java.lang.String> |
identifierFieldNames()
Returns the set of identifier field names.
|
java.lang.String |
idToAlias(java.lang.Integer fieldId)
Returns the full column name in the unconverted data schema for the given column id.
|
java.util.Map<java.lang.Integer,java.lang.String> |
idToName()
Returns a map for this schema between field id and qualified field names.
|
boolean |
sameSchema(Schema anotherSchema)
Checks whether this schema is equivalent to another schema while ignoring the schema ID.
|
int |
schemaId()
Returns the schema ID for this schema.
|
Schema |
select(java.util.Collection<java.lang.String> names)
Creates a projection schema for a subset of columns, selected by name.
|
Schema |
select(java.lang.String... names)
Creates a projection schema for a subset of columns, selected by name.
|
java.lang.String |
toString() |
public Schema(java.util.List<Types.NestedField> columns, java.util.Map<java.lang.String,java.lang.Integer> aliases)
public Schema(java.util.List<Types.NestedField> columns, java.util.Map<java.lang.String,java.lang.Integer> aliases, java.util.Set<java.lang.Integer> identifierFieldIds)
public Schema(java.util.List<Types.NestedField> columns)
public Schema(java.util.List<Types.NestedField> columns, java.util.Set<java.lang.Integer> identifierFieldIds)
public Schema(int schemaId, java.util.List<Types.NestedField> columns)
public Schema(int schemaId, java.util.List<Types.NestedField> columns, java.util.Set<java.lang.Integer> identifierFieldIds)
public Schema(int schemaId, java.util.List<Types.NestedField> columns, java.util.Map<java.lang.String,java.lang.Integer> aliases, java.util.Set<java.lang.Integer> identifierFieldIds)
public Schema(Types.NestedField... columns)
public Schema(int schemaId, Types.NestedField... columns)
public int schemaId()
Note that schema ID will only be populated when reading from/writing to table metadata, otherwise it will be default to 0.
public int highestFieldId()
public java.util.Map<java.lang.String,java.lang.Integer> getAliases()
Alias maps are created when translating an external schema, like an Avro Schema, to this format. The original column names can be provided in a Map when constructing this Schema.
public java.util.Map<java.lang.Integer,java.lang.String> idToName()
public Types.StructType asStruct()
struct type
for this schema.public java.util.List<Types.NestedField> columns()
columns
in this Schema.public java.util.Set<java.lang.Integer> identifierFieldIds()
Identifier is a concept similar to primary key in a relational database system. It consists of a unique set of primitive fields in the schema. An identifier field must be at root, or nested in a chain of structs (no maps or lists). A row should be unique in a table based on the values of the identifier fields. Optional, float and double columns cannot be used as identifier fields. However, Iceberg identifier differs from primary key in the following ways:
public java.util.Set<java.lang.String> identifierFieldNames()
public Type findType(java.lang.String name)
Type
of a sub-field identified by the field name.name
- a field namepublic Type findType(int id)
Type
of a sub-field identified by the field id.id
- a field idpublic Types.NestedField findField(int id)
Types.NestedField
.id
- a field idpublic Types.NestedField findField(java.lang.String name)
Types.NestedField
.
The result may be a top-level or a nested field.
name
- a String namepublic Types.NestedField caseInsensitiveFindField(java.lang.String name)
Types.NestedField
.
The result may be a top-level or a nested field.
name
- a String namepublic java.lang.String findColumnName(int id)
id
- a field idpublic java.lang.Integer aliasToId(java.lang.String alias)
alias
- a full column name in the unconverted data schemapublic java.lang.String idToAlias(java.lang.Integer fieldId)
fieldId
- a column id in this schemapublic Accessor<StructLike> accessorForField(int id)
StructLike
.
Accessors do not retrieve data contained in lists or maps.
id
- a column id in this schemaAccessor
to retrieve values from a StructLike
rowpublic Schema select(java.lang.String... names)
Names that identify nested fields will select part or all of the field's top-level column.
names
- String names for selected columnspublic Schema select(java.util.Collection<java.lang.String> names)
Names that identify nested fields will select part or all of the field's top-level column.
names
- a List of String names for selected columnspublic Schema caseInsensitiveSelect(java.lang.String... names)
Names that identify nested fields will select part or all of the field's top-level column.
names
- a List of String names for selected columnspublic Schema caseInsensitiveSelect(java.util.Collection<java.lang.String> names)
Names that identify nested fields will select part or all of the field's top-level column.
names
- a List of String names for selected columnspublic boolean sameSchema(Schema anotherSchema)
anotherSchema
- another schemapublic java.lang.String toString()
toString
in class java.lang.Object