ringo-core-0.1.0.0: OLTP to OLAP schema transformer for Postgres

Safe HaskellSafe
LanguageHaskell2010

Ringo.Types

Synopsis

Documentation

data Table Source #

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") ]
              ]
            }
:}

Constructors

Table 

Fields

Instances

Eq Table Source # 

Methods

(==) :: Table -> Table -> Bool #

(/=) :: Table -> Table -> Bool #

Show Table Source # 

Methods

showsPrec :: Int -> Table -> ShowS #

show :: Table -> String #

showList :: [Table] -> ShowS #

type TableName = Text Source #

Name of a Table

data TableConstraint Source #

A constraint on a Table

Constructors

PrimaryKey

A primary key constraint

Fields

UniqueKey

A unique key contraint

Fields

ForeignKey

A foreign key constraint

Fields

data Column Source #

A column of a Table

Constructors

Column 

Fields

Instances

type ColumnName = Text Source #

Name of a Column

type ColumnType = Text Source #

Type of a Column

data Fact Source #

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"
             ]
           }
:}

Constructors

Fact 

Fields

Instances

data FactColumn Source #

A column in a fact table

Constructors

FactColumn 

Fields

data FactColumnType a where Source #

Type of a fact column

Constructors

DimTime :: FactColumnType FCKNone

A fact column which contains a time dimension data (e.g. created_at). This is not exatracted as a dimension table and instead just converted to an int which depends on settingTimeUnit. Every fact must have one of this.

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. organization_id). This is not extracted as a dimension table.

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.

Fields

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.

Fields

FactCount :: {..} -> FactColumnType FCKMaybeSourceColumn

A fact column which will contain the count of the rows (count(*)) or count of a source column if provided.

Fields

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.

Fields

FactSum :: {..} -> FactColumnType FCKSourceColumn

A fact column which will contain the sum of the values of the provided source column.

Fields

FactAverage :: {..} -> FactColumnType FCKSourceColumn

A fact column which will contain the average of the values of the provided source column.

Fields

FactMax :: {..} -> FactColumnType FCKSourceColumn

A fact column which will contain the maximum of the values of the provided source column.

Fields

FactMin :: {..} -> FactColumnType FCKSourceColumn

A fact column which will contain the minimum of the values of the provided source column.

Fields

data FactColumnKind Source #

Type of a FactColumnType

Constructors

FCKNone

A FactColumnType without any parameters

FCKTargetTable

A FactColumnType with factColTargetTable as the only parameter

FCKMaybeSourceColumn

A FactColumnType with factColMaybeSourceColumn as the only parameter

FCKSourceColumn

A FactColumnType with factColSourceColumn as the only parameter

factSourceColumnName :: FactColumn -> Maybe ColumnName Source #

Returns the name of the optional source column of a fact column

timeUnitName :: TimeUnit -> Text Source #

Returns the name of a time unit

timeUnitToSeconds :: TimeUnit -> Int Source #

Returns the number of seconds in a time unit

data Config Source #

The config for the library

Instances

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

data Settings Source #

Global settings for the library

Constructors

Settings 

Fields

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

Constructors

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 DimTime columns

MissingNotNullConstraint !TableName !ColumnName

When a DimTime fact column of a fact is nullable

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

Constructors

FullPopulation

Populating the tables fully, starting with empty ones

IncrementalPopulation

Populating the tables incrementally

type Dependencies = Map TableName [TableName] Source #

The dependency graph of the generated tables describing the order in which they have to be populated