Repository navigation
Expand file tree
/
Copy pathcreatecolumnartable.sql
More file actions
83 lines (81 loc) · 2 KB
/
Copy pathcreatecolumnartable.sql
File metadata and controls
83 lines (81 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
-- Change file path of csv file below before running this script.
-- This script creates airlineColumnar table needed for running perf tuning tests.
use PerfTuning;
go
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = N'airlineColumnar')
BEGIN
PRINT 'dropping existing table airlineColumnar'
drop table [airlineColumnar];
END
go
create table [airlineColumnar] (
[Year] smallint,
[Month] tinyint,
[DayOfMonth] tinyint,
[DayOfWeek] tinyint,
[DepTime] real,
[CRSDepTime] real,
[ArrTime] real,
[CRSArrTime] real,
[UniqueCarrier] varchar(100),
[FlightNum] smallint,
[TailNum] varchar(100),
[ActualElapsedTime] smallint,
[CRSElapsedTime] smallint,
[AirTime] smallint,
[ArrDelay] smallint,
[DepDelay] smallint,
[Origin] char(3),
[Dest] char(3),
[Distance] smallint,
[TaxiIn] smallint,
[TaxiOut] smallint,
[Cancelled] bit,
[CancellationCode] varchar(100),
[Diverted] bit,
[CarrierDelay] smallint,
[WeatherDelay] smallint,
[NASDelay] smallint,
[SecurityDelay] smallint,
[LateAircraftDelay] smallint,
);
go
CREATE CLUSTERED COLUMNSTORE INDEX airline_clustered ON airlineColumnar;
GO
DELETE FROM airlineColumnar
PRINT 'bulk inserting data from airline-cleaned-10M.csv into airlineColumnar'
GO
bulk insert airlineColumnar
from 'E:\PerfTuning\Data\airline-cleaned-10M.csv'
with(
batchsize = 1000000, -- Reduce this value if there is memory issue
fieldterminator = ',',
keepnulls,
-- lastrow = 100,
firstrow = 2 -- Skip header
);
go
PRINT 'Inserting Data Done'
GO
ALTER TABLE airlineColumnar
ADD Late BIT
ALTER TABLE airlineColumnar
ADD CRSDepHour int
GO
PRINT 'computing Late and ArrDelay column values.'
GO
update airlineColumnar
set CRSDepHour=ROUND(CRSDepTime, 0, 1), Late=case when ArrDelay>15 then 1 else 0 end
GO
PRINT 'computing done'
GO
PRINT 'adding id column and rebuilding index'
GO
ALTER TABLE airlineColumnar
ADD id INT IDENTITY(1,1)
ALTER INDEX airline_clustered ON airlineColumnar
REBUILD
GO
PRINT 'rebuilding done'
GO