Previous Next JavaScript must be enabled to correctly display this content

## load

    load -file <path to file>

Loads the named file and interpret its contents as a script of commands to be executed. If any of the commands in the script fail, execution will stop at that point.

For example, users of the Table API can use the load command to define a table and insert data using a single script. Suppose you have a table defined like this:

    create table IF NOT EXISTS Users (
      id integer,
      firstname string,
      lastname string,
      age integer,
      income integer,
      primary key (id)
    );

Then sample data for that table can be defined using JSON like this:

    {
    "id":1,
    "firstname":"David",
    "lastname":"Morrison",
    "age":25,
    "income":100000
    }
    {
    "id":2,
    "firstname":"John",
    "lastname":"Anderson",
    "age":35,
    "income":100000
    }
    {
    "id":3,
    "firstname":"John",
    "lastname":"Morgan",
    "age":38,
    "income":200000
    }
    {
    "id":4,
    "firstname":"Peter",
    "lastname":"Smith",
    "age":38,
    "income":80000
    }
    {
    "id":5,
    "firstname":"Dana",
    "lastname":"Scully",
    "age":47,
    "income":400000
    }

Assume that the sample data is contained in a file called `Users.json`. Then you can define the table and load the sample data using a script that looks like this (file name `loadTable.txt`) :

    ### Begin Script ###
    execute "create table IF NOT EXISTS Users ( \
      id integer, \
      firstname string, \
      lastname string, \
      age integer, \
      income integer, \
      primary key (id) \
    )"

    put table -name Users -file users.json

Then, the script can be run by using the `load` command:

    > java -Xmx64m -Xms64m \
    -jar KVHOME/lib/kvstore.jar runadmin -host node01 -port 5000 \
    -security \
    KVROOT/securtiy/client.security \
    -store mystore
    kv-> load -file ./loadTable.txt
    Statement completed successfully
    Loaded 5 rows to Users

    kv->

If you are using the Key/Value API, first you create schema in the store:

    {
         "type": "record",
         "name": "ContactInfo",
         "namespace": "example",
         "fields": [
             {"name": "phone", "type": "string", "default": ""},
             {"name": "email", "type": "string", "default": ""},
             {"name": "city", "type": "string", "default": ""}
         ]
    }

Then you can collect the following commands in the script file `load-contacts-5.txt`:

    ### Begin Script ###
    put -key /contact/Bob/Walker -value "{\"phone\":\"857-431-9361\", \
    \"email\":\"Nunc@Quisque.com\",\"city\":\"Turriff\"}" \
    -json example.ContactInfo
    put -key /contact/Craig/Cohen -value "{\"phone\":\"657-486-0535\", \
    \"email\":\"sagittis@metalcorp.net\",\"city\":\"Hamoir\"}" \
    -json example.ContactInfo
    put -key /contact/Lacey/Benjamin -value "{\"phone\":\"556-975-3364\", \
    \"email\":\"Duis@laceyassociates.ca\",\"city\":\"Wasseiges\"}" \
    -json example.ContactInfo
    put -key /contact/Preston/Church -value "{\"phone\":\"436-396-9213\", \
    \"email\":\"preston@mauris.ca\",\"city\":\"Helmsdale\"}" \
    -json example.ContactInfo
    put -key /contact/Evan/Houston -value "{\"phone\":\"028-781-1457\", \
    \"email\":\"evan@texfoundation.org\",\"city\":\"Geest-G\"}" \
    -json example.ContactInfo
    exit
    ### End Script ###

The script can be run by using the `load` command:

    > java -Xmx64m -Xms64m \
    -jar KVHOME/lib/kvstore.jar runadmin -host node01 -port 5000 \
    -security \
    KVROOT/securtiy/client.security \
    -store mystore
    kv-> load -file ./load-contacts-5.txt
    Operation successful, record inserted.
    Operation successful, record inserted.
    Operation successful, record inserted.
    Operation successful, record inserted.
    Operation successful, record inserted.

For more information on using the load command, see Create a script to configure the data store.