Skip to content
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

fix(patch): consider escaped characters when applying JSON patches #10717

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
33142d1
fix(patch): consider escaped characters when applying JSON patches
ipolding-cais Jun 14, 2024
b2d7185
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 17, 2024
d6eca35
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 17, 2024
71ce009
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 18, 2024
7c7f16a
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 18, 2024
c0b14a3
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 19, 2024
c8f891c
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 19, 2024
df0bbf3
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 20, 2024
3a0642a
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 20, 2024
1cd7d5a
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 20, 2024
0e666ac
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 21, 2024
874ff97
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 24, 2024
01f9ee0
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 27, 2024
ab14454
Update TemplateUtil.java to use decodeKey method
jjoyce0510 Jun 27, 2024
53ea027
Update TemplateUtil.java
jjoyce0510 Jun 27, 2024
2d00e6f
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 27, 2024
31b9c41
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 27, 2024
0393e2e
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 28, 2024
c136896
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 28, 2024
5db4699
Merge branch 'master' into fix-json-patch-edge-case
jjoyce0510 Jun 28, 2024
e244a77
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 28, 2024
f6e0476
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 28, 2024
0487e44
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 28, 2024
84127bd
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 28, 2024
8ea7e4a
Merge branch 'master' into fix-json-patch-edge-case
ipolding-cais Jun 29, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,18 @@ public static JsonNode populateTopLevelKeys(JsonNode transformedNode, JsonPatch
// Skip first as it will always be blank due to path starting with /
for (int i = 1; i < endIdx; i++) {
if (parent.get(keys[i]) == null) {
((ObjectNode) parent).set(keys[i], instance.objectNode());
String decodedKey = decodeValue(keys[i]);
((ObjectNode) parent).set(decodedKey, instance.objectNode());
}
parent = parent.get(keys[i]);
}
}

return transformedNodeClone;
}

/** Simply decode a JSON-patch encoded value * */
private static String decodeValue(String value) {
return value.replace("~1", "/").replace("~0", "~");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.linkedin.common.UrnArray;
import com.linkedin.common.urn.Urn;
Expand Down Expand Up @@ -254,4 +255,63 @@ public void testLargePatchStandard() throws Exception {
assertEquals(result.getUpstreams().size(), 187, "Expected 1 less upstream");
assertEquals(result.getFineGrainedLineages().size(), 607);
}

@Test
public void testPatchWithFieldWithForwardSlash() throws JsonProcessingException {

String downstreamUrn =
"/fineGrainedLineages/CREATE/urn:li:schemaField:(urn:li:dataset:(urn:li:dataPlatform:bigquery,upstream_table_1,PROD),c1)";
String unescapedUpstreamUrn =
"urn:li:schemaField:(urn:li:dataset:(urn:li:dataPlatform:bigquery,upstream_table_2,PROD),slash/column)";
String escapedUpstreamUrn =
"urn:li:schemaField:(urn:li:dataset:(urn:li:dataPlatform:bigquery,upstream_table_2,PROD),slash~1column)";
String lineagePath = downstreamUrn + "//" + escapedUpstreamUrn;

UpstreamLineageTemplate upstreamLineageTemplate = new UpstreamLineageTemplate();
UpstreamLineage upstreamLineage = upstreamLineageTemplate.getDefault();
JsonPatchBuilder jsonPatchBuilder = Json.createPatchBuilder();

JsonObjectBuilder fineGrainedLineageNode = Json.createObjectBuilder();
JsonValue upstreamConfidenceScore = Json.createValue(1.0f);
fineGrainedLineageNode.add("confidenceScore", upstreamConfidenceScore);

jsonPatchBuilder.add(lineagePath, fineGrainedLineageNode.build());

// Initial population test
UpstreamLineage result =
upstreamLineageTemplate.applyPatch(upstreamLineage, jsonPatchBuilder.build());

assertEquals(
result.getFineGrainedLineages().get(0).getUpstreams().get(0).toString(),
unescapedUpstreamUrn);
}

@Test
public void testPatchWithFieldWithTilde() throws JsonProcessingException {

String downstreamUrn =
"/fineGrainedLineages/CREATE/urn:li:schemaField:(urn:li:dataset:(urn:li:dataPlatform:bigquery,upstream_table_1,PROD),c1)";
String unescapedUpstreamUrn =
"urn:li:schemaField:(urn:li:dataset:(urn:li:dataPlatform:bigquery,upstream_table_2,PROD),tilde~column)";
String escapedUpstreamUrn =
"urn:li:schemaField:(urn:li:dataset:(urn:li:dataPlatform:bigquery,upstream_table_2,PROD),tilde~0column)";
String lineagePath = downstreamUrn + "//" + escapedUpstreamUrn;

UpstreamLineageTemplate upstreamLineageTemplate = new UpstreamLineageTemplate();
UpstreamLineage upstreamLineage = upstreamLineageTemplate.getDefault();
JsonPatchBuilder jsonPatchBuilder = Json.createPatchBuilder();

JsonObjectBuilder fineGrainedLineageNode = Json.createObjectBuilder();
JsonValue upstreamConfidenceScore = Json.createValue(1.0f);
fineGrainedLineageNode.add("confidenceScore", upstreamConfidenceScore);

jsonPatchBuilder.add(lineagePath, fineGrainedLineageNode.build());

// Initial population test
UpstreamLineage result =
upstreamLineageTemplate.applyPatch(upstreamLineage, jsonPatchBuilder.build());
assertEquals(
result.getFineGrainedLineages().get(0).getUpstreams().get(0).toString(),
unescapedUpstreamUrn);
}
}
Loading