@VisibleForTesting
  protected void renamePrefixes(GenericRow record) {
    if (_prefixesToRename.isEmpty()) {
      return;
    }
    List<String> fields = new ArrayList<>(record.getFieldToValueMap().keySet());
    for (Map.Entry<String, String> entry : _prefixesToRename.entrySet()) {
      for (String field : fields) {
        String prefix = entry.getKey();
        String replacementPrefix = entry.getValue();
        if (field.startsWith(prefix)) {
          Object value = record.removeValue(field);
          String remainingColumnName = field.substring(prefix.length());
          String newName = replacementPrefix + remainingColumnName;
          if (newName.isEmpty() || record.getValue(newName) != null) {
            throw new RuntimeException(
                String.format("Name conflict after attempting to rename field %s to %s", field, newName));
          }
          record.putValue(newName, value);
        }
      }
    }
  }
@Test
  public void testRenamePrefixes() {
    HashMap<String, String> prefixesToRename = new HashMap<>();
    prefixesToRename.put("map1.", "");
    prefixesToRename.put("map2", "test");
    ComplexTypeTransformer transformer = new ComplexTypeTransformer(new ArrayList<>(), ".",
        DEFAULT_COLLECTION_TO_JSON_MODE, prefixesToRename, null);

    GenericRow genericRow = new GenericRow();
    genericRow.putValue("a", 1L);
    genericRow.putValue("map1.b", 2L);
    genericRow.putValue("map2.c", "u");
    transformer.renamePrefixes(genericRow);
    Assert.assertEquals(genericRow.getValue("a"), 1L);
    Assert.assertEquals(genericRow.getValue("b"), 2L);
    Assert.assertEquals(genericRow.getValue("test.c"), "u");

    // name conflict where there becomes duplicate field names after renaming
    prefixesToRename = new HashMap<>();
    prefixesToRename.put("test.", "");
    transformer = new ComplexTypeTransformer(new ArrayList<>(), ".",
        DEFAULT_COLLECTION_TO_JSON_MODE, prefixesToRename, null);
    genericRow = new GenericRow();
    genericRow.putValue("a", 1L);
    genericRow.putValue("test.a", 2L);
    try {
      transformer.renamePrefixes(genericRow);
      Assert.fail("Should fail due to name conflict after renaming");
    } catch (RuntimeException e) {
      // expected
    }

    // name conflict where there becomes an empty field name after renaming
    prefixesToRename = new HashMap<>();
    prefixesToRename.put("test", "");
    transformer = new ComplexTypeTransformer(new ArrayList<>(), ".",
        DEFAULT_COLLECTION_TO_JSON_MODE, prefixesToRename, null);
    genericRow = new GenericRow();
    genericRow.putValue("a", 1L);
    genericRow.putValue("test", 2L);
    try {
      transformer.renamePrefixes(genericRow);
      Assert.fail("Should fail due to empty name after renaming");
    } catch (RuntimeException e) {
      // expected
    }

    // case where nothing gets renamed
    prefixesToRename = new HashMap<>();
    transformer = new ComplexTypeTransformer(new ArrayList<>(), ".",
        DEFAULT_COLLECTION_TO_JSON_MODE, prefixesToRename, null);
    genericRow = new GenericRow();
    genericRow.putValue("a", 1L);
    genericRow.putValue("test", 2L);
    transformer.renamePrefixes(genericRow);
    Assert.assertEquals(genericRow.getValue("a"), 1L);
    Assert.assertEquals(genericRow.getValue("test"), 2L);
  }