-
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 partitioning #275
Merged
Merged
get partitioning #275
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4a5606f
get partitioning
salamonpavel aaa60b3
implement getPartitioning functionality
salamonpavel b1ab071
implement getPartitioning functionality
salamonpavel ac89d73
fix
salamonpavel 3009882
not found test
salamonpavel 093deed
jacoco 1.7.1
salamonpavel 2dd2c14
renaming
salamonpavel cebb939
clean up
salamonpavel 7fb7475
update comment
salamonpavel aa7e55e
Merge branch 'master' into feature/268-get-partitionings
salamonpavel 1e299a8
conflicts
salamonpavel d7de00b
fixes
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
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
82 changes: 82 additions & 0 deletions
82
database/src/main/postgres/runs/V1.9.12__get_partitioning.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,82 @@ | ||
/* | ||
* 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( | ||
IN i_partitioning JSONB, | ||
OUT status INTEGER, | ||
OUT status_text TEXT, | ||
OUT id BIGINT, | ||
OUT o_partitioning JSONB, | ||
OUT author TEXT | ||
) RETURNS record AS | ||
$$ | ||
------------------------------------------------------------------------------- | ||
-- | ||
-- Function: runs.get_partitioning(1) | ||
-- Retrieves a partitioning by its JSONB representation. | ||
-- | ||
-- Parameters: | ||
-- i_partitioning - partitioning to search for, a valid example: | ||
-- { | ||
-- "keys": ["one", "two", "three"], | ||
-- "version": 1, | ||
-- "keysToValues": { | ||
-- "one": "DatasetA", | ||
-- "two": "Version1", | ||
-- "three": "2022-12-20" | ||
-- } | ||
-- } | ||
-- | ||
-- Returns: | ||
-- status - status of the operation: | ||
-- status_text - textual representation of the status | ||
-- id - ID of the partitioning | ||
-- o_partitioning - partitioning data | ||
-- author - author of the partitioning | ||
-- | ||
-- Status codes: | ||
-- 11 - OK | ||
-- 41 - Partitioning not found | ||
-- | ||
------------------------------------------------------------------------------- | ||
BEGIN | ||
-- Initialize status and status_text | ||
status := 41; | ||
status_text := 'Partitioning not found'; | ||
|
||
-- Retrieve partitioning ID | ||
id := runs._get_id_partitioning(i_partitioning); | ||
|
||
-- If ID is found, retrieve partitioning details | ||
IF id IS NOT NULL THEN | ||
SELECT GPBI.id, GPBI.partitioning, GPBI.author | ||
INTO get_partitioning.id, get_partitioning.o_partitioning, get_partitioning.author | ||
FROM runs.get_partitioning_by_id(id) AS GPBI; | ||
|
||
-- Update status if partitioning is found | ||
IF FOUND THEN | ||
status := 11; | ||
status_text := 'OK'; | ||
END IF; | ||
END IF; | ||
|
||
RETURN; | ||
END; | ||
$$ | ||
LANGUAGE plpgsql IMMUTABLE SECURITY DEFINER; | ||
|
||
ALTER FUNCTION runs.get_partitioning(i_partitioning JSONB) OWNER TO atum_owner; | ||
GRANT EXECUTE ON FUNCTION runs.get_partitioning(i_partitioning JSONB) TO atum_user; |
117 changes: 117 additions & 0 deletions
117
database/src/test/scala/za/co/absa/atum/database/runs/GetPartitioningIntegrationTests.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,117 @@ | ||
/* | ||
* 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.database.runs | ||
|
||
import io.circe.Json | ||
import za.co.absa.balta.DBTestSuite | ||
import za.co.absa.balta.classes.JsonBString | ||
|
||
class GetPartitioningIntegrationTests extends DBTestSuite { | ||
|
||
private val fnCreatePartitioning = "runs.create_partitioning" | ||
private val fnGetPartitioning = "runs.get_partitioning" | ||
|
||
private val partitioning1Value = | ||
""" | ||
|{ | ||
| "version":1, | ||
| "keys":["key1","key2","key3","key4"], | ||
| "keysToValues":{ | ||
| "key1":"valueX", | ||
| "key2":"valueY", | ||
| "key3":"valueZ", | ||
| "key4":"valueA" | ||
| } | ||
|} | ||
|""".stripMargin | ||
|
||
private val partitioning1 = JsonBString(partitioning1Value) | ||
|
||
private val partitioning2 = JsonBString( | ||
""" | ||
|{ | ||
| "version":1, | ||
| "keys":["key1","key2","key3","key4"], | ||
| "keysToValues":{ | ||
| "key1":"valueX", | ||
| "key2":"valueX", | ||
| "key3":"valueX", | ||
| "key4":"valueX" | ||
| } | ||
|} | ||
|""".stripMargin | ||
) | ||
|
||
test("Existing (correct) partitioning is returned") { | ||
val partitioning1ID = function(fnCreatePartitioning) | ||
.setParam("i_partitioning", partitioning1) | ||
.setParam("i_by_user", "Fantômas") | ||
.setParamNull("i_parent_partitioning_id") | ||
.execute { queryResult => | ||
assert(queryResult.hasNext) | ||
val row = queryResult.next() | ||
assert(row.getInt("status").contains(11)) | ||
assert(row.getString("status_text").contains("Partitioning created")) | ||
row.getLong("id_partitioning").get | ||
} | ||
|
||
function(fnCreatePartitioning) | ||
.setParam("i_partitioning", partitioning2) | ||
.setParam("i_by_user", "Fantômas") | ||
.setParamNull("i_parent_partitioning_id") | ||
.execute { queryResult => | ||
assert(queryResult.hasNext) | ||
val row = queryResult.next() | ||
assert(row.getInt("status").contains(11)) | ||
assert(row.getString("status_text").contains("Partitioning created")) | ||
} | ||
|
||
function(fnGetPartitioning) | ||
.setParam("i_partitioning", partitioning1) | ||
.execute { queryResult => | ||
assert(queryResult.hasNext) | ||
val row = queryResult.next() | ||
assert(row.getInt("status").contains(11)) | ||
assert(row.getString("status_text").contains("OK")) | ||
assert(row.getLong("id").contains(partitioning1ID)) | ||
assert { | ||
val retrievedPartitioningAsJson = Json.fromString(row.getJsonB("o_partitioning").get.value) | ||
val expectedPartitioningAsJson = Json.fromString(partitioning1Value) | ||
retrievedPartitioningAsJson \\ "keysToValues" == expectedPartitioningAsJson \\ "keysToValues" && | ||
retrievedPartitioningAsJson \\ "keys" == expectedPartitioningAsJson \\ "keys" | ||
} | ||
assert(row.getString("author").contains("Fantômas")) | ||
assert(!queryResult.hasNext) | ||
} | ||
} | ||
|
||
test("Non-existent partitioning is not returned") { | ||
function(fnGetPartitioning) | ||
.setParam("i_partitioning", partitioning1) | ||
.execute { queryResult => | ||
assert(queryResult.hasNext) | ||
val row = queryResult.next() | ||
assert(row.getInt("status").contains(41)) | ||
assert(row.getString("status_text").contains("Partitioning not found")) | ||
assert(row.getLong("id").isEmpty) | ||
assert(row.getJsonB("o_partitioning").isEmpty) | ||
assert(row.getString("author").isEmpty) | ||
assert(!queryResult.hasNext) | ||
} | ||
} | ||
|
||
} |
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
46 changes: 46 additions & 0 deletions
46
...r/src/main/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioning.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,46 @@ | ||
/* | ||
* 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.implicits.toSqlInterpolator | ||
import io.circe.syntax.EncoderOps | ||
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, PartitioningFromDB} | ||
import za.co.absa.db.fadb.DBSchema | ||
import za.co.absa.db.fadb.doobie.DoobieEngine | ||
import za.co.absa.db.fadb.doobie.DoobieFunction.DoobieSingleResultFunctionWithStatus | ||
import za.co.absa.db.fadb.status.handling.implementations.StandardStatusHandling | ||
import zio._ | ||
|
||
import za.co.absa.db.fadb.doobie.postgres.circe.implicits.jsonbPut | ||
import za.co.absa.db.fadb.doobie.postgres.circe.implicits.jsonbGet | ||
|
||
class GetPartitioning(implicit schema: DBSchema, dbEngine: DoobieEngine[Task]) | ||
extends DoobieSingleResultFunctionWithStatus[PartitioningForDB, Option[PartitioningFromDB], Task](partitioningForDB => | ||
Seq(fr"${partitioningForDB.asJson}") | ||
) with StandardStatusHandling { | ||
override def fieldsToSelect: Seq[String] = super.fieldsToSelect ++ Seq("id", "o_partitioning", "author") | ||
} | ||
|
||
object GetPartitioning { | ||
val layer: URLayer[PostgresDatabaseProvider, GetPartitioning] = ZLayer { | ||
for { | ||
dbProvider <- ZIO.service[PostgresDatabaseProvider] | ||
} yield new GetPartitioning()(Runs, dbProvider.dbEngine) | ||
} | ||
} |
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.
Interesting, I though this was done in earlier of your PRs 😄
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.
yeah I have done it also here to see "more correct" numbers whilst working on the draft pr ...