-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multiple
pointsTo
for a column (#107)
- Loading branch information
1 parent
781cfc6
commit fe2ad81
Showing
9 changed files
with
128 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package typo | ||
package internal | ||
|
||
import typo.internal.rewriteDependentData.EvalMaybe | ||
|
||
// we let types flow through constraints down to this column, the point is to reuse id types downstream | ||
object findTypeFromFk { | ||
def apply( | ||
typoLogger: TypoLogger, | ||
source: Source, | ||
colName: db.ColName, | ||
pointsTo: List[(Source.Relation, db.ColName)], | ||
eval: EvalMaybe[db.RelationName, HasSource] | ||
)(inSameSource: db.ColName => Option[sc.Type]): Option[sc.Type] = { | ||
val all: List[Either[sc.Type, sc.Type]] = | ||
pointsTo.flatMap { case (otherTableSource, otherColName) => | ||
if (otherTableSource == source) | ||
if (colName == otherColName) None | ||
else inSameSource(otherColName).map(Left.apply) | ||
else | ||
for { | ||
existingTable <- eval(otherTableSource.name) | ||
nonCircular <- existingTable.get | ||
otherCol <- nonCircular.cols.find(_.dbName == otherColName) | ||
} yield Right(otherCol.tpe) | ||
} | ||
|
||
all.distinctBy { e => sc.Type.base(e.merge) } match { | ||
case Nil => None | ||
case e :: Nil => Some(e.merge) | ||
case all => | ||
val fromSelf = all.collectFirst { case Left(tpe) => tpe } | ||
val fromOthers = all.collectFirst { case Right(tpe) => tpe } | ||
val renderedTypes = all.map { e => sc.renderTree(e.merge) } | ||
typoLogger.warn(s"Multiple distinct types inherited for column ${colName.value} in $source: ${renderedTypes.mkString(", ")}") | ||
fromOthers.orElse(fromSelf) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters