-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get Atum Context, by getting existing partitioning from DB - retrieve…
… Measures and AdditionalData for a given partitioning #120 (#167) * Fixes #120 - Added class to call partitioning measures function * Fixes #120 - Removed status 16 option from the DB function associated with the partitioning * Fixes #120 - Changed measures function definitions * Fixes #120 - defined the class to communicate with get_partitioning_additional_data function * Fixes #120 - implementing the repository of get_partitioning_additional_data function * Fixes #120 - Calling getPartioningAdditionalData of the repo in the service * Fixes #120 - Calling getPartioningAdditionalData of the repo in the service * Fixes #120 - added value parameters * Fixes #120 - Merged master * Fixes #120 - refactored the controller added computation method in the service * Fixes #120 - refactored the controller added computation method in the service * Fixes #120 - changed type from error response to service error * Fixes #120 - Changed inheritance from service trat to implementation * Fixes #120 - Fixing bugs * Fixes #120 - Fixing type mismatch * Fixes #120 - removed unused imports * Fixes #120 - Adding implicit conversion * Fixes #120 - Added package object * implicits needed for Read instance derivation * Fixes #120 - Fixing bugs in PartitioningRepositorySpec * Fixes #120 - removed dead code in PartitioningRepositorySpec * Fixes #120 - fixing type mismatch in PartitioningRepositorySpec * Fixes #120 - Adding test cases in PartitioningRepositorySpec * Fixes #120 - Adding test cases * Fixes #120 - Adding test cases for db function * Fixes #120 - Adding and fixing test cases for db function * Fixes #120 - removing dead code * Fixes #120 - refactoring function name * Fixes #120 - Applying GitHub comments * Fixes #120 - Applying GitHub comments * Fixes #120 - Fixing bugs * Fixes #120 - Fixing repository test cases bugs * Fixes #120 - removing println * Fixes #120 - Fixing bugs from ControllerSpec * Fixes #120 - Adding more items to measure sequence * Fixes #120 - Removing dead code * Closes #120 * Close #120 - Applying GitHub comments * Close #120 - Addressing GitHub comments * Testing #120 db integration * Closes #120 - Cleaning unwanted code lines * Closes #120 - Fixing the build * Closes #120 - Fixing the build * Closes #120 - Fixing the tests * Closes #120 - Fixing the tests * Closes #120 - Fixing the tests cases * fixing the balta tests * * Fixing jacoco_check.yml setup (hopefully) * * Decreasing overall coverage req * jacoco excludes * added tests, decreased coverage level, added jacoco exclusions --------- Co-authored-by: Pavel Salamon <[email protected]> Co-authored-by: Ladislav Sulak <[email protected]> Co-authored-by: David Benedeki <[email protected]>
- Loading branch information
1 parent
13d0c5a
commit 4d83d79
Showing
23 changed files
with
679 additions
and
92 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
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 := 'Partitioning not found'; | ||
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 := 'Partitioning not found'; | ||
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
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
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) | ||
} | ||
} | ||
|
Oops, something went wrong.