-
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
Feature/224 post partitioning #258
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1e097fb
tmp commit
salamonpavel fd67127
Merge branch 'refs/heads/master' into feature/224-post-partitioning
salamonpavel 6537241
tests
salamonpavel b380095
CreatePartitioningIntegrationTests
salamonpavel 4ad5189
Merge branch 'master' into feature/224-post-partitioning
salamonpavel 4bc6804
Merge branch 'master' into feature/224-post-partitioning
salamonpavel 919f34c
Update V1.9.7__create_partitioning.sql
salamonpavel 43bc8f1
Update database/src/main/postgres/runs/V1.9.7__create_partitioning.sql
salamonpavel faa6548
comments addressed
salamonpavel 0043c61
sql refactored
salamonpavel 22e4ac0
tests fixed
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
93 changes: 93 additions & 0 deletions
93
database/src/main/postgres/runs/V1.9.7__create_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,93 @@ | ||
/* | ||
* 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.create_partitioning( | ||
IN i_partitioning JSONB, | ||
IN i_by_user TEXT, | ||
IN i_parent_partitioning_id BIGINT = NULL, | ||
OUT status INTEGER, | ||
OUT status_text TEXT, | ||
OUT id_partitioning BIGINT | ||
) RETURNS record AS | ||
$$ | ||
------------------------------------------------------------------------------- | ||
-- | ||
-- Function: runs.create_partitioning(3) | ||
-- Creates a partitioning entry | ||
-- | ||
-- Parameters: | ||
-- i_partitioning - partitioning to create or which existence to check | ||
-- i_by_user - user behind the change | ||
-- i_parent_partitioning_id - (optional) parent partitioning id | ||
-- | ||
-- Returns: | ||
-- status - Status code | ||
-- status_text - Status text | ||
-- id_partitioning - id of the partitioning | ||
-- | ||
-- Status codes: | ||
-- 11 - Partitioning created | ||
-- 12 - Partitioning created with parent partitioning | ||
-- 31 - Partitioning already exists | ||
-- 41 - Parent partitioning not found | ||
-- | ||
------------------------------------------------------------------------------- | ||
BEGIN | ||
id_partitioning := runs._get_id_partitioning(i_partitioning, true); | ||
|
||
IF id_partitioning IS NOT NULL THEN | ||
status := 31; | ||
status_text := 'Partitioning already exists'; | ||
RETURN; | ||
benedeki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
END IF; | ||
|
||
IF i_parent_partitioning_id IS NOT NULL THEN | ||
PERFORM 1 FROM runs.partitionings P WHERE P.id_partitioning = i_parent_partitioning_id; | ||
IF NOT FOUND THEN | ||
status := 41; | ||
status_text := 'Parent partitioning not found'; | ||
RETURN; | ||
END IF; | ||
END IF; | ||
|
||
INSERT INTO runs.partitionings (partitioning, created_by) | ||
VALUES (i_partitioning, i_by_user) | ||
RETURNING partitionings.id_partitioning INTO create_partitioning.id_partitioning; | ||
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. I didn't know that these were possible :) |
||
|
||
PERFORM 1 FROM flows._create_flow(id_partitioning, i_by_user); | ||
status := 11; | ||
status_text := 'Partitioning created'; | ||
|
||
IF i_parent_partitioning_id IS NOT NULL THEN | ||
PERFORM 1 FROM flows._add_to_parent_flows(i_parent_partitioning_id, id_partitioning, i_by_user); | ||
|
||
-- copying measure definitions to establish continuity | ||
INSERT INTO runs.measure_definitions(fk_partitioning, measure_name, measured_columns, created_by, created_at) | ||
SELECT id_partitioning, CMD.measure_name, CMD.measured_columns, CMD.created_by, CMD.created_at | ||
FROM runs.measure_definitions CMD | ||
WHERE CMD.fk_partitioning = i_parent_partitioning_id; | ||
|
||
status := 12; | ||
status_text := 'Partitioning created with parent partitioning'; | ||
END IF; | ||
|
||
RETURN; | ||
END; | ||
$$ | ||
LANGUAGE plpgsql VOLATILE SECURITY DEFINER; | ||
|
||
ALTER FUNCTION runs.create_partitioning(JSONB, TEXT, BIGINT) OWNER TO atum_owner; | ||
GRANT EXECUTE ON FUNCTION runs.create_partitioning(JSONB, TEXT, BIGINT) TO atum_user; |
191 changes: 191 additions & 0 deletions
191
...ase/src/test/scala/za/co/absa/atum/database/runs/CreatePartitioningIntegrationTests.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,191 @@ | ||
/* | ||
* 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 za.co.absa.balta.DBTestSuite | ||
import za.co.absa.balta.classes.JsonBString | ||
|
||
class CreatePartitioningIntegrationTests extends DBTestSuite{ | ||
|
||
private val fncCreatePartitioning = "runs.create_partitioning" | ||
|
||
private val partitioning = JsonBString( | ||
""" | ||
|{ | ||
| "version": 1, | ||
| "keys": ["key1", "key3", "key2", "key4"], | ||
| "keysToValues": { | ||
| "key1": "valueX", | ||
| "key2": "valueY", | ||
| "key3": "valueZ", | ||
| "key4": "valueA" | ||
| } | ||
|} | ||
|""".stripMargin | ||
) | ||
|
||
private val parentPartitioning = JsonBString( | ||
""" | ||
|{ | ||
| "version": 1, | ||
| "keys": ["key1", "key3"], | ||
| "keysToValues": { | ||
| "key1": "valueX", | ||
| "key3": "valueZ" | ||
| } | ||
|} | ||
|""".stripMargin | ||
) | ||
|
||
test("Partitioning created") { | ||
val partitioningID = function(fncCreatePartitioning) | ||
.setParam("i_partitioning", partitioning) | ||
.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 | ||
} | ||
|
||
table("runs.partitionings").where(add("id_partitioning", partitioningID)) {partitioningResult => | ||
val row = partitioningResult.next() | ||
assert(row.getString("created_by").contains("Fantômas")) | ||
assert(row.getOffsetDateTime("created_at").contains(now())) | ||
} | ||
|
||
val idFlow = table("flows.partitioning_to_flow").where(add("fk_partitioning", partitioningID)) { partToFlowResult => | ||
assert(partToFlowResult.hasNext) | ||
val partToFlowRow = partToFlowResult.next() | ||
val result = partToFlowRow.getLong("fk_flow") | ||
assert(partToFlowRow.getString("created_by").contains("Fantômas")) | ||
assert(!partToFlowResult.hasNext) | ||
result.get | ||
} | ||
|
||
table("flows.flows").where(add("id_flow", idFlow)) {flowsResult => | ||
assert(flowsResult.hasNext) | ||
val flowRow = flowsResult.next() | ||
assert(flowRow.getString("flow_name").exists(_.startsWith("Custom flow #"))) | ||
assert(flowRow.getString("flow_description").contains("")) | ||
assert(flowRow.getBoolean("from_pattern").contains(false)) | ||
assert(flowRow.getString("created_by").contains("Fantômas")) | ||
assert(flowRow.getOffsetDateTime("created_at").contains(now())) | ||
assert(!flowsResult.hasNext) | ||
} | ||
} | ||
|
||
test("Partitioning created with parent partitioning that already exists") { | ||
val parentPartitioningID = function(fncCreatePartitioning) | ||
.setParam("i_partitioning", parentPartitioning) | ||
.setParam("i_by_user", "Albert Einstein") | ||
.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 | ||
} | ||
|
||
assert( | ||
table("flows.partitioning_to_flow").count(add("fk_partitioning", parentPartitioningID)) == 1 | ||
) | ||
val partitioningID = function(fncCreatePartitioning) | ||
.setParam("i_partitioning", partitioning) | ||
.setParam("i_by_user", "Fantômas") | ||
.setParam("i_parent_partitioning_id", parentPartitioningID) | ||
.execute { queryResult => | ||
assert(queryResult.hasNext) | ||
val row = queryResult.next() | ||
assert(row.getInt("status").contains(12)) | ||
assert(row.getString("status_text").contains("Partitioning created with parent partitioning")) | ||
row.getLong("id_partitioning").get | ||
} | ||
|
||
assert( | ||
table("flows.partitioning_to_flow").count(add("fk_partitioning", parentPartitioningID)) == 1 | ||
) | ||
assert( | ||
table("flows.partitioning_to_flow").count(add("fk_partitioning", partitioningID)) == 2 | ||
) | ||
} | ||
|
||
test("Partitioning already exists") { | ||
val partitioningID = function(fncCreatePartitioning) | ||
.setParam("i_partitioning", partitioning) | ||
.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(fncCreatePartitioning) | ||
.setParam("i_partitioning", partitioning) | ||
.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(31)) | ||
assert(row.getString("status_text").contains("Partitioning already exists")) | ||
assert(row.getLong("id_partitioning").contains(partitioningID)) | ||
} | ||
|
||
assert( | ||
table("flows.partitioning_to_flow").count(add("fk_partitioning", partitioningID)) == 1 | ||
) | ||
} | ||
|
||
test("Partitioning exists, parent is not added") { | ||
val partitioningID = function(fncCreatePartitioning) | ||
.setParam("i_partitioning", partitioning) | ||
.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 | ||
} | ||
|
||
assert( | ||
table("flows.partitioning_to_flow").count(add("fk_partitioning", partitioningID)) == 1 | ||
) | ||
|
||
function(fncCreatePartitioning) | ||
.setParam("i_partitioning", partitioning) | ||
.setParam("i_by_user", "Fantômas") | ||
.setParam("i_parent_partitioning_id", 123456789L) | ||
.execute { queryResult => | ||
assert(queryResult.hasNext) | ||
val row = queryResult.next() | ||
assert(row.getInt("status").contains(31)) | ||
assert(row.getString("status_text").contains("Partitioning already exists")) | ||
} | ||
|
||
assert( | ||
table("flows.partitioning_to_flow").count(add("fk_partitioning", partitioningID)) == 1 | ||
) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
model/src/main/scala/za/co/absa/atum/model/dto/PartitioningSubmitV2DTO.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,31 @@ | ||
/* | ||
* 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.model.dto | ||
|
||
import io.circe.generic.semiauto._ | ||
import io.circe._ | ||
|
||
case class PartitioningSubmitV2DTO( | ||
partitioning: PartitioningDTO, | ||
parentPartitioningId: Option[Long], | ||
author: String | ||
) | ||
|
||
object PartitioningSubmitV2DTO { | ||
implicit val decodePartitioningSubmitV2DTO: Decoder[PartitioningSubmitV2DTO] = deriveDecoder | ||
implicit val encodePartitioningSubmitV2DTO: Encoder[PartitioningSubmitV2DTO] = deriveEncoder | ||
} |
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
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.
or something like that