Changes dimension table population query for coalesce changes.
- Replaces "IS NOT DISTICNT FROM" with "=" - Adds not-all-columns-null check for full refresh.
This commit is contained in:
parent
aeed16570e
commit
d758dc3310
@ -104,21 +104,23 @@ dimensionTablePopulateSQL popMode fact dimTableName = do
|
||||
, let col = fromJust . findColumn cName $ tableColumns factTable ]
|
||||
baseSelectC = "SELECT DISTINCT\n" <> joinColumnNames selectCols
|
||||
<> "\nFROM " <> factTableName fact
|
||||
insertC selectC = "INSERT INTO " <> dimTableName
|
||||
baseWhereC = "(\n"
|
||||
<> Text.intercalate "\nOR " [ c <> " IS NOT NULL" | (_, c) <- colMapping ]
|
||||
<> "\n)"
|
||||
insertC selectC whereCs =
|
||||
"INSERT INTO " <> dimTableName
|
||||
<> " (\n" <> joinColumnNames (map fst colMapping) <> "\n) "
|
||||
<> "SELECT x.* FROM (\n" <> selectC <> ") x"
|
||||
<> "SELECT x.* FROM (\n"
|
||||
<> selectC <> "\nWHERE " <> Text.intercalate " AND\n" whereCs
|
||||
<> ") x"
|
||||
timeCol = head [ cName | DimTime cName <- factColumns fact ]
|
||||
return $ case popMode of
|
||||
FullPopulation -> insertC baseSelectC
|
||||
FullPopulation -> insertC baseSelectC [baseWhereC]
|
||||
IncrementalPopulation ->
|
||||
insertC (baseSelectC <> "\nWHERE "
|
||||
<> timeCol <> " > ? AND " <> timeCol <> " <= ?"
|
||||
<> " AND (\n"
|
||||
<> Text.intercalate "\nOR " [ c <> " IS NOT NULL" | (_, c) <- colMapping ]
|
||||
<> "\n)")
|
||||
insertC baseSelectC [baseWhereC, timeCol <> " > ?", timeCol <> " <= ?"]
|
||||
<> "\nLEFT JOIN " <> dimTableName <> " ON\n"
|
||||
<> Text.intercalate " \nAND "
|
||||
[ fullColName dimTableName c1 <> " IS NOT DISTINCT FROM " <> fullColName "x" c2 -- TODO can be replaced with = ?
|
||||
[ fullColName dimTableName c1 <> " = " <> fullColName "x" c2
|
||||
| (c1, c2) <- colMapping ]
|
||||
<> "\nWHERE " <> Text.intercalate " \nAND "
|
||||
[ fullColName dimTableName c <> " IS NULL" | (c, _) <- colMapping ]
|
||||
@ -237,10 +239,7 @@ factTablePopulateSQL popMode fact = do
|
||||
$ fullColName factSourceTableName dimFKIdColName
|
||||
else "SELECT " <> dimIdColName <> " FROM " <> tableName <> "\nWHERE "
|
||||
<> Text.intercalate "\n AND " dimLookupWhereClauses
|
||||
insertSQL' = if factSourceTableName == fTableName
|
||||
then insertSQL
|
||||
else coalesceFKId insertSQL -- TODO always coalesce
|
||||
in (dimFKIdColName, insertSQL', True)
|
||||
in (dimFKIdColName, coalesceFKId insertSQL, True)
|
||||
|
||||
colMap = [ (cName, (sql, groupByColPrefix <> cName), addToGroupBy)
|
||||
| (cName, sql, addToGroupBy) <- factColMap ++ dimColMap ]
|
||||
|
Loading…
Reference in New Issue
Block a user