Commit c820d893 authored by Vishwesh Patel's avatar Vishwesh Patel
Browse files

fixed bugs with sql script

parent f31d5a9b
/*
drop table if exists AnalystArticle;
drop table if exists PartnerArticle;
drop table if exists Article;
drop table if exists IPODetails;
drop table if exists Financials;
drop table if exists StockComment;
drop table if exists StockPrice;
drop table if exists Stock;
*/
/* Create strong entity Stock table which holds symbols, will be populated by the csvs later on */
create table Stock (
symbol varchar(6),
......@@ -164,7 +180,7 @@ add foreign key (symbol) references Stock(symbol);
/* create IPODetails Temp table to store raw date values */
create table IPODetailsTemp (
symbol varchar(6),
symbol varchar(6) unique,
year int,
month int,
day int,
......@@ -190,8 +206,7 @@ create table IPODetails (
marketYearTrend float,
usaCompany varchar(7),
primary key (symbol, day),
foreign key (symbol) references Stock(symbol)
primary key (symbol, day)
);
/* Load raw data into temp table */
......@@ -203,11 +218,18 @@ ignore 1 lines;
/* calculate date-time field and tranfer data to final table */
insert into IPODetails(symbol, day, daysBetterThanSP, daysGreen, marketMonthTrend, market3MonthTrend, market6MonthTrend, marketYearTrend, usaCompany)
select symbol, cast(cast(year as string) + '-' + cast(month as string) + '-' + cast(day as string) as datetime), daysBetterThanSP, daysGreen, marketMonthTrend, market3MonthTrend, market6MonthTrend, marketYearTrend, usaCompany
select symbol, str_to_date(CONCAT(year,'-',lpad(month,2,'00'),'-',lpad(day,2,'00')), '%Y-%m-%d'), daysBetterThanSP, daysGreen, marketMonthTrend, market3MonthTrend, market6MonthTrend, marketYearTrend, usaCompany
from IPODetailsTemp;
drop table if exists IPODetailsTemp;
insert ignore into Stock (symbol)
select distinct symbol
from IPODetails;
alter table IPODetails
add foreign key (symbol) references Stock(symbol);
/********************************************************************************************/
/********************************************************************************************/
......@@ -274,19 +296,22 @@ select id, author
from ArticleTemp
where type = 0;
truncate table ArticleTemp;
/* Load the partner articles */
load data infile '/var/lib/mysql-files/18-Stocks/raw_partner_headlines.csv' ignore into table ArticleTemp
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
ignore 1 lines;
/* Remove invisible characters and set article type */
update ArticleTemp
set symbol = replace(symbol, '\r', ''), type = 1
where type is null;
/* Insert the partner data into the relevant tables */
insert into Article(articleID, symbol, url, headline, date)
insert ignore into Article(articleID, symbol, url, headline, date)
select id, symbol, url, headline, date
from ArticleTemp
where type = 1;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment