load

load -file <path to file> 

指定したファイルをロードし、その内容を実行対象のコマンドのスクリプトとして解釈します。スクリプト内のいずれかのコマンドが失敗した場合、実行はその時点で停止します。

たとえば、表APIのユーザーは、loadコマンドを使用することで、単一のスクリプトを使用して表を定義し、データを挿入できます。次のように定義された表があるとします。

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

この場合、次のようなJSONを使用して、その表のサンプル・データを定義できます。

{
"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
} 

サンプル・データがUsers.jsonというファイルに含まれているとします。この場合、次のようなスクリプト(ファイル名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 

その後、loadコマンドを使用してスクリプトを実行できます。

> 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-> 

キー/値APIを使用している場合は、最初にストア内にスキーマを作成します。

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

続いて、スクリプト・ファイル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 ###

loadコマンドを使用してスクリプトを実行できます。

> 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.

ロード・コマンドの使用の詳細は、「ストアを構成するためのスクリプトの使用」を参照してください。