Created
September 12, 2019 13:44
-
-
Save vtorosyan/e6c42d92d7239336d33b193f968c6898 to your computer and use it in GitHub Desktop.
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
val partitionsTableSchema = quote { | |
querySchema[Partition]( | |
entity = "partitions", | |
_.id -> "id", | |
_.datasetId -> "dataset", | |
_.partitionTime -> "partition_time", | |
_.deletedAt -> "deleted_at" | |
) | |
} | |
val revisionsTableSchema = quote { | |
querySchema[Revision]( | |
entity = "revisions", | |
_.id -> "id", | |
_.partitionId -> "partition_id", | |
_.url -> "url", | |
_.publishedAt -> "published_at", | |
_.metadata -> "metadata" | |
) | |
} | |
// Fails with confusing error without proper message (scalas: Error while emitting DatasetRepository.scala value p) | |
def retrievePartitions(datasetId: DatasetId) = { | |
val quoted = quote { | |
for { | |
p <- partitionsTableSchema.filter(p => p.datasetId == lift(datasetId)) | |
r <- latestRevision(p.id) | |
} yield (p, r) | |
} | |
databaseClient.run(quoted) | |
} | |
private def latestRevision(partitionId: Long) = quote { | |
revisionsTableSchema.join(r => r.partitionId == lift(partitionId)) | |
// Filter only latest revision | |
.filter { r => | |
revisionsTableSchema | |
.filter(_.partitionId == lift(partitionId)) | |
.map(_.id) | |
.max.contains(r.id) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment