public class Schema extends Object implements Comparable<Schema>, org.apache.hadoop.io.Writable
| Modifier and Type | Class and Description |
|---|---|
static class |
Schema.ColumnSchema
Column Schema in Schema
|
static class |
Schema.ParsedName
Helper class to parse a column name string one section at a time and find
the required type for the parsed part.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
COLUMN_DELIMITER |
| Constructor and Description |
|---|
Schema()
Constructor - schema for empty schema (zero-column) .
|
Schema(boolean projection)
Constructor - schema for empty projection/schema (zero-column) .
|
Schema(Schema.ColumnSchema fs) |
Schema(String schema)
Constructor - create a schema from a string representation.
|
Schema(String[] columns)
Constructor - create a schema from an array of column names.
|
Schema(String schema,
boolean projection) |
| Modifier and Type | Method and Description |
|---|---|
void |
add(Schema.ColumnSchema f)
add a column
|
int |
compareTo(Schema other) |
boolean |
equals(Object obj) |
Schema.ColumnSchema |
getColumn(int index)
Get a particular column's schema
|
Schema.ColumnSchema |
getColumn(String name)
get a column by name
|
int |
getColumnIndex(String name)
Get the index of the column for the input column name.
|
String |
getColumnName(int index) |
String[] |
getColumns()
Get the names of the individual columns.
|
Schema.ColumnSchema |
getColumnSchema(Schema.ParsedName pn)
find the most fitting subcolumn containing the name: the parsed name is set
after the field name plus any possible separator of '.' or '#'.
|
Schema.ColumnSchema |
getColumnSchema(String name)
Get a column's schema
|
Schema.ColumnSchema |
getColumnSchemaOnParsedName(Schema.ParsedName pn)
Get a subcolumn's schema and move the name just parsed into the next subtype
|
int |
getNumColumns()
Get the number of columns as defined in the schema.
|
Schema |
getProjectionSchema(String[] projcols,
HashMap<Schema.ColumnSchema,HashSet<String>> keysmap)
Get a projection's schema
|
String[] |
getTypedColumns()
Get the names and types of the individual columns.
|
static String |
normalize(String value)
Normalize the schema string.
|
static Schema |
parse(String schema)
Parse a schema string and create a schema object.
|
void |
readFields(DataInput in) |
String |
toProjectionString()
return untyped schema string for projection
|
String |
toString()
Convert the schema to a String.
|
void |
unionSchema(Schema other)
union compatible schemas.
|
void |
write(DataOutput out) |
public static final String COLUMN_DELIMITER
public Schema()
public Schema(boolean projection)
projection - A projection schema or notpublic Schema(String schema) throws ParseException
schema - A string representation of the schema. For this version, the
schema string is simply a comma separated list of column names. Of
course, comma (,) and space characters are illegal in column
names. To maintain forward compatibility, please use only
alpha-numeric characters in column names.ParseExceptionpublic Schema(String schema, boolean projection) throws ParseException
ParseExceptionpublic Schema(Schema.ColumnSchema fs) throws ParseException
ParseExceptionpublic Schema(String[] columns) throws ParseException
columns - An array of column names. To maintain forward compatibility,
please use only alpha-numeric characters in column names.ParseExceptionpublic void add(Schema.ColumnSchema f) throws ParseException
f - Column to be added to the schemaParseExceptionpublic Schema.ColumnSchema getColumn(String name)
public String[] getColumns()
public Schema.ColumnSchema getColumn(int index)
public String getColumnName(int index)
public String[] getTypedColumns()
public int getColumnIndex(String name)
name - input column name.public int getNumColumns()
public static Schema parse(String schema) throws ParseException
schema - comma separated schema string.ParseExceptionpublic String toString()
public static String normalize(String value)
value - the input string representation of the schema.public int compareTo(Schema other)
compareTo in interface Comparable<Schema>Comparable.compareTo(Object)public boolean equals(Object obj)
equals in class ObjectObject.equals(Object)public void readFields(DataInput in) throws IOException
readFields in interface org.apache.hadoop.io.WritableIOExceptionWritable.readFields(DataInput)public void write(DataOutput out) throws IOException
write in interface org.apache.hadoop.io.WritableIOExceptionWritable.write(DataOutput)public Schema getProjectionSchema(String[] projcols, HashMap<Schema.ColumnSchema,HashSet<String>> keysmap) throws ParseException
ParseExceptionpublic Schema.ColumnSchema getColumnSchema(String name) throws ParseException
name - column nameParseExceptionpublic Schema.ColumnSchema getColumnSchemaOnParsedName(Schema.ParsedName pn) throws ParseException
pn - The name of subcolumn to be parsed. On return it contains the
subcolumn at the next level after parsingParseExceptionpublic Schema.ColumnSchema getColumnSchema(Schema.ParsedName pn) throws ParseException
pn - The name of subcolumn to be parsed. On return it contains the
subcolumn at the next level after parsingParseExceptionpublic void unionSchema(Schema other) throws ParseException
ParseExceptionpublic String toProjectionString()
Copyright © 2007-2012 The Apache Software Foundation