Académique Documents
Professionnel Documents
Culture Documents
Purpose
In this tutorial, you retrieve data from an Oracle NoSQL Database by providing multiple primary keys.
Time to Complete
15 minutes (approximately).
Background
Oracle NoSQL Database is a scalable, distributed NoSQL database, designed to provide highly reliable, flexible and available data management across a configurable set of
storage nodes.
Consider an eCommerce website, where potential customers want to retrieve all the phones in the price range $ 200 to $ 500 from Apple, Samsung, Nokia, Motorola (for
example) and a host of other manufacturers to view all the details including the images of the product. These can all be retrieved only by specifying multiple primary keys to
the get operation.
Oracle NoSQL Database now includes a high performance API to perform bulk get. You can retrieve records matching multiple primary keys in a single operation. You can
relate this to the IN clause that you supply to a SQL query. The API takes as input a list of keys, which can be a partial or complete shard key, and does a parallel scan across
the shards. It returns an iterator over the matching rows including those matched by the ancestor or descendant tables. The only two criterias are that the primary key must
contain all the field defined for the table's shard key, and the primary key must belong to the same table.
In this section, you load some sample data into a kvstore. In this tutorial, you use table model to store the sample data. For this you need to create a table and then insert the
records. Perform the following steps:
1. Log into the system where Oracle NoSQL Database is installed and running. Open a terminal window and navigate to your working directory.
$ cd /home/oracle/kvstore
2. Confirm that the configured kvstore is running by using the ping command.
Output:
http://www.oracle.com/webfolder/technetwork/tutorials/obe/nosql/bulkgetapi/index.html 2/12/2017
Retrieving Bulk Data in Oracle NoSQL Database Page 2 of 4
OUTPUT:
kv->
OUTPUT:
kv-> exec "create table phones(manufacturer string, price double, name string, primary key(shard(manufacturer), price))"
OUTPUT:
OUTPUT:
{
"type" : "table",
"name" : "phones",
"owner" : null,
"comment" : null,
"shardKey" : [ "manufacturer" ],
"primaryKey" : [ "manufacturer", "price" ],
"fields" : [ {
"name" : "manufacturer",
"type" : "STRING",
"nullable" : true,
"default" : null
}, {
"name" : "price",
"type" : "DOUBLE",
"nullable" : true,
"default" : null
}, {
"name" : "name",
"type" : "STRING",
"nullable" : true,
"default" : null
} ]
}
7. Load a script file that contains commands to insert records into the table.
Note: If you receive an error, ensure that you are in the working directory or specify the absolute path of the data.txt file.
OUTPUT:
http://www.oracle.com/webfolder/technetwork/tutorials/obe/nosql/bulkgetapi/index.html 2/12/2017
Retrieving Bulk Data in Oracle NoSQL Database Page 3 of 4
{"manufacturer":"Apple","price":199.991,"name":"s1"}
{"manufacturer":"Apple","price":200.1,"name":"s2"}
{"manufacturer":"Apple","price":499.991,"name":"s3"}
{"manufacturer":"Apple","price":500.001,"name":"s4"}
{"manufacturer":"Samsung","price":199.991,"name":"s1"}
{"manufacturer":"Samsung","price":200.1,"name":"s2"}
{"manufacturer":"Samsung","price":499.991,"name":"s3"}
{"manufacturer":"Samsung","price":500.001,"name":"s4"}
{"manufacturer":"AAA","price":199.991,"name":"s1"}
{"manufacturer":"DDD","price":500.001,"name":"s4"}
{"manufacturer":"Motorola","price":199.991,"name":"s1"}
{"manufacturer":"Motorola","price":200.1,"name":"s2"}
{"manufacturer":"Motorola","price":499.991,"name":"s3"}
{"manufacturer":"Motorola","price":500.001,"name":"s4"}
{"manufacturer":"BBB","price":200.1,"name":"s2"}
{"manufacturer":"CCC","price":499.991,"name":"s3"}
{"manufacturer":"Nokia","price":199.991,"name":"s1"}
{"manufacturer":"Nokia","price":200.1,"name":"s2"}
{"manufacturer":"Nokia","price":499.991,"name":"s3"}
{"manufacturer":"Nokia","price":500.001,"name":"s4"}
20 rows returned
kv-> exit
In this section, you create a java class to retrieve data using multiple primary keys. You inspect the key lines of the code and then compile and run the Java class.
http://www.oracle.com/webfolder/technetwork/tutorials/obe/nosql/bulkgetapi/index.html 2/12/2017
Retrieving Bulk Data in Oracle NoSQL Database Page 4 of 4
http://www.oracle.com/webfolder/technetwork/tutorials/obe/nosql/bulkgetapi/index.html 2/12/2017