Moves out foreign key id coalesce value as a setting.

pull/1/head
Abhinav Sarkar 2015-12-30 12:34:35 +05:30
parent dc4b260ff6
commit 644acc7ee9
3 changed files with 18 additions and 11 deletions

View File

@ -66,6 +66,11 @@ settingsParser = let Settings {..} = defSettings
<*> minorOption "dimensions-json-file"
settingDimensionJSONFileName
"Name of the output dimensions json file"
<*> option auto (long "foreign-key-id-coalesce-val"
<> hidden
<> value settingForeignKeyIdCoalesceValue
<> showDefault
<> help "Value to coalease missing foriegn key ids to, in fact tables")
where
minorOption longDesc defValue helpTxt =
Text.pack <$> strOption (long longDesc

View File

@ -46,12 +46,12 @@ $$
LANGUAGE 'plpgsql' IMMUTABLE|]
data FactTablePopulateSelectSQL = FactTablePopulateSelectSQL
{ ftpsSelectCols :: ![(Text, Text)]
, ftpsSelectTable :: !Text
, ftpsJoinClauses :: ![Text]
, ftpsWhereClauses :: ![Text]
, ftpsGroupByCols :: ![Text]
} deriving (Show, Eq)
{ ftpsSelectCols :: ![(Text, Text)]
, ftpsSelectTable :: !Text
, ftpsJoinClauses :: ![Text]
, ftpsWhereClauses :: ![Text]
, ftpsGroupByCols :: ![Text]
} deriving (Show, Eq)
factTableUpdateSQL :: Fact -> Text -> FactTablePopulateSelectSQL -> Reader Env [Text]
factTableUpdateSQL fact groupByColPrefix populateSelectSQL@FactTablePopulateSelectSQL {..} = do
@ -116,6 +116,11 @@ factTablePopulateSQL popMode fact = do
fTable = fromJust . findTable fTableName $ tables
dimIdColName = settingDimTableIdColumnName
coalesceFKId col =
if "coalesce" `Text.isPrefixOf` col
then col
else "coalesce((" <> col <> "), " <> Text.pack (show settingForeignKeyIdCoalesceValue) <> ")"
timeUnitColumnInsertSQL cName =
let colName = timeUnitColumnName dimIdColName cName settingTimeUnit
in ( colName
@ -203,11 +208,6 @@ factTablePopulateSQL popMode fact = do
<$> listToMaybe [ colPairs | ForeignKey tName colPairs <- tableConstraints table
, tName == oTableName ]
coalesceFKId col =
if "coalesce" `Text.isPrefixOf` col
then col
else "coalesce((" <> col <> "), -1)" -- TODO extract this out to settings
toSelectSQL :: FactTablePopulateSelectSQL -> Text
toSelectSQL FactTablePopulateSelectSQL {..} =
"SELECT \n" <> joinColumnNames (map (uncurry asName) ftpsSelectCols)

View File

@ -82,6 +82,7 @@ data Settings = Settings
, settingDependenciesJSONFileName :: !Text
, settingFactsJSONFileName :: !Text
, settingDimensionJSONFileName :: !Text
, settingForeignKeyIdCoalesceValue :: !Int
} deriving (Eq, Show)
defSettings :: Settings
@ -99,6 +100,7 @@ defSettings = Settings
, settingDependenciesJSONFileName = "dependencies.json"
, settingFactsJSONFileName = "facts.json"
, settingDimensionJSONFileName = "dimensions.json"
, settingForeignKeyIdCoalesceValue = -1
}
data ValidationError = MissingTable !TableName