Skip to content

feature: support JsonGet for all step types #2506

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

Merged
merged 30 commits into from
Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
868db55
add helper function to generate no-op (data ingestion only) recipe
jerrypeng7773 May 11, 2021
21bedbb
Merge branch 'aws:master' into master
jerrypeng7773 May 11, 2021
854dd10
separate flow generation by source input type + move generation helpe…
jerrypeng7773 May 11, 2021
8798b65
Merge branch 'aws:master' into master
jerrypeng7773 May 11, 2021
69ae4bd
create an internal helper function to generate output node
jerrypeng7773 May 12, 2021
a6a8449
Merge branch 'master' of github.com:jerrypeng7773/sagemaker-python-sdk
jerrypeng7773 May 12, 2021
2aa256e
Merge branch 'aws:master' into master
jerrypeng7773 May 18, 2021
06557a8
add ingestion test using dw processor via pipeline execution
jerrypeng7773 May 19, 2021
dcbfd13
Merge branch 'aws:master' into master
jerrypeng7773 May 19, 2021
fc6522e
verify the fg query df
jerrypeng7773 May 19, 2021
b6f9371
Merge branch 'master' into master
ahsan-z-khan May 19, 2021
86fa47d
fix tests
jerrypeng7773 May 19, 2021
05ccfa6
Merge branch 'master' into master
ahsan-z-khan May 20, 2021
0716e9f
Merge branch 'aws:master' into master
jerrypeng7773 Jun 14, 2021
7ca5af4
add tuning step support
jerrypeng7773 Jun 24, 2021
8cf18b8
fix docstyle check
jerrypeng7773 Jun 24, 2021
1f95b82
add helper function to get tuning step top performing model s3 uri
jerrypeng7773 Jun 29, 2021
1b9d66b
Merge branch 'aws:master' into master
jerrypeng7773 Jun 30, 2021
603b934
Merge branch 'aws:master' into master
jerrypeng7773 Jun 30, 2021
664f2a8
Merge branch 'master' of github.com:jerrypeng7773/sagemaker-python-sdk
jerrypeng7773 Jun 30, 2021
a8755ec
Merge branch 'master' into master
apogupta2018 Jul 1, 2021
e25d36c
Merge branch 'aws:master' into master
jerrypeng7773 Jul 1, 2021
db83c4b
make JsonGet compatible to all steps and put it into functions.py
jerrypeng7773 Jul 1, 2021
003de65
Merge branch 'master' into fix-issue-2426
apogupta2018 Jul 7, 2021
1c1f2d2
Merge branch 'master' into fix-issue-2426
ahsan-z-khan Jul 12, 2021
5ed6d29
Merge branch 'master' into fix-issue-2426
ahsan-z-khan Jul 19, 2021
989875e
Merge branch 'master' into fix-issue-2426
ahsan-z-khan Jul 22, 2021
10d0fc7
Merge branch 'master' into fix-issue-2426
shreyapandit Jul 23, 2021
fcd2615
Merge branch 'master' into fix-issue-2426
shreyapandit Jul 28, 2021
d3f5761
Merge branch 'master' into fix-issue-2426
shreyapandit Aug 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/workflows/pipelines/sagemaker.workflow.pipelines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ConditionStep

.. autoclass:: sagemaker.workflow.condition_step.ConditionStep

.. autoclass:: sagemaker.workflow.condition_step.JsonGet
.. deprecated:: sagemaker.workflow.condition_step.JsonGet

Conditions
----------
Expand Down Expand Up @@ -54,6 +54,8 @@ Functions

.. autoclass:: sagemaker.workflow.functions.Join

.. autoclass:: sagemaker.workflow.functions.JsonGet

Parameters
----------

Expand Down
4 changes: 4 additions & 0 deletions src/sagemaker/workflow/condition_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import attr

from sagemaker.deprecations import deprecated_class
from sagemaker.workflow.conditions import Condition
from sagemaker.workflow.entities import (
Expression,
Expand Down Expand Up @@ -114,3 +115,6 @@ def expr(self):
"Path": self.json_path,
}
}


JsonGet = deprecated_class(JsonGet, "JsonGet")
36 changes: 35 additions & 1 deletion src/sagemaker/workflow/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
"""The step definitions for workflow."""
from __future__ import absolute_import

from typing import List
from typing import List, Union

import attr

from sagemaker.workflow.entities import Expression
from sagemaker.workflow.properties import PropertyFile


@attr.s
Expand Down Expand Up @@ -54,3 +55,36 @@ def expr(self):
],
},
}


@attr.s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this class, we are introducing the same duplicated block of code here as in condition_step.py, while marking the block there as deprecated. The class itself is the same. If we still plan to reuse the same code in condition_step as well as here, why can't we pull this out somewhere common, like utils, where both can import it

class JsonGet(Expression):
"""Get JSON properties from PropertyFiles.

Attributes:
step_name (str): The step name from which to get the property file.
property_file (Union[PropertyFile, str]): Either a PropertyFile instance
or the name of a property file.
json_path (str): The JSON path expression to the requested value.
"""

step_name: str = attr.ib()
property_file: Union[PropertyFile, str] = attr.ib()
json_path: str = attr.ib()

@property
def expr(self):
"""The expression dict for a `JsonGet` function."""
if not isinstance(self.step_name, str):
raise ValueError("Please give step name as a string")

if isinstance(self.property_file, PropertyFile):
name = self.property_file.name
else:
name = self.property_file
return {
"Std:JsonGet": {
"PropertyFile": {"Get": f"Steps.{self.step_name}.PropertyFiles.{name}"},
"Path": self.json_path,
}
}
35 changes: 33 additions & 2 deletions tests/unit/sagemaker/workflow/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
from __future__ import absolute_import

from sagemaker.workflow.execution_variables import ExecutionVariables
from sagemaker.workflow.functions import Join
from sagemaker.workflow.functions import Join, JsonGet
from sagemaker.workflow.parameters import (
ParameterFloat,
ParameterInteger,
ParameterString,
)
from sagemaker.workflow.properties import Properties
from sagemaker.workflow.properties import Properties, PropertyFile


def test_join_primitives_default_on():
Expand Down Expand Up @@ -66,3 +66,34 @@ def test_join_expressions():
],
},
}


def test_json_get_expressions():

assert JsonGet(
step_name="my-step",
property_file="my-property-file",
json_path="my-json-path",
).expr == {
"Std:JsonGet": {
"PropertyFile": {"Get": "Steps.my-step.PropertyFiles.my-property-file"},
"Path": "my-json-path",
},
}

property_file = PropertyFile(
name="name",
output_name="result",
path="output",
)

assert JsonGet(
step_name="my-step",
property_file=property_file,
json_path="my-json-path",
).expr == {
"Std:JsonGet": {
"PropertyFile": {"Get": "Steps.my-step.PropertyFiles.name"},
"Path": "my-json-path",
},
}