Understanding Createview in SQLITE3 - sqlite

I am trying to understand CREATE VIEW command in SQLite, but getting strange view.
I have a CSV file,
table.csv / tab separated
ID NAME AGE ADDRESS SALARY
1 Paul 32 California 20000.0
2 Allen 25 Texas 15000.0
3 Teddy 23 Norway 20000.0
4 Mark 25 Rich-Mond 65000.0
5 David 27 Texas 85000.0
6 Kim 22 South-Hall 45000.0
7 James 24 Houston 10000.0
run commands*
sqlite3 sample.db
.mode csv
.import table.csv COMPANY
CREATE VIEW COMPANY_VIEW AS
SELECT "ID", "NAME", "AGE"
FROM COMPANY;
SELECT * FROM COMPANY_VIEW;
getting
"1 ",NAME,"32 "
"2 ",NAME,"25 "
"3 ",NAME,"23 "
"4 ",NAME,"25 "
"5 ",NAME,"27 "
"6 ",NAME,"22 "
"7 ",NAME,"24 "
Why I am not getting NAME Column. What I am doing wrong. I am an absolute beginner in SQLITE3.

Suggest issuing .schema COMPANY and/or SELECT * FROM COMPANY before the CREATE VIEW command.
From the sqlite doc
Use the ".import" command to import CSV (comma separated value) data into an SQLite table.
The operative term here is comma separated.
Use the .separator command to change the separator to tab.

Related

Error while importing minitab file into R

I was using the foreign package in R to import the MTP file, but it only shows file read error. I already set up the default directory, but it does not work. I would really appreciate if I could get some help. Thank you in advance.
library(foreign)
d44<-read.mtp("PERAGGR.MTP")
Here is the file that I was using
The read.mtp function is fairly ancient. And since that file is actually an ASCII file, just read it with `readLines:
d44<-readLines("~/Downloads/PERAGGR.MTP")
head(d44)
# ============== top of output==================
[1] "Minitab Portable Worksheet P1.1 2007 523 Rel 15.0 ."
[2] "% 3 1 109 0 Study ."
[3] " 1.000000000E+00 2.000000000E+00 3.000000000E+00 4.000000000E+00 5.000000000E+00"
[4] " 6.000000000E+00 7.000000000E+00 8.000000000E+00 9.000000000E+00 1.000000000E+01"
[5] " 1.100000000E+01 1.200000000E+01 1.300000000E+01 1.400000000E+01 1.500000000E+01"
[6] " 1.600000000E+01 1.700000000E+01 1.800000000E+01 1.900000000E+01 2.000000000E+01"

How can I access the data in a Cassandra Table using RCassandra

I need to get the data in a column of a table Cassandra Database. I am using RCassandra for this. After getting the data I need to do some text mining on it. Please suggest me how do connect to cassandra, and get the data into my R Script using RCassandra
My RScript :
library(RCassandra)
connect.handle <- RC.connect(host="127.0.0.1", port=9160)
RC.cluster.name(connect.handle)
RC.use(connect.handle, 'mykeyspace')
sourcetable <- RC.read.table(connect.handle, "sourcetable")
print(ncol(sourcetable))
print(nrow(sourcetable))
print(sourcetable)
This will print the output as:
> print(ncol(sourcetable))
[1] 1
> print(nrow(sourcetable))
[1] 18
> print(sourcetable)
144 BBC News
158 IBN Live
123 Reuters
131 IBN Live
But my cassandra table contains four columns, but here its showing only 1 column. I need to get each column values separated. So how do I get the individual column values(Eg.each feedurl) What changes should I make in my R script?
My cassandra table, named sourcetable
I have used Cassandra and R with the correct Cran Jar files, but RCassandra is easier. RCassandra is a direct interface to Cassandra without the use of Java. To connect to Cassandra you will use RC.connect to return a connection handle like this.
RC.connect(host = <xxx>, port = <xxx>)
RC.login(conn, username = "bar", password = "foo")
You can then use a RC.get command to retrieve data or RC.ReadTable command to read table data.
BUT, First you should read THIS
I am confused as well. Table demo.emp has 4 row and 4 columns ( empid, deptid, first_name and last_name). Neither RC.get nor RC.read.table gets the all the data.
cqlsh:demo> select * from emp;
empid | deptid | first_name | last_name
-------+--------+------------+-----------
1 | 1 | John | Doe
1 | 2 | Mia | Lewis
2 | 1 | Jean | Doe
2 | 2 | Manny | Lewis
> RC.get.range.slices(c, "emp", limit=10)
[[1]]
key value ts
1 1.474796e+15
2 John 1.474796e+15
3 Doe 1.474796e+15
4 1.474796e+15
5 Mia 1.474796e+15
[[2]]
key value ts
1 1.474796e+15
2 Jean 1.474796e+15
3 Doe 1.474796e+15
4 1.474796e+15
5 Manny 1.474796e+15

Showing numbers without scientific notation in R

I need to show the following table in Markdown:
resumen<-data.frame(dato=c('cant_cli','debit', 'costo_real',
'comis_max', 'pagos', 'comis_real',
'recupero%'),
valor=
c(nrow(ops), sum(ops$Debit),sum(ops$costo_real),
sum(ops$comision_max), sum(ops$Amount), sum(ops$comision_ganada),
sum(ops$Amount)/sum(ops$Debit)
))
The result is:
dato valor
1 cant_cli 6.217400e+04
2 debit 3.943952e+06
3 costo_real 2.641091e+04
4 comis_max 1.021484e+05
5 pagos 2.003838e+06
6 comis_real 5.189941e+04
7 recupero% 5.080788e-01
But I need to have the following format:
dato valor
cant_cli 62174
debit 3943952
costo_real 26411
comis_max 102148
pagos 2003838
comis_real 51899
recupero% 50.80%
How can I make the code use this format?
Try this
as.numeric(resumen[,2])

Row count for a column

In my subreport I want do display for eg.
Number of clients born in 1972: 34
So in the database I have a list of their birth years
How can I display this number in a field?
Here is a Sample of the data:
<Born> <Name> <BleBle>
1981 Mnr EH Van Niekerk 9517
1982 MEV A BELL 9520
1972 Mnr GI van der Westhuize 9517
1987 Mnr A Juyn 9517
1983 Mev MJC Prinsloo 9513
1972 Mnr WA Van Rensburg 9517
1989 Kmdt EL Van Der Colff 9514
1972 Mnr JS Jansen Van Vuuren 9517
So if this was all the data the output would have to be
Number of clients born in 1972: 3
Create a variable BORN_IN_1972.
Set its "Variable class" to java.lang.Integer.
Set "Calculation" to "Count".
Set "Variable Expression" to $F{Born}.
Set "Initial Value Expression" to 0.
Than add "Summary" band to your report. And put static text "Number of clients born in 1972:" and text field "$V{BORN_IN_1972}" into it.
Assuming birth year is a string:
SELECT COUNT(*)
FROM MyClients
WHERE birth_year = '1972'
And if birth year is being used as an input control:
SELECT COUNT(*)
FROM MyClients
WHERE birth_year = $P{birth_year}
To count non-zero records in jasper use the expression below -
( $F{test} == 0.0 ? null : $F{test} )

Exception importing data into neo4j using batch-import

I am running neo-4j 1.8.2 on a remote unix box. I am using this jar (https://github.com/jexp/batch-import/downloads).
nodes.csv is same as given in example:
name age works_on
Michael 37 neo4j
Selina 14
Rana 6
Selma 4
rels.csv is like this:
start end type since counter:int
1 2 FATHER_OF 1998-07-10 1
1 3 FATHER_OF 2007-09-15 2
1 4 FATHER_OF 2008-05-03 3
3 4 SISTER_OF 2008-05-03 5
2 3 SISTER_OF 2007-09-15 7
But i am getting this exception :
Using Existing Configuration File
Total import time: 0 seconds
Exception in thread "main" java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(StringTokenizer.java:332)
at org.neo4j.batchimport.Importer$Data.split(Importer.java:156)
at org.neo4j.batchimport.Importer$Data.update(Importer.java:167)
at org.neo4j.batchimport.Importer.importNodes(Importer.java:226)
at org.neo4j.batchimport.Importer.main(Importer.java:83)
I am new to neo4j, was checking if this importer can save some coding effort.
It would be great if someone can point to the probable mistake.
Thanks for help!
--Edit:--
My nodes.csv
name dob city state s_id balance desc mgr_primary mgr_secondary mgr_tertiary mgr_name mgr_status
John Von 8/11/1928 Denver CO 1114-010 7.5 RA 0023-0990 0100-0110 Doozman Keith Active
my rels.csv
start end type since status f_type f_num
2 1 address_of
1 3 has_account 5 Active
4 3 f_of Primary 0111-0230
Hi I had some issues in the past with the batch import script.
The formating of your file must be very rigorous, which means :
no extra spaces where not expected, like the ones I see in the first line of your rels.csv before "start"
no multiple spaces in place of the tab. If your files are exactly like what you've copied here, you have 4 spaces instead of on tab, and this is not going to work, as the script uses a tokenizer looking for tabs !!!
I had this issue because I always convert tabs to 4 spaces, and once I understood that, I stopped doing it for my csv !

Resources