Moves out foreign key id coalesce value as a setting.
parent
dc4b260ff6
commit
644acc7ee9
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue