Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
- data Table = Table {
- tableName :: !TableName
- tableColumns :: ![Column]
- tableConstraints :: ![TableConstraint]
- type TableName = Text
- data TableConstraint
- = PrimaryKey { }
- | UniqueKey { }
- | ForeignKey { }
- data Column = Column {}
- type ColumnName = Text
- type ColumnType = Text
- data Nullable
- data Fact = Fact {
- factName :: !TableName
- factTableName :: !TableName
- factTablePersistent :: !Bool
- factParentNames :: ![TableName]
- factColumns :: ![FactColumn]
- data FactColumn = FactColumn {}
- data FactColumnType a where
- DimTime :: FactColumnType FCKNone
- NoDimId :: FactColumnType FCKNone
- TenantId :: FactColumnType FCKNone
- DimId :: {..} -> FactColumnType FCKTargetTable
- DimVal :: {..} -> FactColumnType FCKTargetTable
- FactCount :: {..} -> FactColumnType FCKMaybeSourceColumn
- FactCountDistinct :: {..} -> FactColumnType FCKMaybeSourceColumn
- FactSum :: {..} -> FactColumnType FCKSourceColumn
- FactAverage :: {..} -> FactColumnType FCKSourceColumn
- FactMax :: {..} -> FactColumnType FCKSourceColumn
- FactMin :: {..} -> FactColumnType FCKSourceColumn
- data FactColumnKind
- factSourceColumnName :: FactColumn -> Maybe ColumnName
- data TimeUnit
- timeUnitName :: TimeUnit -> Text
- timeUnitToSeconds :: TimeUnit -> Int
- data Config
- configTables :: Config -> [Table]
- configFacts :: Config -> [Fact]
- configSettings :: Config -> Settings
- configTypeDefaults :: Config -> TypeDefaults
- data Settings = Settings {
- settingDimPrefix :: !Text
- settingFactPrefix :: !Text
- settingFactInfix :: !Text
- settingTimeUnit :: !TimeUnit
- settingAvgCountColumnSuffix :: !Text
- settingAvgSumColumnSuffix :: !Text
- settingDimTableIdColumnName :: !Text
- settingDimTableIdColumnType :: !Text
- settingFactCountColumnType :: !Text
- settingFactCountDistinctErrorRate :: !Double
- settingDependenciesJSONFileName :: !Text
- settingFactsJSONFileName :: !Text
- settingDimensionsJSONFileName :: !Text
- settingForeignKeyIdCoalesceValue :: !Int
- settingTableNameSuffixTemplate :: !Text
- defSettings :: Settings
- type TypeDefaults = Map Text Text
- data ValidationError
- = MissingTable !TableName
- | MissingFact !TableName
- | MissingColumn !TableName !ColumnName
- | MissingTimeColumn !TableName
- | MissingNotNullConstraint !TableName !ColumnName
- | MissingTypeDefault !Text
- | DuplicateTable !TableName
- | DuplicateFact !TableName
- | DuplicateColumn !TableName !ColumnName
- | DuplicateDimension !TableName
- data TablePopulationMode
- type Dependencies = Map TableName [TableName]
Documentation
A table representing a physical table in the database
The following example represents a set of tables from a multi-publisher blog system:
>>>
:set -XOverloadedStrings
>>>
:{
let publishersTable = Table { tableName = "publishers" , tableColumns = [ Column "id" "integer" NotNull , Column "name" "varchar(100)" NotNull ] , tableConstraints = [ PrimaryKey "id" , UniqueKey [ "name" ] ] } usersTable = Table { tableName = "users" , tableColumns = [ Column "id" "uuid" NotNull , Column "created_at" "timestamp" NotNull , Column "pub_id" "integer" NotNull , Column "username" "varchar(100)" NotNull , Column "email" "varchar(500)" Null ] , tableConstraints = [ PrimaryKey "id" , ForeignKey "publishers" [ ("pub_id", "id") ] , UniqueKey [ "pub_id", "username" ] ] } -- This table records the time spent by each user on a post postViewEventsTable = Table { tableName = "post_view_events" , tableColumns = [ Column "id" "uuid" NotNull , Column "created_at" "timestamp" NotNull , Column "user_id" "uuid" NotNull , Column "pub_id" "integer" NotNull , Column "post_id" "uuid" NotNull , Column "geo_city" "varchar(100)" Null , Column "geo_country" "varchar(100)" Null , Column "device_version" "varchar(25)" Null , Column "device_name" "varchar(100)" Null , Column "device_type" "varchar(50)" Null , Column "time_spent" "integer" NotNull ] , tableConstraints = [ PrimaryKey "id" , ForeignKey "users" [ ("user_id", "id") ] , ForeignKey "publishers" [ ("pub_id", "id") ] ] } :}
Table | |
|
data TableConstraint Source #
A constraint on a Table
PrimaryKey | A primary key constraint |
| |
UniqueKey | A unique key contraint |
| |
ForeignKey | A foreign key constraint |
|
A column of a Table
Column | |
|
type ColumnName = Text Source #
Name of a Column
type ColumnType = Text Source #
Type of a Column
Nullness of a Column
A fact is a table that records measurements or metrics for a specific event
The following represents a fact for the same multi-publisher blog system:
>>>
:{
let postFact = Fact { factName = "post_views" , factTableName = "post_view_events" , factTablePersistent = True , factParentNames = [] , factColumns = [ FactColumn "created_at" $ DimTime , FactColumn "publisher_id" $ TenantId , FactColumn "user_id" $ DimId "users" , FactColumn "post_id" $ NoDimId , FactColumn "geo_city" $ DimVal "geo" , FactColumn "geo_country" $ DimVal "geo" , FactColumn "device_name" $ DimVal "device" , FactColumn "device_type" $ DimVal "device" , FactColumn "count" $ FactCount Nothing , FactColumn "unq_device_count" $ FactCountDistinct $ Just "device_name" , FactColumn "time_spent" $ FactSum "time_spent" , FactColumn "max_time_spent" $ FactMax "time_spent" ] } :}
Fact | |
|
data FactColumn Source #
A column in a fact table
FactColumn | |
|
data FactColumnType a where Source #
Type of a fact column
DimTime :: FactColumnType FCKNone | A fact column which contains a time dimension data (e.g. |
NoDimId :: FactColumnType FCKNone | A fact column which contains an id of a dimension which does not need to extracted as a table and does not exist already. |
TenantId :: FactColumnType FCKNone | A fact column which constains an id of a tenant in a multi-tenant database (e.g. |
DimId :: {..} -> FactColumnType FCKTargetTable | A fact column which constains an id of a dimension which does not need to extracted as a table and exists already. |
| |
DimVal :: {..} -> FactColumnType FCKTargetTable | A fact column which constains a value which needs to be extracted to a dimension table. Multiple DimVal fact columns can be extracted to the same dimension table. |
| |
FactCount :: {..} -> FactColumnType FCKMaybeSourceColumn | A fact column which will contain the count of the rows ( |
| |
FactCountDistinct :: {..} -> FactColumnType FCKMaybeSourceColumn | A fact column which will contain the count of the unique values of a source column if provided or the primary key of the table. |
| |
FactSum :: {..} -> FactColumnType FCKSourceColumn | A fact column which will contain the sum of the values of the provided source column. |
| |
FactAverage :: {..} -> FactColumnType FCKSourceColumn | A fact column which will contain the average of the values of the provided source column. |
| |
FactMax :: {..} -> FactColumnType FCKSourceColumn | A fact column which will contain the maximum of the values of the provided source column. |
| |
FactMin :: {..} -> FactColumnType FCKSourceColumn | A fact column which will contain the minimum of the values of the provided source column. |
|
Show (FactColumnType a) Source # | |
data FactColumnKind Source #
Type of a FactColumnType
FCKNone | A FactColumnType without any parameters |
FCKTargetTable | A FactColumnType with |
FCKMaybeSourceColumn | A FactColumnType with |
FCKSourceColumn | A FactColumnType with |
factSourceColumnName :: FactColumn -> Maybe ColumnName Source #
Returns the name of the optional source column of a fact column
Units of time
timeUnitName :: TimeUnit -> Text Source #
Returns the name of a time unit
timeUnitToSeconds :: TimeUnit -> Int Source #
Returns the number of seconds in a time unit
configTables :: Config -> [Table] Source #
Return the list of source tables from the config
configFacts :: Config -> [Fact] Source #
Return the list of facts to be generated from the config
configSettings :: Config -> Settings Source #
Return the settings from the config
configTypeDefaults :: Config -> TypeDefaults Source #
Return the defaults for the SQL types from the config
Global settings for the library
Settings | |
|
defSettings :: Settings Source #
Settings with default values
type TypeDefaults = Map Text Text Source #
A mapping of SQL types to their default values used to coleasce null column values in the generated dimension and fact tables
data ValidationError Source #
Errors possible while validating the config
MissingTable !TableName | When referencing a table which is missing from the config |
MissingFact !TableName | When referencing a fact which is missing from the config |
MissingColumn !TableName !ColumnName | When referencing a column which is missing from the config |
MissingTimeColumn !TableName | When a fact has no |
MissingNotNullConstraint !TableName !ColumnName | When a |
MissingTypeDefault !Text | When the default value of a type is missing from the config |
DuplicateTable !TableName | When there are multiple tables with the same name in the config |
DuplicateFact !TableName | When there are multiple facts with the same name in the config |
DuplicateColumn !TableName !ColumnName | When there are multiple columns with the same name in a table in the config |
DuplicateDimension !TableName | When there are multiple dimensions with the same name in the config |
data TablePopulationMode Source #
The mode for population of the generated tables; used to switch the SQL for table population
FullPopulation | Populating the tables fully, starting with empty ones |
IncrementalPopulation | Populating the tables incrementally |