Skip to content

06 Append Or Insert

hkuich edited this page Nov 22, 2021 · 1 revision

About

This generator appends attributes if the matching entity is already present in the dataset, and if not, inserts it along with both the matching and to be inserted attributes

Schema

person sub entity,
        ...
        owns first-name,
        owns last-name,
        owns phone-number,
        owns city,
        owns age,
        owns nick-name,
        owns twitter-username,
        owns fakebook-link,
        ...;

Data

first_name,last_name,phone_number,city,age,nick_name
Melli,Winchcum,+7 171 898 0853,London,55,Mel
Sakura,,,Fire Village,13
Xylina,D'Alesco,+7 690 597 4443,Cambridge,51,Xyl
Sasuke,,+62 107 666 3334,Fire Village,13
Elenore,Stokey,+62 107 530 7500,Oxford,35,Elen
Naruto,Uzamaki,+62 107 321 3333,Fire Village,12

Configuration

{
  "globalConfig": {...},
  "attributes": {...},
  "entities": {...},
  "relations": {...},
  "appendAttribute": {...},
  "appendAttributeOrInsertThing": {             // all appendAttributeOrInsertThing generators go here
    "append-or-insert-person": {                // key for generator in appendAttributes, must be unique
      "data": [                                 // files from which to load data
        "src/test/resources/1.0.0/phoneCalls/person-append-or-insert.csv"
      ],
      "match": {
        "type": "person",       // entity type to append attributes to
        "ownerships": [         // attribute(s) the entity already has, ideally a key / something or combination that is uniquely identifying. 
                                // If no thing in the graph is matched, this entity and following ownerships are inserted
          {
            "attribute": "phone-number",      // attribute type to match on
            "column": "phone_number"          // column from which to load values
          }
        ]
      },
      "insert": {
        "ownerships": [                   // attributes to append if present. 
                                          //If no thing is found by match block above, insert attributes along with match attribute above
          {
            "attribute": "first-name",    // attribute type to append/insert
            "column": "first_name"        // column from which to load values
          },
          ...
        ]
      }
    }
  }
}

TypeDB Loader will check if the entity and attributes you are trying to match on/insert are present in your schema. It will also ensure that all values in your data files adhere to the attribute's value type specified in your schema or try to cast them. If a value cannot be cast, it is not inserted, and the line written out into an error log see logging.

See the full phone-calls schema here.

See the full phone-calls config file here.

See the full data file here.