Class FieldSelector.Path

java.lang.Object
io.debezium.connector.mongodb.FieldSelector.Path
Direct Known Subclasses:
FieldSelector.RemovePath, FieldSelector.RenamePath
Enclosing class:
FieldSelector

@ThreadSafe private abstract static class FieldSelector.Path extends Object
Represents a field that should be excluded from or renamed in MongoDB documents.
  • Field Details

    • namespacePattern

      final Pattern namespacePattern
    • fieldNodes

      final String[] fieldNodes
    • field

      final String field
  • Constructor Details

    • Path

      private Path(Pattern namespacePattern, String[] fieldNodes)
  • Method Details

    • matches

      public boolean matches(String namespace)
      Whether this path applies to the given collection namespace or not.
      Parameters:
      namespace - namespace to match
      Returns:
      true if this path applies to the given collection namespace
    • modify

      public void modify(Map<String,Object> doc, Map<String,Object> setDoc, Map<String,Object> unsetDoc)
      Applies the transformation represented by this path, i.e. removes or renames the represented field.
      Parameters:
      doc - the original document; never null
      setDoc - the value of $set field; may be null
      unsetDoc - the value of $unset field; may be null
    • modifyFields

      private void modifyFields(Map<String,Object> doc, String[] nodes, int beginIndex)
      Modifies fields in the document by the given path nodes start with the begin index.

      Note that the path doesn't support modification of fields inside arrays of arrays.

      Parameters:
      doc - the document to modify fields
      nodes - the path nodes
      beginIndex - the begin index
    • modifyFieldsWithDotNotation

      private void modifyFieldsWithDotNotation(Map<String,Object> doc)
      Modifies fields that use the dot notation, like 'a.b' or 'a.0.b'.

      First, we try to modify field that exactly matches the current path. Then, if the field isn't found, we try to find fields that start with the current path or fields that are part of the current path.

      Parameters:
      doc - the document to modify fields
    • modifyFields

      private void modifyFields(Object value, String[] fieldNodes, int length)
    • excludeNumericItems

      private String[] excludeNumericItems(String[] items)
      Excludes numeric items from the given array.

      If the array has consecutive numeric items, like 'a.0.0.b', then the numeric items aren't excluded. It is necessary because the modification of fields inside arrays of arrays isn't supported.

      Parameters:
      items - the array to exclude numeric items
      Returns:
      filtered items
    • startsWith

      private boolean startsWith(String[] begin, String[] source)
      Returns true if the source array starts with the specified array.
      Parameters:
      begin - the array from which the source array begins
      source - the source array to check
      Returns:
      true if the source array starts with the specified array
    • add

      private <T> List<T> add(List<T> list, T element)
    • checkFieldExists

      String checkFieldExists(Map<String,Object> doc, String field)
    • modifyField

      abstract void modifyField(Map<String,Object> doc, String field)
      Modifies the field in the document used for read, insert and full update operations.
      Parameters:
      doc - the document to modify field
      field - the modified field
    • modifyFieldWithDotNotation

      abstract void modifyFieldWithDotNotation(Map<String,Object> doc, String field)
      Immediately modifies the field that uses the dot notation like 'a.b' in the document used for set and unset update operations.
      Parameters:
      doc - the document to modify field
      field - the modified field
    • generateNewFieldName

      abstract FieldSelector.FieldNameAndValue generateNewFieldName(String[] fieldNodes, Object value)
      Generates a new field name for the given value.
      Parameters:
      fieldNodes - the field nodes
      value - the field value
      Returns:
      a new field name for the given value
    • generateNewFieldName

      abstract String generateNewFieldName(String fieldName)
      Generates a new field name.
      Parameters:
      fieldName - the original field name
      Returns:
      a new field name
    • matchesPath

      public boolean matchesPath(String other)
      Verifies whether a parameter representing path is the same or belongs under this path.
      Parameters:
      other - - the string representing the other path
      Returns:
      - true if this path is the same or parent of the path passed
    • toString

      public String toString()
      Overrides:
      toString in class Object