Adds source column to count and count distinct fact columns.

Also removes CountDistinctColumSuffix setting.
pull/1/head
Abhinav Sarkar 7 years ago
parent d1e1eb7676
commit 2dcbe4efd7
  1. 3
      app/Ringo/ArgParser.hs
  2. 12
      app/Ringo/InputParser.hs
  3. 15
      src/Ringo/Extractor.hs
  4. 6
      src/Ringo/Generator.hs
  5. 30
      src/Ringo/Types.hs

@ -40,9 +40,6 @@ settingsParser = let Settings {..} = defSettings
<*> minorOption "avg-sum-col-suffix"
settingAvgSumColumnSuffix
"Suffix for average sum columns"
<*> minorOption "count-distinct-col-suffix"
settingCountDistinctColumSuffix
"Suffix for count distinct bucket columns"
<*> minorOption "dim-id-col-name"
settingDimTableIdColumnName
"Name of dimension table id columns"

@ -52,12 +52,12 @@ instance FromJSON FactColumn where
case cType of
"dimtime" -> DimTime <$> o .: "column"
"nodimid" -> NoDimId <$> o .: "column"
"dimid" -> DimId <$> o .: "table" <*> o .: "column"
"dimval" -> DimVal <$> o .: "table" <*> o .: "column"
"factcount" -> FactCount <$> o .: "column"
"factsum" -> FactSum <$> o .: "sourcecolumn" <*> o .: "column"
"factaverage" -> FactAverage <$> o .: "sourcecolumn" <*> o .: "column"
"factcountdistinct" -> FactCountDistinct <$> o .: "column"
"dimid" -> DimId <$> o .: "table" <*> o .: "column"
"dimval" -> DimVal <$> o .: "table" <*> o .: "column"
"factcount" -> FactCount <$> o .:? "sourcecolumn" <*> o .: "column"
"factsum" -> FactSum <$> o .: "sourcecolumn" <*> o .: "column"
"factaverage" -> FactAverage <$> o .: "sourcecolumn" <*> o .: "column"
"factcountdistinct" -> FactCountDistinct <$> o .:? "sourcecolumn" <*> o .: "column"
_ -> fail $ "Invalid fact column type: " ++ cType
parseJSON o = fail $ "Cannot parse fact column: " ++ show o

@ -29,18 +29,17 @@ extractFactTable fact = do
sourceColumnType colName = columnType . fromJust . findColumn colName . tableColumns $ table
columns = concatFor (factColumns fact) $ \col -> case col of
DimTime cName ->
DimTime cName ->
[ Column (timeUnitColumnName dimIdColName cName settingTimeUnit) "integer" NotNull ]
NoDimId cName -> [ fromJust . findColumn cName . tableColumns $ table]
FactCount cName -> [ Column cName countColType NotNull ]
FactSum scName cName -> [ Column cName (sourceColumnType scName) NotNull ]
FactAverage scName cName ->
NoDimId cName -> [ fromJust . findColumn cName . tableColumns $ table]
FactCount _ cName -> [ Column cName countColType NotNull ]
FactSum scName cName -> [ Column cName (sourceColumnType scName) NotNull ]
FactAverage scName cName ->
[ Column (cName <> settingAvgCountColumSuffix) countColType NotNull
, Column (cName <> settingAvgSumColumnSuffix) (sourceColumnType scName) NotNull
]
FactCountDistinct cName ->
[ Column (cName <> settingCountDistinctColumSuffix) (countColType <> "[]") NotNull ]
_ -> []
FactCountDistinct _ cName -> [ Column cName (countColType <> "[]") NotNull ]
_ -> []
fks = for allDims $ \(fact', tab@Table {..}) ->
let colName = factDimFKIdColumnName settingDimPrefix dimIdColName tableName

@ -140,8 +140,10 @@ factTablePopulateSQL popMode fact = do
factColMap = concatFor (factColumns fact) $ \col -> case col of
DimTime cName -> [ timeUnitColumnInsertSQL cName ]
NoDimId cName -> [ (cName, fullColName fTableName cName, True) ]
FactCount cName -> [ (cName, "count(*)", False) ]
FactSum scName cName -> [ (cName, "sum(" <> fullColName fTableName scName <> ")", False) ]
FactCount scName cName ->
[ (cName, "count(" <> maybe "*" (fullColName fTableName) scName <> ")", False) ]
FactSum scName cName ->
[ (cName, "sum(" <> fullColName fTableName scName <> ")", False) ]
FactAverage scName cName ->
[ ( cName <> settingAvgCountColumSuffix
, "count(" <> fullColName fTableName scName <> ")"

@ -50,23 +50,23 @@ data Fact = Fact
data FactColumn = DimTime !ColumnName
| NoDimId !ColumnName
| DimId !TableName !ColumnName
| DimVal !TableName !ColumnName
| FactCount !ColumnName
| FactSum !ColumnName !ColumnName
| FactAverage !ColumnName !ColumnName
| FactCountDistinct !ColumnName
| DimId !TableName !ColumnName
| DimVal !TableName !ColumnName
| FactCount !(Maybe ColumnName) !ColumnName
| FactSum !ColumnName !ColumnName
| FactAverage !ColumnName !ColumnName
| FactCountDistinct !(Maybe ColumnName) !ColumnName
deriving (Eq, Show)
factColumnName :: FactColumn -> Maybe ColumnName
factColumnName (DimTime cName) = Just cName
factColumnName (NoDimId cName) = Just cName
factColumnName (DimId _ cName) = Just cName
factColumnName (DimVal _ cName) = Just cName
factColumnName (FactCount _) = Nothing
factColumnName (FactSum cName _) = Just cName
factColumnName (FactAverage cName _) = Just cName
factColumnName (FactCountDistinct _) = Nothing
factColumnName (DimTime cName) = Just cName
factColumnName (NoDimId cName) = Just cName
factColumnName (DimId _ cName) = Just cName
factColumnName (DimVal _ cName) = Just cName
factColumnName (FactCount cName _) = cName
factColumnName (FactSum cName _) = Just cName
factColumnName (FactAverage cName _) = Just cName
factColumnName (FactCountDistinct cName _) = cName
data Settings = Settings
{ settingDimPrefix :: !Text
@ -74,7 +74,6 @@ data Settings = Settings
, settingTimeUnit :: !TimeUnit
, settingAvgCountColumSuffix :: !Text
, settingAvgSumColumnSuffix :: !Text
, settingCountDistinctColumSuffix :: !Text
, settingDimTableIdColumnName :: !Text
, settingDimTableIdColumnType :: !Text
, settingFactCountColumnType :: !Text
@ -91,7 +90,6 @@ defSettings = Settings
, settingTimeUnit = Minute
, settingAvgCountColumSuffix = "_count"
, settingAvgSumColumnSuffix = "_sum"
, settingCountDistinctColumSuffix = "_hll"
, settingDimTableIdColumnName = "id"
, settingDimTableIdColumnType = "serial"
, settingFactCountColumnType = "integer"

Loading…
Cancel
Save