Skip to content

05 Appending Attributes

hkuich edited this page Nov 22, 2021 · 1 revision

About

If you already have things loaded to which you would like to append additional attributes (i.e. data that is in a separate file / comes from a different data source / you want to extend your existing graph), you can do the following:

Schema

twitter-username sub attribute,
      value string;

person sub entity,
        ...
        owns twitter-username;

Data

phone_number,twitter
+7 171 898 0853,@jojo
+263 498 495 0617,@hui###@bui
+370 351 224 5176,@lalulix
+81 308 988 7153,@go34
...

Configuration

{
  "globalConfig": {...},
  "attributes": {...},
  "entities": {...},
  "relations": {...},
  "appendAttribute": {            // all appendAttribute generators go here
    "append-twitter": {           // key for generator in appendAttributes, must be unique
      "data": [                   // files from which to load data
        "src/test/resources/1.0.0/phoneCalls/append-twitter-nickname.csv"
      ],
      "match": {
        "type": "person",                 // entity/relation type to append attributes to
        "ownerships": [                   // attribute(s) the entity/relation already has, ideally a key / something or 
                                          // combination that is uniquely identifying
          {
            "attribute": "phone-number",      // attribute type to match on
            "column": "phone_number"          // column from which to load values
          }
        ]
      },
      "insert": {
        "ownerships": [                         // attributes to append
          {
            "attribute": "twitter-username",    // attribute type to insert
            "column": "twitter",                // column from which to load values
            "listSeparator": "###",             // if column in a data file is a list of values, TypeDB Loader will split the list with the provided listSeparator and insert len(list) number of attributes
            "required": true                    // required defaults to false - if set to true, TypeDB Loader only inserts a data row if a value in this column exists and is of the correct type/can be cast
          },
          {
            "attribute": "nick-name",
            "column": "nick_name"
          }
        ]
      }
    },
    ...
  },
  ...
}

TypeDB Loader will check if the 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.