Vous êtes sur la page 1sur 4

Retrieving Bulk Data in Oracle NoSQL Database Page 1 of 4

Retrieving Bulk Data in Oracle NoSQL Database

Before You Begin

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.

What Do You Need?

Oracle NoSQL Database (http://www.oracle.com/technetwork/database/database-technologies/nosqldb/downloads/index.html) (3.5.2 or above) - The software must be


installed, configured, and running.

Scripts (files/files.zip) used in this tutorial.

Loading Sample Data into Oracle NoSQL Database

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.

$ java -jar $KVHOME/lib/kvstore.jar ping -host localhost -port 5000

Output:

Pinging components of store kvstore based upon topology sequence #14


10 partitions and 1 storage nodes
Time: 2016-05-16 09:23:30 UTC Version: 12.1.3.5.2
Shard Status: healthy:1 writable-degraded:0 read-only:0 offline:0
Admin Status: healthy
Zone [name=KVLite id=zn1 type=PRIMARY] RN Status: online:1 offline:0
Storage Node [sn1] on host01:5000 Zone: [name=KVLite id=zn1 type=PRIMARY] Status: RUNNING Ver: 12cR1.3.5.2 2015-12-03 08:36:4
9 UTC Build id: 0c693aa1a5a0
Admin [admin1] Status: RUNNING,MASTER
Rep Node [rg1-rn1] Status: RUNNING,MASTER sequenceNumber:37 haPort:5006

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

$ java -jar $KVHOME/lib/kvstore.jar runadmin -host localhost -port 5000

OUTPUT:

kv->

4. Connect to the kvstore that is up and running.

kv-> connect store -host localhost -port 5000 -name kvstore

OUTPUT:

Connected to kvstore at localhost:5000.

5. Execute the command to create a table to store the sample data.

kv-> exec "create table phones(manufacturer string, price double, name string, primary key(shard(manufacturer), price))"

OUTPUT:

Statement completed successfully

6. Confirm that the table is created.

kv-> show table -name phones

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.

kv-> load -file data.txt

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

Operation successful, row inserted.


Operation successful, row inserted.
Operation successful, row inserted.
Operation successful, row inserted.
Operation successful, row inserted.
Operation successful, row inserted.
Operation successful, row inserted.
Operation successful, row inserted.
Operation successful, row inserted.
Operation successful, row inserted.
Operation successful, row inserted.
Operation successful, row inserted.
Operation successful, row inserted.
Operation successful, row inserted.
Operation successful, row inserted.
Operation successful, row inserted.
Operation successful, row inserted.
Operation successful, row inserted.
Operation successful, row inserted.
Operation successful, row inserted.

8. Confirm that the records are inserted into the table.

kv-> get table -name phones

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

9. Exit the kv prompt.

kv-> exit

Retrieving the Data

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.

Saving the Java Class File

Understanding the Java Class File

Compiling and Running 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

Want to Learn More?


About Oracle (http://www.oracle.com/corporate/index.html) Contact Us (http://www.oracle.com/us/corporate/contact/index.html) Legal Notices (http://www.oracle.com/us/legal/index.html)
Terms of Use (http://www.oracle.com/us/legal/terms/index.html) Your Privacy Rights (http://www.oracle.com/us/legal/privacy/index.html)
Copyright 2015, Oracle and/or its affiliates. All rights reserved.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/nosql/bulkgetapi/index.html 2/12/2017

Vous aimerez peut-être aussi