NoSQL Tutorial
NoSQL can handle data in different way, called list format. A sample table may be:
CODE ACM003 NAME Bart Simpson PHONE 1-555-5432-321 EMAIL bart@springfield.org CODE ACM004 NAME Wiley The Coyote" PHONE 1-800-ILLGETIT EMAIL wiley@looneys.com
Yes, you're right! This is the same way the edit command displays data. Although list tables aren't performing at all, in my opinion they are a good way to insert new data into tables. It's handy creating a program that can output this fashion. An example is shown in Listing 1.
Okay, this is not a “state of the art” shell program, but this example may show that the complete operation is easy with every language, even the shell.
There are a couple of things I would like to emphasize about the above code. How can a list be merged with a real table? The command listtotable does the job for you, as you probably guessed looking at the pipe, converting the list format to the table one. A reverse command, tabletolist, exists as well.
Please notice the beginning and ending newlines, as well as the tabs between field name and value, which appear in the print statement: these are required in order to create the correct list structure.
The list structure, as well as table structure, are well documented in the Chapter 2 of the NoSQL reference you will find in /usr/local/doc/nosql/doc.
Now, let's have a business example? A complete catalog was created using a NoSQL table (see the catalog.rdb file below) and published on the Web dynamically. Every two days, we receive orders from our customers that they have usually created with Excel and exported, at our request, in a coma-separated file.
PRID DESC PRICE ------ ------------------------- ------ PRD001 Acme glue for RoadRunners 30.00 PRD002 Acme TNT 150.00 PRD003 Carrots 5.00 PRD004 Acme toolbox 75.00 The file (sample_order.txt below) we receive has the following format: requester's unique code, Product ID, Quantity.
ACM004,PRD001,5 ACM004,PRD002,30 ACM004,PRD004,1
Now from a shell or command line we run:
export TMPFILE=`mktemp -q /tmp/$0.XXXXXX` ; cat sample_order.txt | \ perl -e 'print "CODE\tPROD\tQTY\n"; print "----\t----\t---\n"; \ while( catalog.rdb | \ nosql addcol SUBTOTAL | nosql compute 'SUBTOTAL = QTY*PRICE' > $TMPFILE ; \ echo "Please bill to:" ; echo "---------------" ; echo ""; cat $TMPFILE |\ nosql join -j CODE - customer.rdb | nosql column NAME PHONE EMAIL | \ nosql body | head -1 ; echo "";echo "" ; cat $TMPFILE | nosql rmcol CODE | \ nosql print -w; echo ""; echo -n "Total due: "; cat $TMPFILE | \ nosql subtotal -T SUBTOTAL | nosql body ; rm $TMPFILEand our output is:
Please bill to: --------------- Wiley The Coyote 1-800-ILLGETIT wiley@looneys.com PROD QTY DESC PRICE SUBTOTAL ------ --- ------------------------- ------ -------- PRD001 5 Acme glue for RoadRunners 30.00 150 PRD002 30 Acme TNT 150.00 4500 PRD004 1 Acme toolbox 75.00 75 Total due: 4725This result may be sent via e-mail to our logistic people. Not so bad for a five-minute single shell command, is it?
I know it's a bit hermetic, so let's have a closer look: the explanation is divided in four sections to be easily read. I will keep out the echo commands which are quite obvious.
export TMPFILE=`mktemp -q /tmp/$0.XXXXXX`: exporting environment variable TMPFILE that contains a runtime generated tempfile.
cat sample_order.txt: get as input the file we received.
perl -e 'print "CODE\tPROD\tQTY\n"; print "-----\t----\t---\n"; while(<STDIN>) { s/,/\t/g; print };`: prints a NoSQL compliant header, composed of CODE, PROD and QTY. Then, it prints the table received from STDIN, substituting a coma (,) with a tab (\t), in order to get the correct table structure.
nosql join -j PROD - catalog.rdb: joins the table read from STDIN (the - character) and catalog.rdb using the PROD (product ID) column.
nosql addcol SUBTOTAL: now a column SUBTOTAL is added to the resulting table.
nosql compute 'SUBTOTAL = QTY*PRICE' > $TMPFILE: calculates the SUBTOTAL column by multiplying quantity and price columns. It then redirects the resulting table to the previous calculated temporary file.
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
| Dart: a New Web Programming Experience | May 07, 2013 |
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- A Topic for Discussion - Open Source Feature-Richness?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Home, My Backup Data Center
- What's the tweeting protocol?
- Readers' Choice Awards
- New Products
- RSS Feeds
- Dart: a New Web Programming Experience
- Reply to comment | Linux Journal
8 hours 29 min ago - Reply to comment | Linux Journal
11 hours 2 min ago - Reply to comment | Linux Journal
12 hours 19 min ago - great post
12 hours 54 min ago - Google Docs
13 hours 16 min ago - Reply to comment | Linux Journal
18 hours 5 min ago - Reply to comment | Linux Journal
18 hours 52 min ago - Web Hosting IQ
20 hours 25 min ago - Thanks for taking the time to
22 hours 2 min ago - Linux is good
1 day 17 sec ago
Enter to Win an Adafruit Prototyping Pi Plate Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Prototyping Pi Plate Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- Next winner announced on 5-21-13!
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.




Comments
dbms
my query is i want the thing as price * qty should give the amount and the total should be calculated for that what is the query in oracle sql(structured query language).