Package org.apache.pinot.spi.data
Class Schema
- java.lang.Object
-
- org.apache.pinot.spi.data.Schema
-
- All Implemented Interfaces:
Serializable
public final class Schema extends Object implements Serializable
TheSchemaclass is defined for each table to describe the details of the table's fields (columns).Four field types are supported: DIMENSION, METRIC, TIME, DATE_TIME. (
DimensionFieldSpec,MetricFieldSpec,TimeFieldSpec,DateTimeFieldSpec)For each field, a
FieldSpecis defined to provide the details of the field.There could be multiple DIMENSION or METRIC or DATE_TIME fields, but at most 1 TIME field.
In pinot, we store data using 5
DataTypes: INT, LONG, FLOAT, DOUBLE, STRING. All otherDataTypes will be converted to one of them.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSchema.SchemaBuilder
-
Constructor Summary
Constructors Constructor Description Schema()
-
Method Summary
Modifier and Type Method Description voidaddField(String columnName, FieldSpec fieldSpec)Deprecated.voidaddField(FieldSpec fieldSpec)Schemaclone()static DateTimeFieldSpecconvertToDateTimeFieldSpec(TimeFieldSpec timeFieldSpec)Helper method that converts aTimeFieldSpectoDateTimeFieldSpec1) If timeFieldSpec contains only incoming granularity spec, directly convert it to a dateTimeFieldSpec 2) If timeFieldSpec contains incoming aas well as outgoing granularity spec, use the outgoing spec to construct the dateTimeFieldSpec, and configure a transform function for the conversion from incomingbooleanequals(Object o)static SchemafromFile(File schemaFile)static SchemafromInputStream(InputStream schemaInputStream)static SchemafromString(String schemaString)Collection<FieldSpec>getAllFieldSpecs()Set<String>getColumnNames()List<DateTimeFieldSpec>getDateTimeFieldSpecs()List<String>getDateTimeNames()DateTimeFieldSpecgetDateTimeSpec(String dateTimeName)List<DimensionFieldSpec>getDimensionFieldSpecs()List<String>getDimensionNames()DimensionFieldSpecgetDimensionSpec(String dimensionName)FieldSpecgetFieldSpecFor(String columnName)Map<String,FieldSpec>getFieldSpecMap()List<MetricFieldSpec>getMetricFieldSpecs()List<String>getMetricNames()MetricFieldSpecgetMetricSpec(String metricName)Set<String>getPhysicalColumnNames()List<String>getPrimaryKeyColumns()StringgetSchemaName()NOTE: schema name could be null in testsDateTimeFieldSpecgetSpecForTimeColumn(String timeColumnName)Fetches the DateTimeFieldSpec for the given time column name.TimeFieldSpecgetTimeFieldSpec()booleanhasColumn(String columnName)inthashCode()booleanhasJSONColumn()booleanisBackwardCompatibleWith(Schema oldSchema)Check whether the current schema is backward compatible with oldSchema.static org.apache.commons.lang3.tuple.Pair<Schema,Map<String,Object>>parseSchemaAndUnrecognizedPropsfromInputStream(InputStream schemaInputStream)booleanremoveField(String columnName)voidsetDateTimeFieldSpecs(List<DateTimeFieldSpec> dateTimeFieldSpecs)Deprecated.voidsetDimensionFieldSpecs(List<DimensionFieldSpec> dimensionFieldSpecs)Deprecated.voidsetMetricFieldSpecs(List<MetricFieldSpec> metricFieldSpecs)Deprecated.voidsetPrimaryKeyColumns(List<String> primaryKeyColumns)voidsetSchemaName(String schemaName)voidsetTimeFieldSpec(TimeFieldSpec timeFieldSpec)Deprecated.intsize()com.fasterxml.jackson.databind.node.ObjectNodetoJsonObject()Returns a json representation of the schema.StringtoPrettyJsonString()Returns a pretty json string representation of the schema.StringtoSingleLineJsonString()Returns a single-line json string representation of the schema.StringtoString()voidupdateBooleanFieldsIfNeeded(Schema oldSchema)Updates fields with BOOLEAN data type to STRING if the data type in the old schema is STRING.voidvalidate()Validates a pinot schema.
-
-
-
Method Detail
-
fromFile
public static Schema fromFile(File schemaFile) throws IOException
- Throws:
IOException
-
fromString
public static Schema fromString(String schemaString) throws IOException
- Throws:
IOException
-
parseSchemaAndUnrecognizedPropsfromInputStream
public static org.apache.commons.lang3.tuple.Pair<Schema,Map<String,Object>> parseSchemaAndUnrecognizedPropsfromInputStream(InputStream schemaInputStream) throws IOException
- Throws:
IOException
-
fromInputStream
public static Schema fromInputStream(InputStream schemaInputStream) throws IOException
- Throws:
IOException
-
getSchemaName
public String getSchemaName()
NOTE: schema name could be null in tests
-
setSchemaName
public void setSchemaName(String schemaName)
-
getDimensionFieldSpecs
public List<DimensionFieldSpec> getDimensionFieldSpecs()
-
setDimensionFieldSpecs
@Deprecated public void setDimensionFieldSpecs(List<DimensionFieldSpec> dimensionFieldSpecs)
Deprecated.Required by JSON deserializer. DO NOT USE. DO NOT REMOVE. Adding @Deprecated to prevent usage
-
getMetricFieldSpecs
public List<MetricFieldSpec> getMetricFieldSpecs()
-
setMetricFieldSpecs
@Deprecated public void setMetricFieldSpecs(List<MetricFieldSpec> metricFieldSpecs)
Deprecated.Required by JSON deserializer. DO NOT USE. DO NOT REMOVE. Adding @Deprecated to prevent usage
-
getDateTimeFieldSpecs
public List<DateTimeFieldSpec> getDateTimeFieldSpecs()
-
setDateTimeFieldSpecs
@Deprecated public void setDateTimeFieldSpecs(List<DateTimeFieldSpec> dateTimeFieldSpecs)
Deprecated.Required by JSON deserializer. DO NOT USE. DO NOT REMOVE. Adding @Deprecated to prevent usage
-
getTimeFieldSpec
public TimeFieldSpec getTimeFieldSpec()
-
setTimeFieldSpec
@Deprecated public void setTimeFieldSpec(TimeFieldSpec timeFieldSpec)
Deprecated.Required by JSON deserializer. DO NOT USE. DO NOT REMOVE. Adding @Deprecated to prevent usage
-
addField
public void addField(FieldSpec fieldSpec)
-
addField
@Deprecated public void addField(String columnName, FieldSpec fieldSpec)
Deprecated.
-
removeField
public boolean removeField(String columnName)
-
hasColumn
public boolean hasColumn(String columnName)
-
hasJSONColumn
public boolean hasJSONColumn()
-
getAllFieldSpecs
public Collection<FieldSpec> getAllFieldSpecs()
-
size
public int size()
-
getMetricSpec
public MetricFieldSpec getMetricSpec(String metricName)
-
getDimensionSpec
public DimensionFieldSpec getDimensionSpec(String dimensionName)
-
getDateTimeSpec
public DateTimeFieldSpec getDateTimeSpec(String dateTimeName)
-
getSpecForTimeColumn
@Nullable public DateTimeFieldSpec getSpecForTimeColumn(String timeColumnName)
Fetches the DateTimeFieldSpec for the given time column name. If the columnName is a DATE_TIME column, returns the DateTimeFieldSpec If the columnName is a TIME column, converts to DateTimeFieldSpec before returning
-
toJsonObject
public com.fasterxml.jackson.databind.node.ObjectNode toJsonObject()
Returns a json representation of the schema.
-
toPrettyJsonString
public String toPrettyJsonString()
Returns a pretty json string representation of the schema.
-
toSingleLineJsonString
public String toSingleLineJsonString()
Returns a single-line json string representation of the schema.
-
validate
public void validate()
Validates a pinot schema.The following validations are performed:
- For dimension, time, date time fields, support
FieldSpec.DataType: INT, LONG, FLOAT, DOUBLE, BOOLEAN, TIMESTAMP, STRING, BYTES - For metric fields, support
FieldSpec.DataType: INT, LONG, FLOAT, DOUBLE, BYTES
- For dimension, time, date time fields, support
-
updateBooleanFieldsIfNeeded
public void updateBooleanFieldsIfNeeded(Schema oldSchema)
Updates fields with BOOLEAN data type to STRING if the data type in the old schema is STRING. BOOLEAN data type was stored as STRING within the schema before release 0.8.0. In release 0.8.0, we introduced native BOOLEAN support and BOOLEAN data type is no longer replaced with STRING. To keep the existing schema backward compatible, when the new field spec has BOOLEAN data type and the old field spec has STRING data type, set the new field spec's data type to STRING.
-
isBackwardCompatibleWith
public boolean isBackwardCompatibleWith(Schema oldSchema)
Check whether the current schema is backward compatible with oldSchema. Backward compatibility requires (1) all columns in oldSchema should be retained. (2) all column fieldSpecs should be backward compatible with the old ones.- Parameters:
oldSchema- old schema
-
convertToDateTimeFieldSpec
public static DateTimeFieldSpec convertToDateTimeFieldSpec(TimeFieldSpec timeFieldSpec)
Helper method that converts aTimeFieldSpectoDateTimeFieldSpec1) If timeFieldSpec contains only incoming granularity spec, directly convert it to a dateTimeFieldSpec 2) If timeFieldSpec contains incoming aas well as outgoing granularity spec, use the outgoing spec to construct the dateTimeFieldSpec, and configure a transform function for the conversion from incoming
-
-