-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
210 additions
and
6 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
3 changes: 3 additions & 0 deletions
3
modules/service/src/main/resources/db/migration/V0003__functions.sql
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,3 @@ | ||
-- https://stackoverflow.com/questions/54372666/create-an-immutable-clone-of-concat-ws/54384767#54384767 | ||
CREATE OR REPLACE FUNCTION immutable_concat_ws(text, VARIADIC text[]) | ||
RETURNS text AS 'text_concat_ws' LANGUAGE internal IMMUTABLE PARALLEL SAFE; |
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
11 changes: 11 additions & 0 deletions
11
modules/service/src/main/resources/db/migration/V0100_constraint_set_groups.sql
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,11 @@ | ||
CREATE view v_constraint_set_group AS | ||
SELECT | ||
DISTINCT c_conditions_key, | ||
c_program_id, | ||
max(c_observation_id) as c_observation_id -- arbitrary, just pick one | ||
FROM | ||
t_observation | ||
GROUP BY | ||
c_conditions_key, | ||
c_program_id; | ||
|
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
72 changes: 72 additions & 0 deletions
72
modules/service/src/main/scala/lucuma/odb/graphql/mapping/ConstraintSetGroupMapping.scala
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,72 @@ | ||
// Copyright (c) 2016-2022 Association of Universities for Research in Astronomy, Inc. (AURA) | ||
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause | ||
|
||
package lucuma.odb.graphql | ||
|
||
package mapping | ||
|
||
import cats.syntax.all._ | ||
import edu.gemini.grackle.skunk.SkunkMapping | ||
import edu.gemini.grackle.Mapping | ||
import edu.gemini.grackle.Path | ||
import edu.gemini.grackle.Predicate | ||
import edu.gemini.grackle.Predicate._ | ||
import edu.gemini.grackle.Query | ||
import edu.gemini.grackle.Query._ | ||
import edu.gemini.grackle.Result | ||
import edu.gemini.grackle.TypeRef | ||
import edu.gemini.grackle.skunk.SkunkMapping | ||
import lucuma.core.model.Observation | ||
import lucuma.core.model.Program | ||
import lucuma.core.model.User | ||
import lucuma.odb.data.Existence | ||
import lucuma.odb.graphql.predicate.Predicates | ||
import table.ObservationView | ||
import lucuma.odb.graphql.table.ConstraintSetGroupView | ||
import binding._ | ||
import input._ | ||
import table._ | ||
|
||
trait ConstraintSetGroupMapping[F[_]] | ||
extends ConstraintSetGroupView[F] | ||
with ObservationView[F] | ||
with Predicates[F] { | ||
|
||
lazy val ConstraintSetGroupMapping = | ||
ObjectMapping( | ||
tpe = ConstraintSetGroupType, | ||
fieldMappings = List( | ||
SqlField("key", ConstraintSetGroupView.ConstraintSetKey, key = true, hidden = true), | ||
SqlField("programId", ConstraintSetGroupView.ProgramId), | ||
SqlObject("observations", Join(ConstraintSetGroupView.ConstraintSetKey, ObservationView.ConstraintSet.Key)), | ||
SqlObject("constraintSet", Join(ConstraintSetGroupView.ObservationId, ObservationView.Id)), | ||
) | ||
) | ||
|
||
lazy val ConstraintSetGroupElaborator: Map[TypeRef, PartialFunction[Select, Result[Query]]] = | ||
Map( | ||
ConstraintSetGroupType -> { | ||
case Select("observations", List( | ||
BooleanBinding("includeDeleted", rIncludeDeleted), | ||
ObservationIdBinding.Option("OFFSET", rOFFSET), | ||
NonNegIntBinding.Option("LIMIT", rLIMIT), | ||
), child) => | ||
(rIncludeDeleted, rOFFSET, rLIMIT).parTupled.flatMap { (includeDeleted, OFFSET, lim) => | ||
val limit = lim.fold(ResultMapping.MaxLimit)(_.value) | ||
ResultMapping.selectResult("observations", child, limit) { q => | ||
FilterOrderByOffsetLimit( | ||
pred = Some(and(List( | ||
Predicates.observation.existence.includeDeleted(includeDeleted), | ||
OFFSET.fold[Predicate](True)(Predicates.observation.id.gtEql) | ||
))), | ||
oss = Some(List(OrderSelection[Observation.Id](ObservationType / "id", true, true))), | ||
offset = None, | ||
limit = Some(limit + 1), | ||
q | ||
) | ||
} | ||
} | ||
} | ||
) | ||
} | ||
|
18 changes: 18 additions & 0 deletions
18
...ice/src/main/scala/lucuma/odb/graphql/mapping/ConstraintSetGroupSelectResultMapping.scala
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,18 @@ | ||
// Copyright (c) 2016-2022 Association of Universities for Research in Astronomy, Inc. (AURA) | ||
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause | ||
|
||
package lucuma.odb.graphql | ||
|
||
package mapping | ||
|
||
import edu.gemini.grackle.skunk.SkunkMapping | ||
|
||
import table.ObservationView | ||
import lucuma.odb.graphql.table.ConstraintSetGroupView | ||
|
||
trait ConstraintSetGroupSelectResultMapping[F[_]] extends ResultMapping[F] { | ||
|
||
lazy val ConstraintSetGroupSelectResultMapping: ObjectMapping = | ||
topLevelSelectResultMapping(ConstraintSetGroupSelectResultType) | ||
|
||
} |
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
11 changes: 11 additions & 0 deletions
11
...es/service/src/main/scala/lucuma/odb/graphql/predicate/ConstraintSetGroupPredicates.scala
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,11 @@ | ||
// Copyright (c) 2016-2022 Association of Universities for Research in Astronomy, Inc. (AURA) | ||
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause | ||
|
||
package lucuma.odb.graphql.predicate | ||
|
||
import edu.gemini.grackle.Path | ||
import lucuma.core.model.Program | ||
|
||
class ConstraintSetGroupPredicates(path: Path) { | ||
val programId = LeafPredicates[Program.Id](path / "programId") | ||
} |
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
20 changes: 20 additions & 0 deletions
20
modules/service/src/main/scala/lucuma/odb/graphql/table/ConstraintSetGroupView.scala
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,20 @@ | ||
// Copyright (c) 2016-2022 Association of Universities for Research in Astronomy, Inc. (AURA) | ||
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause | ||
|
||
package lucuma.odb.graphql | ||
|
||
package table | ||
|
||
import edu.gemini.grackle.skunk.SkunkMapping | ||
import lucuma.odb.util.Codecs._ | ||
import skunk.codec.all._ | ||
|
||
trait ConstraintSetGroupView[F[_]] extends BaseMapping[F] { | ||
|
||
object ConstraintSetGroupView extends TableDef("v_constraint_set_group") { | ||
val ProgramId: ColumnRef = col("c_program_id", program_id) | ||
val ConstraintSetKey: ColumnRef = col("c_conditions_key", text) | ||
val ObservationId: ColumnRef = col("c_observation_id", observation_id) | ||
} | ||
|
||
} |
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