-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get Atum Context, by getting existing partitioning from DB - retrieve Measures and AdditionalData for a given partitioning #120 #167
Merged
TebaleloS
merged 56 commits into
master
from
feature/#120-retrieve-Measures-and-AdditionalData-for-a-given-partitioning
Apr 30, 2024
Merged
Changes from 51 commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
74af153
Fixes #120 - Added class to call partitioning measures function
TebaleloS 74993c0
Merge branch 'master' into feature/#120-retrieve-Measures-and-Additio…
TebaleloS 9b8dc52
Fixes #120 - Removed status 16 option from the DB function associated…
TebaleloS b0949ba
Merge remote-tracking branch 'origin/feature/#120-retrieve-Measures-a…
TebaleloS daa1a16
Fixes #120 - Changed measures function definitions
TebaleloS 9680a1b
Fixes #120 - defined the class to communicate with get_partitioning_a…
TebaleloS ff6edb5
Fixes #120 - implementing the repository of get_partitioning_addition…
TebaleloS 086525e
Fixes #120 - Calling getPartioningAdditionalData of the repo in the s…
TebaleloS 52449d3
Fixes #120 - Calling getPartioningAdditionalData of the repo in the s…
TebaleloS 57a1fd7
Fixes #120 - added value parameters
TebaleloS 6d7145b
Merge branch 'master' into feature/#120-retrieve-Measures-and-Additio…
TebaleloS 1896eba
Fixes #120 - Merged master
TebaleloS ac6aa3a
Fixes #120 - refactored the controller added computation method in th…
TebaleloS 94703b8
Fixes #120 - refactored the controller added computation method in th…
TebaleloS 3b05824
Fixes #120 - changed type from error response to service error
TebaleloS c063480
Fixes #120 - Changed inheritance from service trat to implementation
TebaleloS c5c5a28
Fixes #120 - Fixing bugs
TebaleloS e6e48c9
Fixes #120 - Fixing type mismatch
TebaleloS f43f67f
Fixes #120 - removed unused imports
TebaleloS baf89a2
Fixes #120 - Adding implicit conversion
TebaleloS c86914b
Fixes #120 - Added package object
TebaleloS 5b3ceb5
implicits needed for Read instance derivation
salamonpavel 9100092
Fixes #120 - Fixing bugs in PartitioningRepositorySpec
TebaleloS 1212cd6
Fixes #120 - removed dead code in PartitioningRepositorySpec
TebaleloS a1c6cca
Fixes #120 - fixing type mismatch in PartitioningRepositorySpec
TebaleloS 1301c24
Fixes #120 - Adding test cases in PartitioningRepositorySpec
TebaleloS 1fabc96
Fixes #120 - Adding test cases
TebaleloS 9fd6069
Fixes #120 - Adding test cases for db function
TebaleloS 5de083a
Fixes #120 - Adding and fixing test cases for db function
TebaleloS e440533
Fixes #120 - removing dead code
TebaleloS ae68970
Fixes #120 - refactoring function name
TebaleloS d75b5dd
Fixes #120 - Applying GitHub comments
TebaleloS a6f09d3
Fixes #120 - Applying GitHub comments
TebaleloS 4475aaa
Fixes #120 - merging master
TebaleloS c4f2aaa
Fixes #120 - Fixing bugs
TebaleloS 5bfe34b
Fixes #120 - Fixing repository test cases bugs
TebaleloS 975648b
Fixes #120 - removing println
TebaleloS ed67783
Fixes #120 - Fixing bugs from ControllerSpec
TebaleloS a8348a6
Fixes #120 - Adding more items to measure sequence
TebaleloS 604d518
Fixes #120 - Removing dead code
TebaleloS 1d31880
Closes #120
TebaleloS 9c5bb99
Close #120 - Applying GitHub comments
TebaleloS 44c3664
Close #120 - Addressing GitHub comments
TebaleloS 7e30a62
Testing #120 db integration
TebaleloS d1b6f7c
Closes #120 - Cleaning unwanted code lines
TebaleloS 42e9604
Closes #120 - Fixing the build
TebaleloS 66af419
Closes #120 - Fixing the build
TebaleloS 31dea31
Closes #120 - Fixing the tests
TebaleloS ef537a5
Closes #120 - Fixing the tests
TebaleloS 30c5f3f
Closes #120 - Fixing the tests cases
TebaleloS c41a50f
Merge remote-tracking branch 'refs/remotes/origin/master' into featur…
lsulak 14d8244
fixing the balta tests
lsulak d62f574
* Fixing jacoco_check.yml setup (hopefully)
benedeki 57ffa95
* Decreasing overall coverage req
benedeki 7ab2215
jacoco excludes
salamonpavel f6ef5df
added tests, decreased coverage level, added jacoco exclusions
salamonpavel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
database/src/main/postgres/runs/V1.8.1__get_partitioning_measures.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,70 @@ | ||
/* | ||
* Copyright 2021 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
CREATE OR REPLACE FUNCTION runs.get_partitioning_measures( | ||
IN i_partitioning JSONB, | ||
OUT status INTEGER, | ||
OUT status_text TEXT, | ||
OUT measure_name TEXT, | ||
OUT measured_columns TEXT[] | ||
) RETURNS SETOF record AS | ||
$$ | ||
------------------------------------------------------------------------------- | ||
-- | ||
-- Function: runs.get_partitioning_measures(1) | ||
-- Returns measures for the given partitioning | ||
-- | ||
-- Parameters: | ||
-- i_partitioning - partitioning we are asking the measures for | ||
-- | ||
-- Returns: | ||
-- status - Status code | ||
-- status_text - Status message | ||
-- measure_name - Name of the measure | ||
-- measured_columns - Array of columns associated with the measure | ||
|
||
-- Status codes: | ||
-- 11 - OK | ||
-- 41 - Partitioning not found | ||
-- | ||
------------------------------------------------------------------------------- | ||
|
||
DECLARE | ||
_fk_partitioning BIGINT; | ||
BEGIN | ||
_fk_partitioning = runs._get_id_partitioning(i_partitioning); | ||
|
||
IF _fk_partitioning IS NULL THEN | ||
status := 41; | ||
status_text := 'The partitioning does not exist.'; | ||
RETURN NEXT; | ||
RETURN; | ||
END IF; | ||
|
||
status := 11; | ||
status_text := 'OK'; | ||
|
||
RETURN QUERY | ||
SELECT status, status_text, md.measure_name, md.measured_columns | ||
FROM runs.measure_definitions AS md | ||
WHERE md.fk_partitioning = _fk_partitioning; | ||
|
||
END; | ||
$$ | ||
LANGUAGE plpgsql VOLATILE SECURITY DEFINER; | ||
|
||
ALTER FUNCTION runs.get_partitioning_measures(JSONB) OWNER TO atum_owner; | ||
GRANT EXECUTE ON FUNCTION runs.get_partitioning_measures(JSONB) TO atum_user; |
71 changes: 71 additions & 0 deletions
71
database/src/main/postgres/runs/V1.8.2__get_partitioning_additional_data.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,71 @@ | ||
/* | ||
* Copyright 2021 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
CREATE OR REPLACE FUNCTION runs.get_partitioning_additional_data( | ||
IN i_partitioning JSONB, | ||
OUT status INTEGER, | ||
OUT status_text TEXT, | ||
OUT ad_name TEXT, | ||
OUT ad_value TEXT | ||
) RETURNS SETOF record AS | ||
|
||
$$ | ||
------------------------------------------------------------------------------- | ||
-- | ||
-- Function: runs.get_partitioning_additional_data(1) | ||
-- Returns additional data for the given partitioning | ||
-- | ||
-- Parameters: | ||
-- i_partitioning - partitioning for requested additional data | ||
-- | ||
-- Returns: | ||
-- status - Status code | ||
-- status_text - Status message | ||
-- ad_name - Name of the additional data | ||
-- ad_value - Value of the additional data | ||
-- | ||
-- Status codes: | ||
-- 11 - OK | ||
-- 41 - Partitioning not found | ||
-- | ||
------------------------------------------------------------------------------- | ||
|
||
DECLARE | ||
_fk_partitioning BIGINT; | ||
BEGIN | ||
_fk_partitioning = runs._get_id_partitioning(i_partitioning); | ||
|
||
IF _fk_partitioning IS NULL THEN | ||
status := 41; | ||
status_text := 'The partitioning does not exist.'; | ||
RETURN NEXT; | ||
RETURN; | ||
END IF; | ||
|
||
status = 11; | ||
status_text = 'OK'; | ||
|
||
RETURN QUERY | ||
SELECT status, status_text, ad.ad_name, ad.ad_value | ||
FROM runs.additional_data AS ad | ||
WHERE ad.fk_partitioning = _fk_partitioning; | ||
|
||
END; | ||
$$ | ||
LANGUAGE plpgsql VOLATILE SECURITY DEFINER; | ||
|
||
ALTER FUNCTION runs.get_partitioning_additional_data(JSONB) OWNER TO atum_owner; | ||
GRANT EXECUTE ON FUNCTION runs.get_partitioning_additional_data(JSONB) TO atum_user; |
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 |
---|---|---|
|
@@ -16,23 +16,31 @@ | |
|
||
package za.co.absa.atum.server.api.controller | ||
|
||
import za.co.absa.atum.model.dto._ | ||
|
||
import za.co.absa.atum.model.dto.{AdditionalDataSubmitDTO, AtumContextDTO, PartitioningSubmitDTO} | ||
import za.co.absa.atum.server.api.exception.ServiceError | ||
import za.co.absa.atum.server.api.service.PartitioningService | ||
import za.co.absa.atum.server.model.ErrorResponse | ||
import za.co.absa.atum.server.model.{ErrorResponse, InternalServerErrorResponse} | ||
import zio._ | ||
|
||
class PartitioningControllerImpl(partitioningService: PartitioningService) | ||
extends PartitioningController with BaseController { | ||
|
||
override def createPartitioningIfNotExists(partitioning: PartitioningSubmitDTO): IO[ErrorResponse, AtumContextDTO] = { | ||
serviceCallWithStatus[Unit, AtumContextDTO]( | ||
partitioningService.createPartitioningIfNotExists(partitioning), | ||
_ => { | ||
val measures: Set[MeasureDTO] = Set(MeasureDTO("count", Seq("*"))) | ||
val additionalData: AdditionalDataDTO = Map.empty | ||
AtumContextDTO(partitioning.partitioning, measures, additionalData) | ||
override def createPartitioningIfNotExists( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tiny: |
||
partitioningSubmitDTO: PartitioningSubmitDTO | ||
): IO[ErrorResponse, AtumContextDTO] = { | ||
for { | ||
_ <- partitioningService.createPartitioningIfNotExists(partitioningSubmitDTO) | ||
.mapError(serviceError => InternalServerErrorResponse(serviceError.message)) | ||
measures <- partitioningService.getPartitioningMeasures(partitioningSubmitDTO.partitioning) | ||
.mapError { | ||
serviceError: ServiceError => InternalServerErrorResponse(serviceError.message) | ||
} | ||
) | ||
additionalData <- partitioningService.getPartitioningAdditionalData(partitioningSubmitDTO.partitioning) | ||
.mapError { | ||
serviceError: ServiceError => InternalServerErrorResponse(serviceError.message) | ||
} | ||
} yield AtumContextDTO(partitioningSubmitDTO.partitioning, measures.toSet, additionalData) | ||
} | ||
|
||
override def createOrUpdateAdditionalData( | ||
|
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
60 changes: 60 additions & 0 deletions
60
...la/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningAdditionalData.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,60 @@ | ||
/* | ||
* Copyright 2021 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package za.co.absa.atum.server.api.database.runs.functions | ||
|
||
import doobie.Fragment | ||
import doobie.implicits.toSqlInterpolator | ||
import doobie.util.Read | ||
import play.api.libs.json.Json | ||
import za.co.absa.atum.model.dto.PartitioningDTO | ||
import za.co.absa.atum.server.api.database.PostgresDatabaseProvider | ||
import za.co.absa.atum.server.api.database.runs.Runs | ||
import za.co.absa.atum.server.model.PartitioningForDB | ||
import za.co.absa.fadb.DBSchema | ||
import za.co.absa.fadb.doobie.DoobieFunction.DoobieMultipleResultFunction | ||
import za.co.absa.fadb.doobie.DoobieEngine | ||
import zio.interop.catz.asyncInstance | ||
import zio.{Task, URLayer, ZIO, ZLayer} | ||
import za.co.absa.atum.server.api.database.DoobieImplicits.getMapWithOptionStringValues | ||
|
||
class GetPartitioningAdditionalData (implicit schema: DBSchema, dbEngine: DoobieEngine[Task]) | ||
extends DoobieMultipleResultFunction[PartitioningDTO, (String, Option[String]), Task] | ||
{ | ||
import za.co.absa.atum.server.api.database.DoobieImplicits.Jsonb.jsonbPutUsingString | ||
|
||
override val fieldsToSelect: Seq[String] = Seq("ad_name", "ad_value") | ||
|
||
override def sql(values: PartitioningDTO)(implicit read: Read[(String, Option[String])]): Fragment = { | ||
val partitioning: PartitioningForDB = PartitioningForDB.fromSeqPartitionDTO(values) | ||
val partitioningJsonString = Json.toJson(partitioning).toString | ||
|
||
sql"""SELECT ${Fragment.const(selectEntry)} FROM ${Fragment.const(functionName)}( | ||
${ | ||
partitioningJsonString | ||
} | ||
) ${Fragment.const(alias)};""" | ||
} | ||
|
||
} | ||
|
||
object GetPartitioningAdditionalData { | ||
val layer: URLayer[PostgresDatabaseProvider, GetPartitioningAdditionalData] = ZLayer { | ||
for { | ||
dbProvider <- ZIO.service[PostgresDatabaseProvider] | ||
} yield new GetPartitioningAdditionalData()(Runs, dbProvider.dbEngine) | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...in/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningMeasures.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,61 @@ | ||
/* | ||
* Copyright 2021 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package za.co.absa.atum.server.api.database.runs.functions | ||
|
||
import doobie.Fragment | ||
import doobie.implicits.toSqlInterpolator | ||
import doobie.util.Read | ||
import play.api.libs.json.Json | ||
import za.co.absa.atum.model.dto.{MeasureDTO, PartitioningDTO} | ||
import za.co.absa.atum.server.model.PartitioningForDB | ||
import za.co.absa.fadb.DBSchema | ||
import za.co.absa.fadb.doobie.DoobieEngine | ||
import za.co.absa.fadb.doobie.DoobieFunction.DoobieMultipleResultFunction | ||
import za.co.absa.atum.server.api.database.PostgresDatabaseProvider | ||
import za.co.absa.atum.server.api.database.runs.Runs | ||
import zio._ | ||
import zio.interop.catz._ | ||
import za.co.absa.atum.server.api.database.DoobieImplicits.Sequence.get | ||
|
||
class GetPartitioningMeasures (implicit schema: DBSchema, dbEngine: DoobieEngine[Task]) | ||
extends DoobieMultipleResultFunction[PartitioningDTO, MeasureDTO, Task] | ||
{ | ||
import za.co.absa.atum.server.api.database.DoobieImplicits.Jsonb.jsonbPutUsingString | ||
|
||
override val fieldsToSelect: Seq[String] = Seq("measure_name", "measured_columns") | ||
|
||
override def sql(values: PartitioningDTO)(implicit read: Read[MeasureDTO]): Fragment = { | ||
val partitioning = PartitioningForDB.fromSeqPartitionDTO(values) | ||
val partitioningJsonString = Json.toJson(partitioning).toString | ||
|
||
sql"""SELECT ${Fragment.const(selectEntry)} FROM ${Fragment.const(functionName)}( | ||
${ | ||
partitioningJsonString | ||
} | ||
) ${Fragment.const(alias)};""" | ||
} | ||
|
||
} | ||
|
||
object GetPartitioningMeasures { | ||
val layer: URLayer[PostgresDatabaseProvider, GetPartitioningMeasures] = ZLayer { | ||
for { | ||
dbProvider <- ZIO.service[PostgresDatabaseProvider] | ||
} yield new GetPartitioningMeasures()(Runs, dbProvider.dbEngine) | ||
} | ||
} | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny:
Why the parameter rename?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I wanted to distinguish between the partitioning parameter for this method and for
partitioningMeasure's
andpartitioningAdditionalData
methodsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, good reason. It's just it's not the best idea to put the type name into the parameter/variable name (only with rare exceptions). Next time I would for example use
submittedPartitioning: PartitioningSubmitDTO
.But don't change it anymore! It's OK, good enough 😉