public class Schema
extends java.lang.Object
implements java.io.Serializable
See also: SequenceSchema
Modifier and Type | Class and Description |
---|---|
static class |
Schema.Builder |
Modifier | Constructor and Description |
---|---|
|
Schema(java.util.List<ColumnMetaData> columnMetaData)
Create a schema based on the
given metadata
|
protected |
Schema(Schema.Builder builder) |
Modifier and Type | Method and Description |
---|---|
java.util.List<ColumnMetaData> |
differences(Schema schema)
Compute the difference in
ColumnMetaData
between this schema and the passed in schema. |
static Schema |
fromJson(java.lang.String json)
Create a schema from a given json string
|
static Schema |
fromYaml(java.lang.String yaml)
Create a schema from the given
yaml string
|
java.util.List<ColumnMetaData> |
getColumnMetaData()
Returns a copy of the underlying
schema
ColumnMetaData |
java.util.List<java.lang.String> |
getColumnNames()
Return a copy of the list column names
|
java.util.List<ColumnType> |
getColumnTypes()
A copy of the list of
ColumnType
for this schema |
int |
getIndexOfColumn(java.lang.String columnName)
Returns the index for the given
column name
|
ColumnMetaData |
getMetaData(int column)
Returns the
ColumnMetaData
at the specified column index |
ColumnMetaData |
getMetaData(java.lang.String column)
Retrieve the metadata for the given
column name
|
java.lang.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 |
boolean |
hasColumn(java.lang.String columnName)
Determine if the schema has a column with the specified name
|
static Schema |
infer(java.util.List<Writable> record)
Infers a schema based on the record.
|
static Schema |
inferMultiple(java.util.List<java.util.List<Writable>> record)
Infers a schema based on the record.
|
Schema |
newSchema(java.util.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
|
java.lang.String |
toJson()
Serialize this schema to json
|
java.lang.String |
toString() |
java.lang.String |
toYaml()
Serialize this schema to yaml
|
protected Schema(Schema.Builder builder)
public Schema(java.util.List<ColumnMetaData> columnMetaData)
columnMetaData
- the metadata to create the
schema frompublic boolean sameTypes(Schema schema)
schema
- the schema to compare the types topublic java.util.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(java.util.List<ColumnMetaData> columnMetaData)
columnMetaData
- the new metadata to create the
schema frompublic int numColumns()
public java.lang.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 ColumnMetaData getMetaData(int column)
ColumnMetaData
at the specified column indexcolumn
- the index
to get the metadata forpublic ColumnMetaData getMetaData(java.lang.String column)
column
- the name of the column to get metadata forpublic java.util.List<java.lang.String> getColumnNames()
public java.util.List<ColumnType> getColumnTypes()
ColumnType
for this schemapublic java.util.List<ColumnMetaData> getColumnMetaData()
ColumnMetaData
public int getIndexOfColumn(java.lang.String columnName)
columnName
- the column name to get the
index forpublic boolean hasColumn(java.lang.String columnName)
columnName
- Name to see if the column existspublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toJson()
public java.lang.String toYaml()
public static Schema fromJson(java.lang.String json)
json
- the json to create the schema frompublic static Schema fromYaml(java.lang.String yaml)
yaml
- the yaml to create the schema frompublic static Schema inferMultiple(java.util.List<java.util.List<Writable>> record)
record
- the record to infer from