Loading the data

Log in to the VM using the ID packt (password: packt):

Logging into the Packt VM
# We will start KDB+ - the NoSQL database that we'll use for the tutorial

# Launch the Q Console by typing: packt@vagrant:~$ rlwrap ~/q/l32/q -s 4 -p 5001 KDB+ 3.5 2017.06.15 Copyright (C) 1993-2017 Kx Systems l32/ 1()core 3951MB packt vagrant 127.0.1.1 NONEXPIRE Welcome to kdb+ 32bit edition For support please see http://groups.google.com/d/forum/personal-kdbplus Tutorials can be found at http://code.kx.com/wiki/Tutorials To exit, type \ To remove this startup msg, edit q.q q)
# Enter the following at the Q console. Explanations for each of the commands have been provided in the comments (using /): 
 
/change to the home directory for user packt 
cd /home/packt/ 
 
/Define the schema of the cms table 
d:(`category`city`company`date`firstName`lastName`payment`paymentNature`product`state)!"SSSZSSFSSS"; 
 
/Read the headersfrom the cms csv file. These will be our table column names 
 
columns:system "head -1 cms2016.csv"; 
columns:`$"," vs ssr(raze columns;""";""); 
 
/Run Garbage Collection 
.Q.gc(); 
 
/Load the cms csv file 
	s cms2016:(d columns;enlist",")0:`:cms2016.csv; 
 
/Add a month column to the data 
	s cms2016: `month`date xasc update month:`month$date, date:`date$date from cms2016 
 
.Q.gc(); 
 
/Modify character columns to be lower case. The data contains u 
	s update lower firstName from `cms2016 
	s update lower lastName from `cms2016 
	s update lower city from `cms2016 
	s update lower state from `cms2016 
	s update lower product from `cms2016 
	s update lower category from `cms2016 
	s update lower paymentNature from `cms2016 
	s update lower company from `cms2016
.Q.gc() cms2016:`month`date`firstName`lastName`company`state`city`product`category`payment`paymentNature xcols cms2016 count cms2016 /11 million
/Function to save the data that was read from the CMS csv file
savedata:{show (string .z.T)," Writing: ",string x;cms::delete month from select from cms2016 where month=x; .Q.dpft(`:cms;x;`date;`cms)}
/Save the data in monthly partitions in the current folder 

savedata each 2016.01m +til 12
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.97.187