Package org.datavec.api.transform.schema
Class Schema
- java.lang.Object
-
- org.datavec.api.transform.schema.Schema
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
SequenceSchema
public class Schema extends Object implements Serializable
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSchema.Builder
-
Constructor Summary
Constructors Modifier Constructor Description Schema(List<ColumnMetaData> columnMetaData)Create a schema based on the given metadataprotectedSchema(Schema.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<ColumnMetaData>differences(Schema schema)Compute the difference inColumnMetaDatabetween this schema and the passed in schema.static SchemafromJson(String json)Create a schema from a given json stringstatic SchemafromYaml(String yaml)Create a schema from the given yaml stringList<ColumnMetaData>getColumnMetaData()Returns a copy of the underlying schemaColumnMetaDataList<String>getColumnNames()Return a copy of the list column namesList<ColumnType>getColumnTypes()A copy of the list ofColumnTypefor this schemaintgetIndexOfColumn(String columnName)Returns the index for the given column nameint[]getIndexOfColumns(String... columnNames)Return the indices of the columns, given their namessint[]getIndexOfColumns(Collection<String> columnNames)Return the indices of the columns, given their namessColumnMetaDatagetMetaData(int column)Returns theColumnMetaDataat the specified column indexColumnMetaDatagetMetaData(String column)Retrieve the metadata for the given column nameStringgetName(int column)Returns the name of a given column at the specified indexColumnTypegetType(int column)Returns theColumnTypefor the column at the specified indexColumnTypegetType(String columnName)Returns theColumnTypefor the column at the specified indexbooleanhasColumn(String columnName)Determine if the schema has a column with the specified namestatic Schemainfer(List<Writable> record)Infers a schema based on the record.static SchemainferMultiple(List<List<Writable>> record)Infers a schema based on the record.SchemanewSchema(List<ColumnMetaData> columnMetaData)Create a new schema based on the new metadataintnumColumns()Returns the number of columns or fields for this schemabooleansameTypes(Schema schema)Returns true if the given schema has the same types at each indexStringtoJson()Serialize this schema to jsonStringtoString()StringtoYaml()Serialize this schema to yaml
-
-
-
Constructor Detail
-
Schema
protected Schema(Schema.Builder builder)
-
Schema
public Schema(List<ColumnMetaData> columnMetaData)
Create a schema based on the given metadata- Parameters:
columnMetaData- the metadata to create the schema from
-
-
Method Detail
-
sameTypes
public boolean sameTypes(Schema schema)
Returns true if the given schema has the same types at each index- Parameters:
schema- the schema to compare the types to- Returns:
- true if the schema has the same types at every index as this one,false otherwise
-
differences
public List<ColumnMetaData> differences(Schema schema)
Compute the difference inColumnMetaDatabetween this schema and the passed in schema. This is useful during theTransformProcessto identify what a process will do to a givenSchema.- Parameters:
schema- the schema to compute the difference for- Returns:
- the metadata that is different (in order) between this schema and the other schema
-
newSchema
public Schema newSchema(List<ColumnMetaData> columnMetaData)
Create a new schema based on the new metadata- Parameters:
columnMetaData- the new metadata to create the schema from- Returns:
- the new schema
-
numColumns
public int numColumns()
Returns the number of columns or fields for this schema- Returns:
- the number of columns or fields for this schema
-
getName
public String getName(int column)
Returns the name of a given column at the specified index- Parameters:
column- the index of the column to get the name for- Returns:
- the name of the column at the specified index
-
getType
public ColumnType getType(int column)
Returns theColumnTypefor the column at the specified index- Parameters:
column- the index of the column to get the type for- Returns:
- the type of the column to at the specified inde
-
getType
public ColumnType getType(String columnName)
Returns theColumnTypefor the column at the specified index- Parameters:
columnName- the index of the column to get the type for- Returns:
- the type of the column to at the specified inde
-
getMetaData
public ColumnMetaData getMetaData(int column)
Returns theColumnMetaDataat the specified column index- Parameters:
column- the index to get the metadata for- Returns:
- the metadata at ths specified index
-
getMetaData
public ColumnMetaData getMetaData(String column)
Retrieve the metadata for the given column name- Parameters:
column- the name of the column to get metadata for- Returns:
- the metadata for the given column name
-
getColumnNames
public List<String> getColumnNames()
Return a copy of the list column names- Returns:
- a copy of the list of column names for this schema
-
getColumnTypes
public List<ColumnType> getColumnTypes()
A copy of the list ofColumnTypefor this schema- Returns:
- the list of column types in order based on column index for this schema
-
getColumnMetaData
public List<ColumnMetaData> getColumnMetaData()
Returns a copy of the underlying schemaColumnMetaData- Returns:
- the list of schema metadata
-
getIndexOfColumn
public int getIndexOfColumn(String columnName)
Returns the index for the given column name- Parameters:
columnName- the column name to get the index for- Returns:
- the index of the given column name for the schema
-
getIndexOfColumns
public int[] getIndexOfColumns(Collection<String> columnNames)
Return the indices of the columns, given their namess- Parameters:
columnNames- Name of the columns to get indices for- Returns:
- Column indexes
-
getIndexOfColumns
public int[] getIndexOfColumns(String... columnNames)
Return the indices of the columns, given their namess- Parameters:
columnNames- Name of the columns to get indices for- Returns:
- Column indexes
-
hasColumn
public boolean hasColumn(String columnName)
Determine if the schema has a column with the specified name- Parameters:
columnName- Name to see if the column exists- Returns:
- True if a column exists for that name, false otherwise
-
toJson
public String toJson()
Serialize this schema to json- Returns:
- a json representation of this schema
-
toYaml
public String toYaml()
Serialize this schema to yaml- Returns:
- the yaml representation of this schema
-
fromJson
public static Schema fromJson(String json)
Create a schema from a given json string- Parameters:
json- the json to create the schema from- Returns:
- the created schema based on the json
-
fromYaml
public static Schema fromYaml(String yaml)
Create a schema from the given yaml string- Parameters:
yaml- the yaml to create the schema from- Returns:
- the created schema based on the yaml
-
inferMultiple
public static Schema inferMultiple(List<List<Writable>> record)
Infers a schema based on the record. The column names are based on indexing.- Parameters:
record- the record to infer from- Returns:
- the infered schema
-
-