I have 15 GB csv file. It has two columns (trade_time and price).
This is how the data looks like.
trade_time,price
2020-01-01 00:00:01.481,7189.42
2020-01-01 00:00:01.708,7189.42
2020-01-01 00:00:06.290,7189.5
2020-01-01 00:00:06.291,7190.52
2020-01-01 00:00:07.161,7188.97
2020-01-01 00:00:08.274,7189.93
2020-01-01 00:00:09.277,7190.47
2020-01-01 00:00:09.384,7190.47
2020-01-01 00:00:09.630,7190.11
2020-01-01 00:00:09.848,7189.74
2020-01-01 00:00:10.098,7189.46
2020-01-01 00:00:10.197,7189.16
2020-01-01 00:00:10.351,7189.1
I would like to check whether price is up or down by 0.5%. If the price hits +0.5% first, the result is 1. If the price hits -0.5% first, then the result is 0.
At the moment, I'm using this python solution. If database can perform better for my use case, then I would like to move to the database solution.
- Since my task involves timeseries data, which database is better for my use case? SQL or NoSQL?
- Is it really possible to do
percentage based
comparison in databases? e.g.+0.5%
- How long the indexing process usually take for 1 billion rows?
Edit: dbfiddle can be found here.
CREATE TABLE Trades (
trade_time datetime(3) NOT NULL PRIMARY KEY,
price NUMERIC(7,2) NOT NULL
);
INSERT INTO Trades(trade_time,price) VALUES
('2020-01-01 00:00:01.481',7189.42)
,('2020-01-01 00:00:01.708',7189.42)
,('2020-01-01 00:00:06.290',7189.5)
,('2020-01-01 00:00:06.291',7190.52)
,('2020-01-01 00:00:07.161',7188.97)
,('2020-01-01 00:00:08.274',7189.93)
,('2020-01-01 00:00:09.277',7190.47)
,('2020-01-01 00:00:09.384',7190.47)
,('2020-01-01 00:00:09.630',7190.11)
,('2020-01-01 00:00:09.848',7189.74)
CSV Import to MySQL
LOAD DATA INFILE 'trades.csv' INTO TABLE Trades
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(trade_time, price);
3 servers
. Could you elaborate?LOAD DATA INFILE
. I have edited my question to add details. Please do understand that I'm a beginner. So ifLOAD DATA INFILE
is not a better solution, feel free to recommend the better solution. ThanksLAG()
andLEAD()
window functions. Also, you appear to be searching for a suitable database - may I suggest that you take a look at PostgreSQL - there are two systems (extensions) which use it and are specifically geared towards Time Series - TimescaleDB and Citus Data - you might want to take a look. After yourLOAD DATA...
, you can run anUPDATE
using LAG/LEAD to track differences (absolute or %) between adjacent records! HTH...