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"
|
<*> minorOption "dimensions-json-file"
|
||||||
settingDimensionJSONFileName
|
settingDimensionJSONFileName
|
||||||
"Name of the output dimensions json file"
|
"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
|
where
|
||||||
minorOption longDesc defValue helpTxt =
|
minorOption longDesc defValue helpTxt =
|
||||||
Text.pack <$> strOption (long longDesc
|
Text.pack <$> strOption (long longDesc
|
||||||
|
|
|
@ -46,12 +46,12 @@ $$
|
||||||
LANGUAGE 'plpgsql' IMMUTABLE|]
|
LANGUAGE 'plpgsql' IMMUTABLE|]
|
||||||
|
|
||||||
data FactTablePopulateSelectSQL = FactTablePopulateSelectSQL
|
data FactTablePopulateSelectSQL = FactTablePopulateSelectSQL
|
||||||
{ ftpsSelectCols :: ![(Text, Text)]
|
{ ftpsSelectCols :: ![(Text, Text)]
|
||||||
, ftpsSelectTable :: !Text
|
, ftpsSelectTable :: !Text
|
||||||
, ftpsJoinClauses :: ![Text]
|
, ftpsJoinClauses :: ![Text]
|
||||||
, ftpsWhereClauses :: ![Text]
|
, ftpsWhereClauses :: ![Text]
|
||||||
, ftpsGroupByCols :: ![Text]
|
, ftpsGroupByCols :: ![Text]
|
||||||
} deriving (Show, Eq)
|
} deriving (Show, Eq)
|
||||||
|
|
||||||
factTableUpdateSQL :: Fact -> Text -> FactTablePopulateSelectSQL -> Reader Env [Text]
|
factTableUpdateSQL :: Fact -> Text -> FactTablePopulateSelectSQL -> Reader Env [Text]
|
||||||
factTableUpdateSQL fact groupByColPrefix populateSelectSQL@FactTablePopulateSelectSQL {..} = do
|
factTableUpdateSQL fact groupByColPrefix populateSelectSQL@FactTablePopulateSelectSQL {..} = do
|
||||||
|
@ -116,6 +116,11 @@ factTablePopulateSQL popMode fact = do
|
||||||
fTable = fromJust . findTable fTableName $ tables
|
fTable = fromJust . findTable fTableName $ tables
|
||||||
dimIdColName = settingDimTableIdColumnName
|
dimIdColName = settingDimTableIdColumnName
|
||||||
|
|
||||||
|
coalesceFKId col =
|
||||||
|
if "coalesce" `Text.isPrefixOf` col
|
||||||
|
then col
|
||||||
|
else "coalesce((" <> col <> "), " <> Text.pack (show settingForeignKeyIdCoalesceValue) <> ")"
|
||||||
|
|
||||||
timeUnitColumnInsertSQL cName =
|
timeUnitColumnInsertSQL cName =
|
||||||
let colName = timeUnitColumnName dimIdColName cName settingTimeUnit
|
let colName = timeUnitColumnName dimIdColName cName settingTimeUnit
|
||||||
in ( colName
|
in ( colName
|
||||||
|
@ -203,11 +208,6 @@ factTablePopulateSQL popMode fact = do
|
||||||
<$> listToMaybe [ colPairs | ForeignKey tName colPairs <- tableConstraints table
|
<$> listToMaybe [ colPairs | ForeignKey tName colPairs <- tableConstraints table
|
||||||
, tName == oTableName ]
|
, 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 -> Text
|
||||||
toSelectSQL FactTablePopulateSelectSQL {..} =
|
toSelectSQL FactTablePopulateSelectSQL {..} =
|
||||||
"SELECT \n" <> joinColumnNames (map (uncurry asName) ftpsSelectCols)
|
"SELECT \n" <> joinColumnNames (map (uncurry asName) ftpsSelectCols)
|
||||||
|
|
|
@ -82,6 +82,7 @@ data Settings = Settings
|
||||||
, settingDependenciesJSONFileName :: !Text
|
, settingDependenciesJSONFileName :: !Text
|
||||||
, settingFactsJSONFileName :: !Text
|
, settingFactsJSONFileName :: !Text
|
||||||
, settingDimensionJSONFileName :: !Text
|
, settingDimensionJSONFileName :: !Text
|
||||||
|
, settingForeignKeyIdCoalesceValue :: !Int
|
||||||
} deriving (Eq, Show)
|
} deriving (Eq, Show)
|
||||||
|
|
||||||
defSettings :: Settings
|
defSettings :: Settings
|
||||||
|
@ -99,6 +100,7 @@ defSettings = Settings
|
||||||
, settingDependenciesJSONFileName = "dependencies.json"
|
, settingDependenciesJSONFileName = "dependencies.json"
|
||||||
, settingFactsJSONFileName = "facts.json"
|
, settingFactsJSONFileName = "facts.json"
|
||||||
, settingDimensionJSONFileName = "dimensions.json"
|
, settingDimensionJSONFileName = "dimensions.json"
|
||||||
|
, settingForeignKeyIdCoalesceValue = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
data ValidationError = MissingTable !TableName
|
data ValidationError = MissingTable !TableName
|
||||||
|
|
Loading…
Reference in New Issue