public class Schema extends Object implements Serializable
See also: SequenceSchema
| Modifier and Type | Class and Description |
|---|---|
static class |
Schema.Builder |
| Modifier | Constructor and Description |
|---|---|
|
Schema(List<ColumnMetaData> columnMetaData)
Create a schema based on the
given metadata
|
protected |
Schema(Schema.Builder builder) |
| Modifier and Type | Method and Description |
|---|---|
List<ColumnMetaData> |
differences(Schema schema)
Compute the difference in
ColumnMetaData
between this schema and the passed in schema. |
static Schema |
fromJson(String json)
Create a schema from a given json string
|
static Schema |
fromYaml(String yaml)
Create a schema from the given
yaml string
|
List<ColumnMetaData> |
getColumnMetaData()
Returns a copy of the underlying
schema
ColumnMetaData |
List<String> |
getColumnNames()
Return a copy of the list column names
|
List<ColumnType> |
getColumnTypes()
A copy of the list of
ColumnType
for this schema |
int |
getIndexOfColumn(String columnName)
Returns the index for the given
column name
|
int[] |
getIndexOfColumns(Collection<String> columnNames)
Return the indices of the columns, given their namess
|
int[] |
getIndexOfColumns(String... columnNames)
Return the indices of the columns, given their namess
|
ColumnMetaData |
getMetaData(int column)
Returns the
ColumnMetaData
at the specified column index |
ColumnMetaData |
getMetaData(String column)
Retrieve the metadata for the given
column name
|
String |
getName(int column)
Returns the name of a
given column at the specified index
|
ColumnType |
getType(int column)
Returns the
ColumnType
for the column at the specified index |
ColumnType |
getType(String columnName)
Returns the
ColumnType
for the column at the specified index |
boolean |
hasColumn(String columnName)
Determine if the schema has a column with the specified name
|
static Schema |
infer(List<Writable> record)
Infers a schema based on the record.
|
static Schema |
inferMultiple(List<List<Writable>> record)
Infers a schema based on the record.
|
Schema |
newSchema(List<ColumnMetaData> columnMetaData)
Create a new schema based on the new metadata
|
int |
numColumns()
Returns the number of columns or fields
for this schema
|
boolean |
sameTypes(Schema schema)
Returns true if the given schema
has the same types at each index
|
String |
toJson()
Serialize this schema to json
|
String |
toString() |
String |
toYaml()
Serialize this schema to yaml
|
protected Schema(Schema.Builder builder)
public Schema(List<ColumnMetaData> columnMetaData)
columnMetaData - the metadata to create the
schema frompublic boolean sameTypes(Schema schema)
schema - the schema to compare the types topublic List<ColumnMetaData> differences(Schema schema)
ColumnMetaData
between this schema and the passed in schema.
This is useful during the TransformProcess
to identify what a process will do to a given Schema.schema - the schema to compute the difference forpublic Schema newSchema(List<ColumnMetaData> columnMetaData)
columnMetaData - the new metadata to create the
schema frompublic int numColumns()
public String getName(int column)
column - the index of the column
to get the name forpublic ColumnType getType(int column)
ColumnType
for the column at the specified indexcolumn - the index of the column to get the type forpublic ColumnType getType(String columnName)
ColumnType
for the column at the specified indexcolumnName - the index of the column to get the type forpublic ColumnMetaData getMetaData(int column)
ColumnMetaData
at the specified column indexcolumn - the index
to get the metadata forpublic ColumnMetaData getMetaData(String column)
column - the name of the column to get metadata forpublic List<String> getColumnNames()
public List<ColumnType> getColumnTypes()
ColumnType
for this schemapublic List<ColumnMetaData> getColumnMetaData()
ColumnMetaDatapublic int getIndexOfColumn(String columnName)
columnName - the column name to get the
index forpublic int[] getIndexOfColumns(Collection<String> columnNames)
columnNames - Name of the columns to get indices forpublic int[] getIndexOfColumns(String... columnNames)
columnNames - Name of the columns to get indices forpublic boolean hasColumn(String columnName)
columnName - Name to see if the column existspublic String toJson()
public String toYaml()
public static Schema fromJson(String json)
json - the json to create the schema frompublic static Schema fromYaml(String yaml)
yaml - the yaml to create the schema frompublic static Schema inferMultiple(List<List<Writable>> record)
record - the record to infer fromCopyright © 2019. All rights reserved.