[issue-2116] - Add target property to MlModel (#2134)

* Add target property to MlModel

* Use pull_request_target for forks

* Simplify str

* Update ingestion-core setup

* Bump ingestion-core version

* Update install
This commit is contained in:
Pere Miquel Brull 2022-01-18 16:27:35 +01:00 committed by GitHub
parent d4e66ecd7c
commit a9c840778a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 85 additions and 12 deletions

View File

@ -44,9 +44,12 @@ public class MlModelRepository extends EntityRepository<MlModel> {
private static final Logger LOG = LoggerFactory.getLogger(MlModelRepository.class); private static final Logger LOG = LoggerFactory.getLogger(MlModelRepository.class);
private static final Fields MODEL_UPDATE_FIELDS = private static final Fields MODEL_UPDATE_FIELDS =
new Fields( new Fields(
MlModelResource.FIELD_LIST, "owner,algorithm,dashboard,mlHyperParameters,mlFeatures,mlStore,server,tags"); MlModelResource.FIELD_LIST,
"owner,algorithm,dashboard,mlHyperParameters,mlFeatures,mlStore,server,target,tags");
private static final Fields MODEL_PATCH_FIELDS = private static final Fields MODEL_PATCH_FIELDS =
new Fields(MlModelResource.FIELD_LIST, "owner,algorithm,dashboard,mlHyperParameters,mlFeatures,tags"); new Fields(
MlModelResource.FIELD_LIST,
"owner,algorithm,dashboard,mlHyperParameters,mlFeatures,mlStore,server,target,tags");
public MlModelRepository(CollectionDAO dao) { public MlModelRepository(CollectionDAO dao) {
super( super(
@ -77,6 +80,7 @@ public class MlModelRepository extends EntityRepository<MlModel> {
mlModel.setOwner(fields.contains("owner") ? getOwner(mlModel) : null); mlModel.setOwner(fields.contains("owner") ? getOwner(mlModel) : null);
mlModel.setDashboard(fields.contains("dashboard") ? getDashboard(mlModel) : null); mlModel.setDashboard(fields.contains("dashboard") ? getDashboard(mlModel) : null);
mlModel.setMlFeatures(fields.contains("mlFeatures") ? mlModel.getMlFeatures() : null); mlModel.setMlFeatures(fields.contains("mlFeatures") ? mlModel.getMlFeatures() : null);
mlModel.setTarget(fields.contains("target") ? mlModel.getTarget() : null);
mlModel.setMlHyperParameters(fields.contains("mlHyperParameters") ? mlModel.getMlHyperParameters() : null); mlModel.setMlHyperParameters(fields.contains("mlHyperParameters") ? mlModel.getMlHyperParameters() : null);
mlModel.setMlStore(fields.contains("mlStore") ? mlModel.getMlStore() : null); mlModel.setMlStore(fields.contains("mlStore") ? mlModel.getMlStore() : null);
mlModel.setServer(fields.contains("server") ? mlModel.getServer() : null); mlModel.setServer(fields.contains("server") ? mlModel.getServer() : null);
@ -396,6 +400,7 @@ public class MlModelRepository extends EntityRepository<MlModel> {
updateMlHyperParameters(origMlModel, updatedMlModel); updateMlHyperParameters(origMlModel, updatedMlModel);
updateMlStore(origMlModel, updatedMlModel); updateMlStore(origMlModel, updatedMlModel);
updateServer(origMlModel, updatedMlModel); updateServer(origMlModel, updatedMlModel);
updateTarget(origMlModel, updatedMlModel);
} }
private void updateAlgorithm(MlModel origModel, MlModel updatedModel) throws JsonProcessingException { private void updateAlgorithm(MlModel origModel, MlModel updatedModel) throws JsonProcessingException {
@ -442,6 +447,13 @@ public class MlModelRepository extends EntityRepository<MlModel> {
} }
} }
private void updateTarget(MlModel origModel, MlModel updatedModel) throws JsonProcessingException {
// Updating the target changes the model response
if (recordChange("target", origModel.getTarget(), updatedModel.getTarget())) {
majorVersionChange = true;
}
}
private void updateDashboard(MlModel origModel, MlModel updatedModel) throws JsonProcessingException { private void updateDashboard(MlModel origModel, MlModel updatedModel) throws JsonProcessingException {
EntityReference origDashboard = origModel.getDashboard(); EntityReference origDashboard = origModel.getDashboard();
EntityReference updatedDashboard = updatedModel.getDashboard(); EntityReference updatedDashboard = updatedModel.getDashboard();

View File

@ -103,7 +103,7 @@ public class MlModelResource {
} }
static final String FIELDS = static final String FIELDS =
"owner,dashboard,algorithm,mlFeatures,mlHyperParameters,mlStore,server," + "followers,tags,usageSummary"; "owner,dashboard,algorithm,mlFeatures,mlHyperParameters,mlStore,server,target,followers,tags,usageSummary";
public static final List<String> FIELD_LIST = Arrays.asList(FIELDS.replace(" ", "").split(",")); public static final List<String> FIELD_LIST = Arrays.asList(FIELDS.replace(" ", "").split(","));
@GET @GET
@ -423,6 +423,7 @@ public class MlModelResource {
.withMlHyperParameters(create.getMlHyperParameters()) .withMlHyperParameters(create.getMlHyperParameters())
.withMlStore(create.getMlStore()) .withMlStore(create.getMlStore())
.withServer(create.getServer()) .withServer(create.getServer())
.withTarget(create.getTarget())
.withTags(create.getTags()) .withTags(create.getTags())
.withOwner(create.getOwner()) .withOwner(create.getOwner())
.withUpdatedBy(securityContext.getUserPrincipal().getName()) .withUpdatedBy(securityContext.getUserPrincipal().getName())

View File

@ -31,6 +31,10 @@
}, },
"default" : null "default" : null
}, },
"target": {
"description": "For supervised ML Models, the value to estimate.",
"$ref": "../../entity/data/mlmodel.json#/definitions/featureName"
},
"mlHyperParameters": { "mlHyperParameters": {
"description": "Hyper Parameters used to train the ML Model.", "description": "Hyper Parameters used to train the ML Model.",
"type": "array", "type": "array",

View File

@ -222,6 +222,10 @@
}, },
"default": null "default": null
}, },
"target": {
"description": "For supervised ML Models, the value to estimate.",
"$ref": "#/definitions/featureName"
},
"dashboard" : { "dashboard" : {
"description": "Performance Dashboard URL to track metric evolution.", "description": "Performance Dashboard URL to track metric evolution.",
"$ref" : "../../type/entityReference.json" "$ref" : "../../type/entityReference.json"

View File

@ -375,6 +375,30 @@ public class MlModelResourceTest extends EntityResourceTest<MlModel> {
request.withMlHyperParameters(ML_HYPERPARAMS), Status.OK, adminAuthHeaders(), MINOR_UPDATE, change); request.withMlHyperParameters(ML_HYPERPARAMS), Status.OK, adminAuthHeaders(), MINOR_UPDATE, change);
} }
@Test
void put_MlModelAddTarget_200(TestInfo test) throws IOException {
CreateMlModel request = create(test);
MlModel model = createAndCheckEntity(request, adminAuthHeaders());
ChangeDescription change = getChangeDescription(model.getVersion());
change.getFieldsAdded().add(new FieldChange().withName("target").withNewValue("myTarget"));
updateAndCheckEntity(request.withTarget("myTarget"), Status.OK, adminAuthHeaders(), MAJOR_UPDATE, change);
}
@Test
void put_MlModelUpdateTarget_200(TestInfo test) throws IOException {
CreateMlModel request = create(test).withTarget("origTarget");
MlModel model = createAndCheckEntity(request, adminAuthHeaders());
ChangeDescription change = getChangeDescription(model.getVersion());
change
.getFieldsUpdated()
.add(new FieldChange().withName("target").withNewValue("newTarget").withOldValue("origTarget"));
updateAndCheckEntity(request.withTarget("newTarget"), Status.OK, adminAuthHeaders(), MAJOR_UPDATE, change);
}
@Test @Test
void delete_MlModel_200_ok(TestInfo test) throws HttpResponseException { void delete_MlModel_200_ok(TestInfo test) throws HttpResponseException {
MlModel model = createMlModel(create(test), adminAuthHeaders()); MlModel model = createMlModel(create(test), adminAuthHeaders());

View File

@ -1,7 +1,10 @@
install_dev:
python -m pip install ".[dev]"
generate: generate:
mkdir -p src/metadata/generated mkdir -p src/metadata/generated
python3 -m pip install --upgrade pip setuptools python3 -m pip install --upgrade pip setuptools
python3 -m pip install --upgrade -r requirements-dev.txt make install_dev
datamodel-codegen --input ../catalog-rest-service/src/main/resources/json --input-file-type jsonschema --output src/metadata/generated datamodel-codegen --input ../catalog-rest-service/src/main/resources/json --input-file-type jsonschema --output src/metadata/generated
clean: clean:

View File

@ -1,10 +1,12 @@
--- ---
This guide will help you setup the Ingestion framework and connectors This guide will help you set up OpenMetadata Core Models
--- ---
![Python version 3.8+](https://img.shields.io/badge/python-3.8%2B-blue) ![Python version 3.8+](https://img.shields.io/badge/python-3.8%2B-blue)
OpenMetadata Ingesiton is a simple framework to build connectors and ingest metadata of various systems through OpenMetadata APIs. It could be used in an orchestration framework(e.g. Apache Airflow) to ingest metadata. These models are `pydantic` models automatically generated from the
central JSON Schemas that define our APIs and Entities.
**Prerequisites** **Prerequisites**
- Python &gt;= 3.8.x - Python &gt;= 3.8.x
@ -12,3 +14,18 @@ OpenMetadata Ingesiton is a simple framework to build connectors and ingest meta
### Docs ### Docs
Please refer to the documentation here https://docs.open-metadata.org/connectors Please refer to the documentation here https://docs.open-metadata.org/connectors
### Contribution
In order to contribute to this package:
```bash
cd ingestion-core
python -m virtualenv venv
source venv/bin/activate
python -m pip install ".[dev]"
```
> OBS: During development we might need to treat this in a different
virtual environment if we are yet to update the reference to the core
package in `openmetadata-ingestion`.

View File

@ -1,5 +0,0 @@
datamodel-code-generator==0.11.14
incremental
twine
twisted
wheel

View File

@ -20,6 +20,15 @@ def get_long_description():
return description return description
dev = {
"datamodel-code-generator==0.11.14",
"incremental",
"twine",
"twisted",
"wheel",
"click",
}
setup( setup(
name="openmetadata-ingestion-core", name="openmetadata-ingestion-core",
url="https://open-metadata.org/", url="https://open-metadata.org/",
@ -39,4 +48,7 @@ setup(
"Source": "https://github.com/open-metadata/OpenMetadata", "Source": "https://github.com/open-metadata/OpenMetadata",
}, },
packages=find_namespace_packages(where="./src", exclude=["tests*"]), packages=find_namespace_packages(where="./src", exclude=["tests*"]),
extras_require={
"dev": list(dev),
},
) )

View File

@ -7,5 +7,5 @@ Provides metadata version information.
from incremental import Version from incremental import Version
__version__ = Version("metadata", 0, 8, 0, dev=4) __version__ = Version("metadata", 0, 8, 0, dev=5)
__all__ = ["__version__"] __all__ = ["__version__"]

View File

@ -265,6 +265,7 @@ class OMetaModelTest(TestCase):
MlHyperParameter(name="regularisation", value="0.5"), MlHyperParameter(name="regularisation", value="0.5"),
MlHyperParameter(name="random", value="hello"), MlHyperParameter(name="random", value="hello"),
], ],
target="myTarget",
) )
res = self.metadata.create_or_update(data=model) res = self.metadata.create_or_update(data=model)