-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
feat(SDK) Add java SDK for structuredProperty entity PATCH + CRUD examples #10823
feat(SDK) Add java SDK for structuredProperty entity PATCH + CRUD examples #10823
Conversation
WalkthroughThis update improves the handling of structured properties in the DataHub project. It introduces new methods for setting and removing string and number properties in structured properties. It also expands the testing infrastructure and provides examples demonstrating how to update and upsert structured properties for various entities. Changes
Poem
Tip AI model upgrade
|
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.
Actionable comments posted: 4
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (5)
- entity-registry/src/main/java/com/linkedin/metadata/aspect/patch/builder/StructuredPropertiesPatchBuilder.java (3 hunks)
- entity-registry/src/main/java/com/linkedin/metadata/aspect/patch/builder/StructuredPropertyDefinitionPatchBuilder.java (1 hunks)
- metadata-integration/java/datahub-client/src/test/java/datahub/client/patch/PatchTest.java (3 hunks)
- metadata-integration/java/examples/src/main/java/io/datahubproject/examples/DatasetStructuredPropertiesUpdate.java (1 hunks)
- metadata-integration/java/examples/src/main/java/io/datahubproject/examples/StructuredPropertyUpsert.java (1 hunks)
Additional comments not posted (14)
entity-registry/src/main/java/com/linkedin/metadata/aspect/patch/builder/StructuredPropertiesPatchBuilder.java (4)
Line range hint
19-34
: LGTM!The method correctly removes a structured property by its URN.
53-69
: LGTM!The method correctly sets a number property with a list of integer values.
90-106
: LGTM!The method correctly sets a string property with a list of string values.
Line range hint
137-145
: LGTM!The methods correctly return the aspect name and entity type.
entity-registry/src/main/java/com/linkedin/metadata/aspect/patch/builder/StructuredPropertyDefinitionPatchBuilder.java (6)
34-41
: LGTM!The method correctly sets the qualified name for a structured property.
43-50
: LGTM!The method correctly sets the display name for a structured property.
52-59
: LGTM!The method correctly sets the value type for a structured property.
61-75
: LGTM!The method correctly sets the type qualifier for a structured property.
77-92
: LGTM!The method correctly adds an allowed value for a structured property.
94-102
: LGTM!The method correctly sets the cardinality for a structured property.
metadata-integration/java/datahub-client/src/test/java/datahub/client/patch/PatchTest.java (4)
652-654
: Verify the reason for ignoring the test.The test method is marked with
@Ignore
. Ensure that this is intentional and not an oversight.
696-696
: Ensure the test should be active.The test method is not marked with
@Ignore
. Ensure that this is intentional and not an oversight.
697-718
: LGTM! Ensure the correctness of the patch builder logic.The logic for building the patch looks good. Verify that the
StructuredPropertiesPatchBuilder
is functioning as expected.
655-693
: LGTM! Ensure the correctness of the patch builder logic.The logic for building the patch looks good. Verify that the
StructuredPropertyDefinitionPatchBuilder
is functioning as expected.
public static void main(String[] args) | ||
throws IOException, ExecutionException, InterruptedException { | ||
|
||
// Adding a structured property with a single string value | ||
MetadataChangeProposal mcp1 = | ||
new StructuredPropertiesPatchBuilder() | ||
.urn( | ||
UrnUtils.getUrn( | ||
"urn:li:dataset:(urn:li:dataPlatform:hive,SampleCypressHiveDataset,PROD)")) | ||
.setStringProperty( | ||
UrnUtils.getUrn("urn:li:structuredProperty:io.acryl.privacy.retentionTime"), "30") | ||
.build(); | ||
|
||
String token = ""; | ||
RestEmitter emitter = RestEmitter.create(b -> b.server("http://localhost:8080").token(token)); | ||
Future<MetadataWriteResponse> response1 = emitter.emit(mcp1, null); | ||
System.out.println(response1.get().getResponseContent()); | ||
|
||
// Adding a structured property with a list of string values | ||
List<String> values = new ArrayList<>(); | ||
values.add("30"); | ||
values.add("90"); | ||
MetadataChangeProposal mcp2 = | ||
new StructuredPropertiesPatchBuilder() | ||
.urn( | ||
UrnUtils.getUrn( | ||
"urn:li:dataset:(urn:li:dataPlatform:hive,SampleCypressHiveDataset,PROD)")) | ||
.setStringProperty( | ||
UrnUtils.getUrn("urn:li:structuredProperty:io.acryl.privacy.retentionTime"), values) | ||
.build(); | ||
|
||
Future<MetadataWriteResponse> response2 = emitter.emit(mcp2, null); | ||
System.out.println(response2.get().getResponseContent()); | ||
|
||
// Adding a structured property with a single number value | ||
MetadataChangeProposal mcp3 = | ||
new StructuredPropertiesPatchBuilder() | ||
.urn( | ||
UrnUtils.getUrn( | ||
"urn:li:dataset:(urn:li:dataPlatform:hive,SampleCypressHiveDataset,PROD)")) | ||
.setNumberProperty( | ||
UrnUtils.getUrn("urn:li:structuredProperty:io.acryl.dataManagement.replicationSLA"), | ||
3456) | ||
.build(); | ||
|
||
Future<MetadataWriteResponse> response3 = emitter.emit(mcp3, null); | ||
System.out.println(response3.get().getResponseContent()); | ||
|
||
// Removing a structured property from a dataset | ||
MetadataChangeProposal mcp4 = | ||
new StructuredPropertiesPatchBuilder() | ||
.urn( | ||
UrnUtils.getUrn( | ||
"urn:li:dataset:(urn:li:dataPlatform:hive,SampleCypressHiveDataset,PROD)")) | ||
.removeProperty( | ||
UrnUtils.getUrn("urn:li:structuredProperty:io.acryl.dataManagement.replicationSLA")) | ||
.build(); | ||
|
||
Future<MetadataWriteResponse> response4 = emitter.emit(mcp4, null); | ||
System.out.println(response4.get().getResponseContent()); | ||
} |
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.
Add error handling and logging.
The main
method lacks error handling and logging. Adding these will enhance maintainability and debugging.
public static void main(String[] args)
throws IOException, ExecutionException, InterruptedException {
try {
// Adding a structured property with a single string value
MetadataChangeProposal mcp1 =
new StructuredPropertiesPatchBuilder()
.urn(
UrnUtils.getUrn(
"urn:li:dataset:(urn:li:dataPlatform:hive,SampleCypressHiveDataset,PROD)"))
.setStringProperty(
UrnUtils.getUrn("urn:li:structuredProperty:io.acryl.privacy.retentionTime"), "30")
.build();
String token = "";
RestEmitter emitter = RestEmitter.create(b -> b.server("http://localhost:8080").token(token));
Future<MetadataWriteResponse> response1 = emitter.emit(mcp1, null);
System.out.println(response1.get().getResponseContent());
// Adding a structured property with a list of string values
List<String> values = new ArrayList<>();
values.add("30");
values.add("90");
MetadataChangeProposal mcp2 =
new StructuredPropertiesPatchBuilder()
.urn(
UrnUtils.getUrn(
"urn:li:dataset:(urn:li:dataPlatform:hive,SampleCypressHiveDataset,PROD)"))
.setStringProperty(
UrnUtils.getUrn("urn:li:structuredProperty:io.acryl.privacy.retentionTime"), values)
.build();
Future<MetadataWriteResponse> response2 = emitter.emit(mcp2, null);
System.out.println(response2.get().getResponseContent());
// Adding a structured property with a single number value
MetadataChangeProposal mcp3 =
new StructuredPropertiesPatchBuilder()
.urn(
UrnUtils.getUrn(
"urn:li:dataset:(urn:li:dataPlatform:hive,SampleCypressHiveDataset,PROD)"))
.setNumberProperty(
UrnUtils.getUrn("urn:li:structuredProperty:io.acryl.dataManagement.replicationSLA"),
3456)
.build();
Future<MetadataWriteResponse> response3 = emitter.emit(mcp3, null);
System.out.println(response3.get().getResponseContent());
// Removing a structured property from a dataset
MetadataChangeProposal mcp4 =
new StructuredPropertiesPatchBuilder()
.urn(
UrnUtils.getUrn(
"urn:li:dataset:(urn:li:dataPlatform:hive,SampleCypressHiveDataset,PROD)"))
.removeProperty(
UrnUtils.getUrn("urn:li:structuredProperty:io.acryl.dataManagement.replicationSLA"))
.build();
Future<MetadataWriteResponse> response4 = emitter.emit(mcp4, null);
System.out.println(response4.get().getResponseContent());
} catch (Exception e) {
System.err.println("An error occurred: " + e.getMessage());
e.printStackTrace();
}
}
public StructuredPropertiesPatchBuilder setNumberProperty( | ||
@Nonnull Urn propertyUrn, @Nullable Integer propertyValue) { | ||
ValueNode propertyValueNode = instance.numberNode((Integer) propertyValue); | ||
ObjectNode value = instance.objectNode(); | ||
value.put(URN_KEY, propertyUrn.toString()); | ||
ObjectNode newProperty = instance.objectNode(); | ||
newProperty.put(URN_KEY, propertyUrn.toString()); | ||
|
||
ArrayNode valuesNode = instance.arrayNode(); | ||
ObjectNode propertyValueNode = instance.objectNode(); | ||
propertyValueNode.set("double", instance.numberNode(propertyValue)); | ||
valuesNode.add(propertyValueNode); | ||
newProperty.set(VALUES_KEY, valuesNode); | ||
|
||
pathValues.add( | ||
ImmutableTriple.of( | ||
PatchOperationType.ADD.getValue(), BASE_PATH + "/" + propertyUrn, propertyValueNode)); | ||
PatchOperationType.ADD.getValue(), BASE_PATH + "/" + propertyUrn, newProperty)); |
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.
Add null check for propertyValue
.
The method can be improved by adding a null check for propertyValue
to handle potential null values gracefully.
public StructuredPropertiesPatchBuilder setNumberProperty(
@Nonnull Urn propertyUrn, @Nullable Integer propertyValue) {
ObjectNode newProperty = instance.objectNode();
newProperty.put(URN_KEY, propertyUrn.toString());
ArrayNode valuesNode = instance.arrayNode();
if (propertyValue != null) {
ObjectNode propertyValueNode = instance.objectNode();
propertyValueNode.set("double", instance.numberNode(propertyValue));
valuesNode.add(propertyValueNode);
}
newProperty.set(VALUES_KEY, valuesNode);
pathValues.add(
ImmutableTriple.of(
PatchOperationType.ADD.getValue(), BASE_PATH + "/" + propertyUrn, newProperty));
return this;
}
public StructuredPropertiesPatchBuilder setStringProperty( | ||
@Nonnull Urn propertyUrn, @Nullable String propertyValue) { | ||
ObjectNode newProperty = instance.objectNode(); | ||
newProperty.put(URN_KEY, propertyUrn.toString()); | ||
|
||
ArrayNode valuesNode = instance.arrayNode(); | ||
ObjectNode propertyValueNode = instance.objectNode(); | ||
propertyValueNode.set("string", instance.textNode(propertyValue)); | ||
valuesNode.add(propertyValueNode); | ||
newProperty.set(VALUES_KEY, valuesNode); | ||
|
||
pathValues.add( | ||
ImmutableTriple.of( | ||
PatchOperationType.ADD.getValue(), | ||
BASE_PATH + "/" + propertyUrn + "/" + String.valueOf(propertyValue), | ||
propertyValueNode)); | ||
PatchOperationType.ADD.getValue(), BASE_PATH + "/" + propertyUrn, newProperty)); |
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.
Add null check for propertyValue
.
The method can be improved by adding a null check for propertyValue
to handle potential null values gracefully.
public StructuredPropertiesPatchBuilder setStringProperty(
@Nonnull Urn propertyUrn, @Nullable String propertyValue) {
ObjectNode newProperty = instance.objectNode();
newProperty.put(URN_KEY, propertyUrn.toString());
ArrayNode valuesNode = instance.arrayNode();
if (propertyValue != null) {
ObjectNode propertyValueNode = instance.objectNode();
propertyValueNode.set("string", instance.textNode(propertyValue));
valuesNode.add(propertyValueNode);
}
newProperty.set(VALUES_KEY, valuesNode);
pathValues.add(
ImmutableTriple.of(
PatchOperationType.ADD.getValue(), BASE_PATH + "/" + propertyUrn, newProperty));
return this;
}
public static void main(String[] args) | ||
throws IOException, ExecutionException, InterruptedException { | ||
// open ended string structured property on datasets and dataFlows | ||
MetadataChangeProposal mcp1 = | ||
new StructuredPropertyDefinitionPatchBuilder() | ||
.urn( | ||
UrnUtils.getUrn( | ||
"urn:li:structuredProperty:testString")) // use existing urn for update, new urn | ||
// for new property | ||
.setQualifiedName("io.acryl.testString") | ||
.setDisplayName("Open Ended String") | ||
.setValueType("urn:li:dataType:datahub.string") | ||
.setCardinality(PropertyCardinality.SINGLE) | ||
.addEntityType("urn:li:entityType:datahub.dataset") | ||
.addEntityType("urn:li:entityType:datahub.dataFlow") | ||
.setDescription("test description for open ended string") | ||
.setImmutable(true) | ||
.build(); | ||
|
||
String token = ""; | ||
RestEmitter emitter = RestEmitter.create(b -> b.server("http://localhost:8080").token(token)); | ||
Future<MetadataWriteResponse> response1 = emitter.emit(mcp1, null); | ||
System.out.println(response1.get().getResponseContent()); | ||
|
||
// Next, let's make a property that allows for multiple datahub entity urns as values | ||
// This example property could be used to reference other users or groups in datahub | ||
StringArrayMap typeQualifier = new StringArrayMap(); | ||
typeQualifier.put( | ||
"allowedTypes", | ||
new StringArray( | ||
"urn:li:entityType:datahub.corpuser", "urn:li:entityType:datahub.corpGroup")); | ||
|
||
MetadataChangeProposal mcp2 = | ||
new StructuredPropertyDefinitionPatchBuilder() | ||
.urn(UrnUtils.getUrn("urn:li:structuredProperty:dataSteward")) | ||
.setQualifiedName("io.acryl.dataManagement.dataSteward") | ||
.setDisplayName("Data Steward") | ||
.setValueType("urn:li:dataType:datahub.urn") | ||
.setTypeQualifier(typeQualifier) | ||
.setCardinality(PropertyCardinality.MULTIPLE) | ||
.addEntityType("urn:li:entityType:datahub.dataset") | ||
.setDescription( | ||
"The data stewards of this asset are in charge of ensuring data cleanliness and governance") | ||
.setImmutable(true) | ||
.build(); | ||
|
||
Future<MetadataWriteResponse> response2 = emitter.emit(mcp2, null); | ||
System.out.println(response2.get().getResponseContent()); | ||
|
||
// Finally, let's make a single select number property with a few allowed options | ||
PropertyValue propertyValue1 = new PropertyValue(); | ||
PrimitivePropertyValue value1 = new PrimitivePropertyValue(); | ||
value1.setDouble(30.0); | ||
propertyValue1.setDescription( | ||
"30 days, usually reserved for datasets that are ephemeral and contain pii"); | ||
propertyValue1.setValue(value1); | ||
PropertyValue propertyValue2 = new PropertyValue(); | ||
PrimitivePropertyValue value2 = new PrimitivePropertyValue(); | ||
value2.setDouble(90.0); | ||
propertyValue2.setDescription( | ||
"Use this for datasets that drive monthly reporting but contain pii"); | ||
propertyValue2.setValue(value2); | ||
|
||
MetadataChangeProposal mcp3 = | ||
new StructuredPropertyDefinitionPatchBuilder() | ||
.urn(UrnUtils.getUrn("urn:li:structuredProperty:replicationSLA")) | ||
.setQualifiedName("io.acryl.dataManagement.replicationSLA") | ||
.setDisplayName("Replication SLA") | ||
.setValueType("urn:li:dataType:datahub.string") | ||
.addAllowedValue(propertyValue1) | ||
.addAllowedValue(propertyValue2) | ||
.setCardinality(PropertyCardinality.SINGLE) | ||
.addEntityType("urn:li:entityType:datahub.dataset") | ||
.setDescription( | ||
"SLA for how long data can be delayed before replicating to the destination cluster") | ||
.setImmutable(false) | ||
.build(); | ||
|
||
Future<MetadataWriteResponse> response3 = emitter.emit(mcp3, null); | ||
System.out.println(response3.get().getResponseContent()); | ||
} |
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.
Add error handling and logging.
The main
method lacks error handling and logging. Adding these will enhance maintainability and debugging.
public static void main(String[] args)
throws IOException, ExecutionException, InterruptedException {
try {
// open ended string structured property on datasets and dataFlows
MetadataChangeProposal mcp1 =
new StructuredPropertyDefinitionPatchBuilder()
.urn(
UrnUtils.getUrn(
"urn:li:structuredProperty:testString")) // use existing urn for update, new urn
// for new property
.setQualifiedName("io.acryl.testString")
.setDisplayName("Open Ended String")
.setValueType("urn:li:dataType:datahub.string")
.setCardinality(PropertyCardinality.SINGLE)
.addEntityType("urn:li:entityType:datahub.dataset")
.addEntityType("urn:li:entityType:datahub.dataFlow")
.setDescription("test description for open ended string")
.setImmutable(true)
.build();
String token = "";
RestEmitter emitter = RestEmitter.create(b -> b.server("http://localhost:8080").token(token));
Future<MetadataWriteResponse> response1 = emitter.emit(mcp1, null);
System.out.println(response1.get().getResponseContent());
// Next, let's make a property that allows for multiple datahub entity urns as values
// This example property could be used to reference other users or groups in datahub
StringArrayMap typeQualifier = new StringArrayMap();
typeQualifier.put(
"allowedTypes",
new StringArray(
"urn:li:entityType:datahub.corpuser", "urn:li:entityType:datahub.corpGroup"));
MetadataChangeProposal mcp2 =
new StructuredPropertyDefinitionPatchBuilder()
.urn(UrnUtils.getUrn("urn:li:structuredProperty:dataSteward"))
.setQualifiedName("io.acryl.dataManagement.dataSteward")
.setDisplayName("Data Steward")
.setValueType("urn:li:dataType:datahub.urn")
.setTypeQualifier(typeQualifier)
.setCardinality(PropertyCardinality.MULTIPLE)
.addEntityType("urn:li:entityType:datahub.dataset")
.setDescription(
"The data stewards of this asset are in charge of ensuring data cleanliness and governance")
.setImmutable(true)
.build();
Future<MetadataWriteResponse> response2 = emitter.emit(mcp2, null);
System.out.println(response2.get().getResponseContent());
// Finally, let's make a single select number property with a few allowed options
PropertyValue propertyValue1 = new PropertyValue();
PrimitivePropertyValue value1 = new PrimitivePropertyValue();
value1.setDouble(30.0);
propertyValue1.setDescription(
"30 days, usually reserved for datasets that are ephemeral and contain pii");
propertyValue1.setValue(value1);
PropertyValue propertyValue2 = new PropertyValue();
PrimitivePropertyValue value2 = new PrimitivePropertyValue();
value2.setDouble(90.0);
propertyValue2.setDescription(
"Use this for datasets that drive monthly reporting but contain pii");
propertyValue2.setValue(value2);
MetadataChangeProposal mcp3 =
new StructuredPropertyDefinitionPatchBuilder()
.urn(UrnUtils.getUrn("urn:li:structuredProperty:replicationSLA"))
.setQualifiedName("io.acryl.dataManagement.replicationSLA")
.setDisplayName("Replication SLA")
.setValueType("urn:li:dataType:datahub.string")
.addAllowedValue(propertyValue1)
.addAllowedValue(propertyValue2)
.setCardinality(PropertyCardinality.SINGLE)
.addEntityType("urn:li:entityType:datahub.dataset")
.setDescription(
"SLA for how long data can be delayed before replicating to the destination cluster")
.setImmutable(false)
.build();
Future<MetadataWriteResponse> response3 = emitter.emit(mcp3, null);
System.out.println(response3.get().getResponseContent());
} catch (Exception e) {
System.err.println("An error occurred: " + e.getMessage());
e.printStackTrace();
}
}
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.
Actionable comments posted: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- metadata-integration/java/datahub-client/src/test/java/datahub/client/patch/PatchTest.java (4 hunks)
Additional comments not posted (1)
metadata-integration/java/datahub-client/src/test/java/datahub/client/patch/PatchTest.java (1)
20-21
: Imports are necessary and correctly used.The added imports for
StringArray
,StringArrayMap
,StructuredPropertiesPatchBuilder
,StructuredPropertyDefinitionPatchBuilder
,PrimitivePropertyValue
,PropertyCardinality
, andPropertyValue
are required and correctly used in the newly added tests.Also applies to: 35-36, 40-42
@Test | ||
@Ignore | ||
public void testLocalStructuredPropertiesUpdate() { | ||
try { | ||
MetadataChangeProposal mcp = | ||
new StructuredPropertiesPatchBuilder() | ||
.urn( | ||
UrnUtils.getUrn( | ||
"urn:li:dataset:(urn:li:dataPlatform:hive,SampleCypressHiveDataset,PROD)")) | ||
.setNumberProperty( | ||
UrnUtils.getUrn( | ||
"urn:li:structuredProperty:io.acryl.dataManagement.replicationSLA"), | ||
3456) | ||
.build(); | ||
|
||
String token = ""; | ||
RestEmitter emitter = RestEmitter.create(b -> b.server("http://localhost:8080").token(token)); | ||
Future<MetadataWriteResponse> response = emitter.emit(mcp, null); | ||
System.out.println(response.get().getResponseContent()); | ||
|
||
} catch (IOException | ExecutionException | InterruptedException e) { | ||
System.out.println(Arrays.asList(e.getStackTrace())); | ||
} | ||
} |
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.
Ensure proper handling of RestEmitter
resource and token usage.
The RestEmitter
resource should be properly closed after use to avoid potential resource leaks. Additionally, the token usage should be verified for correctness.
try (RestEmitter emitter = RestEmitter.create(b -> b.server("http://localhost:8080").token(token))) {
...
} catch (IOException | ExecutionException | InterruptedException e) {
System.out.println(Arrays.asList(e.getStackTrace()));
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
@Test | |
@Ignore | |
public void testLocalStructuredPropertiesUpdate() { | |
try { | |
MetadataChangeProposal mcp = | |
new StructuredPropertiesPatchBuilder() | |
.urn( | |
UrnUtils.getUrn( | |
"urn:li:dataset:(urn:li:dataPlatform:hive,SampleCypressHiveDataset,PROD)")) | |
.setNumberProperty( | |
UrnUtils.getUrn( | |
"urn:li:structuredProperty:io.acryl.dataManagement.replicationSLA"), | |
3456) | |
.build(); | |
String token = ""; | |
RestEmitter emitter = RestEmitter.create(b -> b.server("http://localhost:8080").token(token)); | |
Future<MetadataWriteResponse> response = emitter.emit(mcp, null); | |
System.out.println(response.get().getResponseContent()); | |
} catch (IOException | ExecutionException | InterruptedException e) { | |
System.out.println(Arrays.asList(e.getStackTrace())); | |
} | |
} | |
@Test | |
@Ignore | |
public void testLocalStructuredPropertiesUpdate() { | |
try { | |
MetadataChangeProposal mcp = | |
new StructuredPropertiesPatchBuilder() | |
.urn( | |
UrnUtils.getUrn( | |
"urn:li:dataset:(urn:li:dataPlatform:hive,SampleCypressHiveDataset,PROD)")) | |
.setNumberProperty( | |
UrnUtils.getUrn( | |
"urn:li:structuredProperty:io.acryl.dataManagement.replicationSLA"), | |
3456) | |
.build(); | |
String token = ""; | |
try (RestEmitter emitter = RestEmitter.create(b -> b.server("http://localhost:8080").token(token))) { | |
Future<MetadataWriteResponse> response = emitter.emit(mcp, null); | |
System.out.println(response.get().getResponseContent()); | |
} | |
} catch (IOException | ExecutionException | InterruptedException e) { | |
System.out.println(Arrays.asList(e.getStackTrace())); | |
} | |
} |
@Test | ||
@Ignore | ||
public void testLocalStructuredPropertyDefinitionAdd() { | ||
RestEmitter restEmitter = new RestEmitter(RestEmitterConfig.builder().build()); | ||
try { | ||
StringArrayMap typeQualifier = new StringArrayMap(); | ||
typeQualifier.put( | ||
"allowedTypes", | ||
new StringArray( | ||
"urn:li:entityType:datahub.corpuser", "urn:li:entityType:datahub.corpGroup")); | ||
PropertyValue propertyValue1 = new PropertyValue(); | ||
PrimitivePropertyValue value1 = new PrimitivePropertyValue(); | ||
value1.setString("test value 1"); | ||
propertyValue1.setValue(value1); | ||
PropertyValue propertyValue2 = new PropertyValue(); | ||
PrimitivePropertyValue value2 = new PrimitivePropertyValue(); | ||
value2.setString("test value 2"); | ||
propertyValue2.setValue(value2); | ||
|
||
MetadataChangeProposal structuredPropertyDefinitionPatch = | ||
new StructuredPropertyDefinitionPatchBuilder() | ||
.urn(UrnUtils.getUrn("urn:li:structuredProperty:123456")) | ||
.setQualifiedName("test.testing.123") | ||
.setDisplayName("Test Display Name") | ||
.setValueType("urn:li:dataType:datahub.urn") | ||
.setTypeQualifier(typeQualifier) | ||
.addAllowedValue(propertyValue1) | ||
.addAllowedValue(propertyValue2) | ||
.setCardinality(PropertyCardinality.MULTIPLE) | ||
.addEntityType("urn:li:entityType:datahub.dataFlow") | ||
.setDescription("test description") | ||
.setImmutable(true) | ||
.build(); | ||
|
||
Future<MetadataWriteResponse> response = restEmitter.emit(structuredPropertyDefinitionPatch); | ||
|
||
System.out.println(response.get().getResponseContent()); | ||
|
||
} catch (IOException | ExecutionException | InterruptedException e) { | ||
System.out.println(Arrays.asList(e.getStackTrace())); | ||
} | ||
} |
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.
Ensure proper handling of RestEmitter
resource.
The RestEmitter
resource should be properly closed after use to avoid potential resource leaks.
try (RestEmitter restEmitter = new RestEmitter(RestEmitterConfig.builder().build())) {
...
} catch (IOException | ExecutionException | InterruptedException e) {
System.out.println(Arrays.asList(e.getStackTrace()));
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
@Test | |
@Ignore | |
public void testLocalStructuredPropertyDefinitionAdd() { | |
RestEmitter restEmitter = new RestEmitter(RestEmitterConfig.builder().build()); | |
try { | |
StringArrayMap typeQualifier = new StringArrayMap(); | |
typeQualifier.put( | |
"allowedTypes", | |
new StringArray( | |
"urn:li:entityType:datahub.corpuser", "urn:li:entityType:datahub.corpGroup")); | |
PropertyValue propertyValue1 = new PropertyValue(); | |
PrimitivePropertyValue value1 = new PrimitivePropertyValue(); | |
value1.setString("test value 1"); | |
propertyValue1.setValue(value1); | |
PropertyValue propertyValue2 = new PropertyValue(); | |
PrimitivePropertyValue value2 = new PrimitivePropertyValue(); | |
value2.setString("test value 2"); | |
propertyValue2.setValue(value2); | |
MetadataChangeProposal structuredPropertyDefinitionPatch = | |
new StructuredPropertyDefinitionPatchBuilder() | |
.urn(UrnUtils.getUrn("urn:li:structuredProperty:123456")) | |
.setQualifiedName("test.testing.123") | |
.setDisplayName("Test Display Name") | |
.setValueType("urn:li:dataType:datahub.urn") | |
.setTypeQualifier(typeQualifier) | |
.addAllowedValue(propertyValue1) | |
.addAllowedValue(propertyValue2) | |
.setCardinality(PropertyCardinality.MULTIPLE) | |
.addEntityType("urn:li:entityType:datahub.dataFlow") | |
.setDescription("test description") | |
.setImmutable(true) | |
.build(); | |
Future<MetadataWriteResponse> response = restEmitter.emit(structuredPropertyDefinitionPatch); | |
System.out.println(response.get().getResponseContent()); | |
} catch (IOException | ExecutionException | InterruptedException e) { | |
System.out.println(Arrays.asList(e.getStackTrace())); | |
} | |
} | |
@Test | |
@Ignore | |
public void testLocalStructuredPropertyDefinitionAdd() { | |
try (RestEmitter restEmitter = new RestEmitter(RestEmitterConfig.builder().build())) { | |
StringArrayMap typeQualifier = new StringArrayMap(); | |
typeQualifier.put( | |
"allowedTypes", | |
new StringArray( | |
"urn:li:entityType:datahub.corpuser", "urn:li:entityType:datahub.corpGroup")); | |
PropertyValue propertyValue1 = new PropertyValue(); | |
PrimitivePropertyValue value1 = new PrimitivePropertyValue(); | |
value1.setString("test value 1"); | |
propertyValue1.setValue(value1); | |
PropertyValue propertyValue2 = new PropertyValue(); | |
PrimitivePropertyValue value2 = new PrimitivePropertyValue(); | |
value2.setString("test value 2"); | |
propertyValue2.setValue(value2); | |
MetadataChangeProposal structuredPropertyDefinitionPatch = | |
new StructuredPropertyDefinitionPatchBuilder() | |
.urn(UrnUtils.getUrn("urn:li:structuredProperty:123456")) | |
.setQualifiedName("test.testing.123") | |
.setDisplayName("Test Display Name") | |
.setValueType("urn:li:dataType:datahub.urn") | |
.setTypeQualifier(typeQualifier) | |
.addAllowedValue(propertyValue1) | |
.addAllowedValue(propertyValue2) | |
.setCardinality(PropertyCardinality.MULTIPLE) | |
.addEntityType("urn:li:entityType:datahub.dataFlow") | |
.setDescription("test description") | |
.setImmutable(true) | |
.build(); | |
Future<MetadataWriteResponse> response = restEmitter.emit(structuredPropertyDefinitionPatch); | |
System.out.println(response.get().getResponseContent()); | |
} catch (IOException | ExecutionException | InterruptedException e) { | |
System.out.println(Arrays.asList(e.getStackTrace())); | |
} | |
} |
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- metadata-integration/java/datahub-client/src/test/java/datahub/client/patch/PatchTest.java (4 hunks)
Files skipped from review as they are similar to previous changes (1)
- metadata-integration/java/datahub-client/src/test/java/datahub/client/patch/PatchTest.java
a7f4b71
into
datahub-project:master
This PR tackles two main pieces in the Java SDK around structured properties:
So now you should be able to create structured properties and then assign/patch them on assets using the java SDK.
Checklist
Summary by CodeRabbit
New Features
Tests
These updates enhance the flexibility and capabilities of managing structured properties, providing users with robust options for handling complex data structures.