SOLR-14090: fix delete-copy-field when source is dynamic field

This commit is contained in:
Munendra S N 2020-02-04 21:33:31 +05:30
parent 4eff9c9b5e
commit c91dd9d0e4
3 changed files with 81 additions and 4 deletions

View File

@ -259,6 +259,8 @@ Bug Fixes
* SOLR-13897: Fix unsafe publication of Terms object in ZkShardTerms that can cause visibility issues
and race conditions under contention. (shalin)
* SOLR-14090: Handle the case in `delete-copy-field` when source is a dynamic field (Frank Iversen, Munendra S N)
Other Changes
---------------------

View File

@ -860,7 +860,11 @@ public final class ManagedIndexSchema extends IndexSchema {
break;
}
}
} else { // non-dynamic copy field directive
}
if (!found) {
// non-dynamic copy field directive.
// Here, source field could either exists in schema or match a dynamic rule
List<CopyField> copyFieldList = copyFieldsMap.get(source);
if (copyFieldList != null) {
for (Iterator<CopyField> iter = copyFieldList.iterator() ; iter.hasNext() ; ) {

View File

@ -676,6 +676,76 @@ public class TestBulkSchemaAPI extends RestTestBase {
assertEquals("string", m.get("type"));
}
public void testCopyFieldRules() throws Exception {
RestTestHarness harness = restTestHarness;
Map m = getObj(harness, "name", "fields");
assertNotNull("'name' field does not exist in the schema", m);
m = getObj(harness, "bind", "fields");
assertNotNull("'bind' field does not exist in the schema", m);
List l = getSourceCopyFields(harness, "bleh_s");
assertTrue("'bleh_s' copyField rule exists in the schema", l.isEmpty());
String payload = "{\n" +
" 'add-copy-field' : {\n" +
" 'source' :'bleh_s',\n" +
" 'dest':'name'\n" +
" }\n" +
" }\n";
String response = harness.post("/schema", json(payload));
Map map = (Map) fromJSONString(response);
assertNull(response, map.get("error"));
l = getSourceCopyFields(harness, "bleh_s");
assertFalse("'bleh_s' copyField rule doesn't exist", l.isEmpty());
assertEquals("bleh_s", ((Map)l.get(0)).get("source"));
assertEquals("name", ((Map)l.get(0)).get("dest"));
// delete copy field rule
payload = "{\n" +
" 'delete-copy-field' : {\n" +
" 'source' :'bleh_s',\n" +
" 'dest':'name'\n" +
" }\n" +
" }\n";
response = harness.post("/schema", json(payload));
map = (Map) fromJSONString(response);
assertNull(response, map.get("error"));
l = getSourceCopyFields(harness, "bleh_s");
assertTrue("'bleh_s' copyField rule exists in the schema", l.isEmpty());
// copy and delete with multiple destination
payload = "{\n" +
" 'add-copy-field' : {\n" +
" 'source' :'bleh_s',\n" +
" 'dest':['name','bind']\n" +
" }\n" +
" }\n";
response = harness.post("/schema", json(payload));
map = (Map) fromJSONString(response);
assertNull(response, map.get("error"));
l = getSourceCopyFields(harness, "bleh_s");
assertEquals(2, l.size());
payload = "{\n" +
" 'delete-copy-field' : {\n" +
" 'source' :'bleh_s',\n" +
" 'dest':['name','bind']\n" +
" }\n" +
" }\n";
response = harness.post("/schema", json(payload));
map = (Map) fromJSONString(response);
assertNull(response, map.get("error"));
l = getSourceCopyFields(harness, "bleh_s");
assertTrue("'bleh_s' copyField rule exists in the schema", l.isEmpty());
}
public void testDeleteAndReplace() throws Exception {
RestTestHarness harness = restTestHarness;
@ -904,6 +974,7 @@ public class TestBulkSchemaAPI extends RestTestBase {
map = (Map) fromJSONString(response);
assertNull(map.get("error"));
}
public void testSortableTextFieldWithAnalyzer() throws Exception {
String fieldTypeName = "sort_text_type";
String fieldName = "sort_text";