forked from opensearch-project/opensearch-migrations
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request opensearch-project#1023 from chelma/empty_mappings
Fixed bug in mapping parsing; added tests
- Loading branch information
Showing
33 changed files
with
152 additions
and
14 deletions.
There are no files selected for viewing
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
98 changes: 98 additions & 0 deletions
98
...src/test/java/org/opensearch/migrations/bulkload/transformers/TransformFunctionsTest.java
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,98 @@ | ||
package org.opensearch.migrations.bulkload.transformers; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ArrayNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@Slf4j | ||
public class TransformFunctionsTest { | ||
|
||
@Test | ||
public void removeIntermediateMappingsLevels_AsExpected() throws Exception { | ||
// Extract from {"mappings":[{"_doc":{"properties":{"address":{"type":"text"}}}}]) | ||
ObjectNode testNode1 = new ObjectMapper().createObjectNode(); | ||
ArrayNode mappingsNode1 = new ObjectMapper().createArrayNode(); | ||
ObjectNode docNode1 = new ObjectMapper().createObjectNode(); | ||
ObjectNode propertiesNode1 = new ObjectMapper().createObjectNode(); | ||
ObjectNode addressNode1 = new ObjectMapper().createObjectNode(); | ||
addressNode1.put("type", "text"); | ||
propertiesNode1.set("address", addressNode1); | ||
docNode1.set(TransformFunctions.PROPERTIES_KEY_STR, propertiesNode1); | ||
ObjectNode intermediateNode1 = new ObjectMapper().createObjectNode(); | ||
intermediateNode1.set("_doc", docNode1); | ||
mappingsNode1.add(intermediateNode1); | ||
testNode1.set(TransformFunctions.MAPPINGS_KEY_STR, mappingsNode1); | ||
|
||
TransformFunctions.removeIntermediateMappingsLevels(testNode1); | ||
assertEquals(docNode1.toString(), testNode1.get(TransformFunctions.MAPPINGS_KEY_STR).toString()); | ||
|
||
// Extract from {"mappings":[{"properties":{"address":{"type":"text"}}}]) | ||
ObjectNode testNode2 = new ObjectMapper().createObjectNode(); | ||
ArrayNode mappingsNode2 = new ObjectMapper().createArrayNode(); | ||
ObjectNode propertiesNode2 = new ObjectMapper().createObjectNode(); | ||
ObjectNode addressNode2 = new ObjectMapper().createObjectNode(); | ||
addressNode2.put("type", "text"); | ||
propertiesNode2.set("address", addressNode2); | ||
ObjectNode intermediateNode2 = new ObjectMapper().createObjectNode(); | ||
intermediateNode2.set(TransformFunctions.PROPERTIES_KEY_STR, propertiesNode2); | ||
mappingsNode2.add(intermediateNode2); | ||
testNode2.set(TransformFunctions.MAPPINGS_KEY_STR, mappingsNode2); | ||
|
||
TransformFunctions.removeIntermediateMappingsLevels(testNode2); | ||
assertEquals(intermediateNode2.toString(), testNode2.get(TransformFunctions.MAPPINGS_KEY_STR).toString()); | ||
|
||
// Extract from {"mappings":[]) | ||
ObjectNode testNode3 = new ObjectMapper().createObjectNode(); | ||
ArrayNode mappingsNode3 = new ObjectMapper().createArrayNode(); | ||
testNode3.set(TransformFunctions.MAPPINGS_KEY_STR, mappingsNode3); | ||
|
||
TransformFunctions.removeIntermediateMappingsLevels(testNode3); | ||
assertEquals(new ObjectMapper().createObjectNode().toString(), testNode3.get(TransformFunctions.MAPPINGS_KEY_STR).toString()); | ||
} | ||
|
||
@Test | ||
public void getMappingsFromBeneathIntermediate_AsExpected() throws Exception { | ||
// Extract from {"_doc":{"properties":{"address":{"type":"text"}}}} | ||
ObjectNode testNode1 = new ObjectMapper().createObjectNode(); | ||
ObjectNode docNode1 = new ObjectMapper().createObjectNode(); | ||
ObjectNode propertiesNode1 = new ObjectMapper().createObjectNode(); | ||
ObjectNode addressNode1 = new ObjectMapper().createObjectNode(); | ||
addressNode1.put("type", "text"); | ||
propertiesNode1.set("address", addressNode1); | ||
docNode1.set(TransformFunctions.PROPERTIES_KEY_STR, propertiesNode1); | ||
testNode1.set("_doc", docNode1); | ||
|
||
ObjectNode result1 = TransformFunctions.getMappingsFromBeneathIntermediate(testNode1); | ||
assertEquals(docNode1.toString(), result1.toString()); | ||
|
||
// Extract from {"arbitrary_type":{"properties":{"address":{"type":"text"}}}} | ||
ObjectNode testNode2 = new ObjectMapper().createObjectNode(); | ||
ObjectNode docNode2 = new ObjectMapper().createObjectNode(); | ||
ObjectNode propertiesNode2 = new ObjectMapper().createObjectNode(); | ||
ObjectNode addressNode2 = new ObjectMapper().createObjectNode(); | ||
addressNode2.put("type", "text"); | ||
propertiesNode2.set("address", addressNode2); | ||
docNode2.set(TransformFunctions.PROPERTIES_KEY_STR, propertiesNode2); | ||
testNode2.set("arbitrary_type", docNode2); | ||
|
||
ObjectNode result2 = TransformFunctions.getMappingsFromBeneathIntermediate(testNode2); | ||
assertEquals(docNode2.toString(), result2.toString()); | ||
|
||
// Extract from {"properties":{"address":{"type":"text"}} | ||
ObjectNode testNode3 = new ObjectMapper().createObjectNode(); | ||
ObjectNode propertiesNode3 = new ObjectMapper().createObjectNode(); | ||
ObjectNode addressNode3 = new ObjectMapper().createObjectNode(); | ||
addressNode3.put("type", "text"); | ||
propertiesNode3.set("address", addressNode3); | ||
testNode3.set(TransformFunctions.PROPERTIES_KEY_STR, propertiesNode3); | ||
|
||
ObjectNode result3 = TransformFunctions.getMappingsFromBeneathIntermediate(testNode3); | ||
assertEquals(testNode3.toString(), result3.toString()); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"snapshots":[{"name":"rfs-snapshot","uuid":"rNzQqxl5Qrm99ZzB44Yz0w","state":1,"index_metadata_lookup":{"rtO3hIcQREynKwRVke75sQ":"P4PDS4fFSECIprHxpKSoiQ-_na_-1-1-1","6f5_qLyfQu-MKqe5IEJGuQ":"riC1gLlrR2eh_uAh9Zdpiw-_na_-1-1-1"},"version":"7.10.2"}],"indices":{"bwc_index_1":{"id":"rtO3hIcQREynKwRVke75sQ","snapshots":["rNzQqxl5Qrm99ZzB44Yz0w"],"shard_generations":["OSYnb8w3SKmTqQ_p7m84JA"]},"fwc_index_1":{"id":"6f5_qLyfQu-MKqe5IEJGuQ","snapshots":["rNzQqxl5Qrm99ZzB44Yz0w"],"shard_generations":["73ZKrS4iTc6nKzY0E4kC1w"]}},"min_version":"7.9.0","index_metadata_identifiers":{"riC1gLlrR2eh_uAh9Zdpiw-_na_-1-1-1":"AzJBKpIBKBXpMe1tfd-g","P4PDS4fFSECIprHxpKSoiQ-_na_-1-1-1":"AjJBKpIBKBXpMe1tfd-g"}} | ||
{"snapshots":[{"name":"rfs-snapshot","uuid":"KhcpVj8aRMek0oLMUSPHeg","state":1,"index_metadata_lookup":{"zUFSBaZgSdKCPAS2xEfCww":"ndSIWVDSQpuC8xY2DieX7g-_na_-1-1-1","s_FgCb4gREmddVPRW-EtWw":"BI3xMNgnRe6HldftNpfxzQ-_na_-1-1-1","a5ONDmS2RmmN1GEZMRCJRg":"S0lxKX7vSLS7jzquAnNzdg-_na_-1-1-1","0edrmuSPR1CIr2B6BZbMJA":"tBmFXxGhTeiDlznQiKfNCA-_na_-1-1-1"},"version":"7.10.2"}],"indices":{"empty_mappings_no_docs":{"id":"zUFSBaZgSdKCPAS2xEfCww","snapshots":["KhcpVj8aRMek0oLMUSPHeg"],"shard_generations":["C7dK_wyqSUuDyKkefOXUUQ"]},"bwc_index_1":{"id":"0edrmuSPR1CIr2B6BZbMJA","snapshots":["KhcpVj8aRMek0oLMUSPHeg"],"shard_generations":["tGRrEPUKTuWK_eyviXSHvg"]},"fwc_index_1":{"id":"s_FgCb4gREmddVPRW-EtWw","snapshots":["KhcpVj8aRMek0oLMUSPHeg"],"shard_generations":["yaxW_gAlTNqirWlIIoil8A"]},"no_mappings_no_docs":{"id":"a5ONDmS2RmmN1GEZMRCJRg","snapshots":["KhcpVj8aRMek0oLMUSPHeg"],"shard_generations":["cbs2bGwwSy66JeQOO9vNbQ"]}},"min_version":"7.9.0","index_metadata_identifiers":{"ndSIWVDSQpuC8xY2DieX7g-_na_-1-1-1":"3liaNJIBxXZFvc_xLY-F","S0lxKX7vSLS7jzquAnNzdg-_na_-1-1-1":"31iaNJIBxXZFvc_xLY-F","BI3xMNgnRe6HldftNpfxzQ-_na_-1-1-1":"3ViaNJIBxXZFvc_xLY-F","tBmFXxGhTeiDlznQiKfNCA-_na_-1-1-1":"4FiaNJIBxXZFvc_xLY-F"}} |
Binary file renamed
BIN
+479 Bytes
...REynKwRVke75sQ/0/__d3rngFHgRnOiALrbvS6Odg → ...R1CIr2B6BZbMJA/0/__67c_vZhQSvW4em6Cxfh2lQ
Binary file not shown.
Binary file added
BIN
+2.68 KB
...ces/snapshots/ES_7_10_BWC_Check/indices/0edrmuSPR1CIr2B6BZbMJA/0/__XZWNr4iFS0OndjXNhMWtOg
Binary file not shown.
Binary file added
BIN
+1.22 KB
...snapshots/ES_7_10_BWC_Check/indices/0edrmuSPR1CIr2B6BZbMJA/0/index-tGRrEPUKTuWK_eyviXSHvg
Binary file not shown.
Binary file added
BIN
+1.13 KB
...pshots/ES_7_10_BWC_Check/indices/0edrmuSPR1CIr2B6BZbMJA/0/snap-KhcpVj8aRMek0oLMUSPHeg.dat
Binary file not shown.
Binary file added
BIN
+535 Bytes
.../snapshots/ES_7_10_BWC_Check/indices/0edrmuSPR1CIr2B6BZbMJA/meta-4FiaNJIBxXZFvc_xLY-F.dat
Binary file not shown.
Binary file removed
BIN
-2.68 KB
...ces/snapshots/ES_7_10_BWC_Check/indices/6f5_qLyfQu-MKqe5IEJGuQ/0/__xdhJGeuxSAGPk5gBj8PlfA
Binary file not shown.
Binary file removed
BIN
-1.22 KB
...snapshots/ES_7_10_BWC_Check/indices/6f5_qLyfQu-MKqe5IEJGuQ/0/index-73ZKrS4iTc6nKzY0E4kC1w
Binary file not shown.
Binary file removed
BIN
-1.13 KB
...pshots/ES_7_10_BWC_Check/indices/6f5_qLyfQu-MKqe5IEJGuQ/0/snap-rNzQqxl5Qrm99ZzB44Yz0w.dat
Binary file not shown.
Binary file removed
BIN
-525 Bytes
.../snapshots/ES_7_10_BWC_Check/indices/6f5_qLyfQu-MKqe5IEJGuQ/meta-AzJBKpIBKBXpMe1tfd-g.dat
Binary file not shown.
Binary file added
BIN
+491 Bytes
...snapshots/ES_7_10_BWC_Check/indices/a5ONDmS2RmmN1GEZMRCJRg/0/index-cbs2bGwwSy66JeQOO9vNbQ
Binary file not shown.
Binary file added
BIN
+475 Bytes
...pshots/ES_7_10_BWC_Check/indices/a5ONDmS2RmmN1GEZMRCJRg/0/snap-KhcpVj8aRMek0oLMUSPHeg.dat
Binary file not shown.
Binary file added
BIN
+473 Bytes
.../snapshots/ES_7_10_BWC_Check/indices/a5ONDmS2RmmN1GEZMRCJRg/meta-31iaNJIBxXZFvc_xLY-F.dat
Binary file not shown.
Binary file removed
BIN
-2.68 KB
...ces/snapshots/ES_7_10_BWC_Check/indices/rtO3hIcQREynKwRVke75sQ/0/__q7cUOllVStaQMJVUtgWEPQ
Binary file not shown.
Binary file removed
BIN
-1.22 KB
...snapshots/ES_7_10_BWC_Check/indices/rtO3hIcQREynKwRVke75sQ/0/index-OSYnb8w3SKmTqQ_p7m84JA
Binary file not shown.
Binary file removed
BIN
-1.13 KB
...pshots/ES_7_10_BWC_Check/indices/rtO3hIcQREynKwRVke75sQ/0/snap-rNzQqxl5Qrm99ZzB44Yz0w.dat
Binary file not shown.
Binary file removed
BIN
-535 Bytes
.../snapshots/ES_7_10_BWC_Check/indices/rtO3hIcQREynKwRVke75sQ/meta-AjJBKpIBKBXpMe1tfd-g.dat
Binary file not shown.
Binary file added
BIN
+2.68 KB
...ces/snapshots/ES_7_10_BWC_Check/indices/s_FgCb4gREmddVPRW-EtWw/0/__VpJYHno2ROCuG6vyVjvD4g
Binary file not shown.
Binary file renamed
BIN
+479 Bytes
...Qu-MKqe5IEJGuQ/0/__7d8i9c5gTH62_a-mtjnh1g → ...REmddVPRW-EtWw/0/__gHQYvOH6Rp-cJKmVReWxuQ
Binary file not shown.
Binary file added
BIN
+1.22 KB
...snapshots/ES_7_10_BWC_Check/indices/s_FgCb4gREmddVPRW-EtWw/0/index-yaxW_gAlTNqirWlIIoil8A
Binary file not shown.
Binary file added
BIN
+1.13 KB
...pshots/ES_7_10_BWC_Check/indices/s_FgCb4gREmddVPRW-EtWw/0/snap-KhcpVj8aRMek0oLMUSPHeg.dat
Binary file not shown.
Binary file added
BIN
+525 Bytes
.../snapshots/ES_7_10_BWC_Check/indices/s_FgCb4gREmddVPRW-EtWw/meta-3ViaNJIBxXZFvc_xLY-F.dat
Binary file not shown.
Binary file added
BIN
+492 Bytes
...snapshots/ES_7_10_BWC_Check/indices/zUFSBaZgSdKCPAS2xEfCww/0/index-C7dK_wyqSUuDyKkefOXUUQ
Binary file not shown.
Binary file added
BIN
+476 Bytes
...pshots/ES_7_10_BWC_Check/indices/zUFSBaZgSdKCPAS2xEfCww/0/snap-KhcpVj8aRMek0oLMUSPHeg.dat
Binary file not shown.
Binary file added
BIN
+488 Bytes
.../snapshots/ES_7_10_BWC_Check/indices/zUFSBaZgSdKCPAS2xEfCww/meta-3liaNJIBxXZFvc_xLY-F.dat
Binary file not shown.
Binary file added
BIN
+717 Bytes
RFS/test-resources/snapshots/ES_7_10_BWC_Check/meta-KhcpVj8aRMek0oLMUSPHeg.dat
Binary file not shown.
Binary file removed
BIN
-717 Bytes
RFS/test-resources/snapshots/ES_7_10_BWC_Check/meta-rNzQqxl5Qrm99ZzB44Yz0w.dat
Binary file not shown.
Binary file added
BIN
+330 Bytes
RFS/test-resources/snapshots/ES_7_10_BWC_Check/snap-KhcpVj8aRMek0oLMUSPHeg.dat
Binary file not shown.
Binary file removed
BIN
-287 Bytes
RFS/test-resources/snapshots/ES_7_10_BWC_Check/snap-rNzQqxl5Qrm99ZzB44Yz0w.dat
Binary file not shown.