1 | USE [HeuristicLab.Hive-3.3]
|
---|
2 | /* create and initialize hive database tables */
|
---|
3 |
|
---|
4 | EXEC sp_configure filestream_access_level, 2
|
---|
5 | GO
|
---|
6 | RECONFIGURE
|
---|
7 | GO
|
---|
8 |
|
---|
9 | SET ARITHABORT ON
|
---|
10 | CREATE TABLE [dbo].[AssignedResources](
|
---|
11 | [ResourceId] UniqueIdentifier NOT NULL,
|
---|
12 | [TaskId] UniqueIdentifier NOT NULL,
|
---|
13 | CONSTRAINT [PK_dbo.ResourceIdTaskId] PRIMARY KEY ([ResourceId], [TaskId])
|
---|
14 | )
|
---|
15 | CREATE TABLE [dbo].[Plugin](
|
---|
16 | [PluginId] UniqueIdentifier NOT NULL,
|
---|
17 | [Name] VarChar(MAX) NOT NULL,
|
---|
18 | [Version] VarChar(MAX) NOT NULL,
|
---|
19 | [UserId] UniqueIdentifier NOT NULL,
|
---|
20 | [DateCreated] DateTime NOT NULL,
|
---|
21 | [Hash] VarBinary(20) NOT NULL,
|
---|
22 | CONSTRAINT [PK_dbo.Plugin] PRIMARY KEY ([PluginId])
|
---|
23 | )
|
---|
24 | CREATE TABLE [dbo].[RequiredPlugins](
|
---|
25 | [RequiredPluginId] UniqueIdentifier NOT NULL,
|
---|
26 | [TaskId] UniqueIdentifier NOT NULL,
|
---|
27 | [PluginId] UniqueIdentifier NOT NULL,
|
---|
28 | CONSTRAINT [PK_dbo.RequiredPlugins] PRIMARY KEY ([RequiredPluginId])
|
---|
29 | )
|
---|
30 | CREATE TABLE [dbo].[Resource](
|
---|
31 | [ResourceId] UniqueIdentifier NOT NULL,
|
---|
32 | [Name] VarChar(MAX) NOT NULL,
|
---|
33 | [ResourceType] NVarChar(4000) NOT NULL,
|
---|
34 | [ParentResourceId] UniqueIdentifier,
|
---|
35 | [CpuSpeed] Int,
|
---|
36 | [Memory] Int,
|
---|
37 | [Login] DateTime,
|
---|
38 | [SlaveState] VarChar(15),
|
---|
39 | [Cores] Int,
|
---|
40 | [FreeCores] Int,
|
---|
41 | [FreeMemory] Int,
|
---|
42 | [IsAllowedToCalculate] Bit,
|
---|
43 | [CpuArchitecture] VarChar(3),
|
---|
44 | [OperatingSystem] VarChar(MAX),
|
---|
45 | [LastHeartbeat] DateTime,
|
---|
46 | [CpuUtilization] float,
|
---|
47 | [HbInterval] int NOT NULL,
|
---|
48 | [IsDisposable] Bit,
|
---|
49 | [OwnerUserId] UniqueIdentifier,
|
---|
50 | CONSTRAINT [PK_dbo.Resource] PRIMARY KEY ([ResourceId])
|
---|
51 | )
|
---|
52 | CREATE TABLE [dbo].[ResourcePermission](
|
---|
53 | [ResourceId] UniqueIdentifier NOT NULL,
|
---|
54 | [GrantedUserId] UniqueIdentifier NOT NULL,
|
---|
55 | [GrantedByUserId] UniqueIdentifier NOT NULL,
|
---|
56 | CONSTRAINT [PK_dbo.ResourcePermission] PRIMARY KEY ([ResourceId], [GrantedUserId])
|
---|
57 | )
|
---|
58 | CREATE TABLE [dbo].[Task](
|
---|
59 | [TaskId] UniqueIdentifier NOT NULL,
|
---|
60 | [TaskState] VarChar(30) NOT NULL,
|
---|
61 | [ExecutionTimeMs] float NOT NULL,
|
---|
62 | [LastHeartbeat] DateTime,
|
---|
63 | [ParentTaskId] UniqueIdentifier,
|
---|
64 | [Priority] Int NOT NULL,
|
---|
65 | [CoresNeeded] Int NOT NULL,
|
---|
66 | [MemoryNeeded] Int NOT NULL,
|
---|
67 | [IsParentTask] Bit NOT NULL,
|
---|
68 | [FinishWhenChildJobsFinished] Bit NOT NULL,
|
---|
69 | [Command] VarChar(30),
|
---|
70 | [JobId] UniqueIdentifier NOT NULL,
|
---|
71 | [IsPrivileged] Bit NOT NULL,
|
---|
72 | CONSTRAINT [PK_dbo.Task] PRIMARY KEY ([TaskId])
|
---|
73 | )
|
---|
74 | CREATE TABLE [dbo].[Downtime](
|
---|
75 | [DowntimeId] UniqueIdentifier NOT NULL,
|
---|
76 | [ResourceId] UniqueIdentifier NOT NULL,
|
---|
77 | [StartDate] DateTime NOT NULL,
|
---|
78 | [EndDate] DateTime NOT NULL,
|
---|
79 | [AllDayEvent] Bit NOT NULL,
|
---|
80 | [Recurring] Bit NOT NULL,
|
---|
81 | [RecurringId] UniqueIdentifier NOT NULL,
|
---|
82 | [DowntimeType] VarChar(MAX) NOT NULL,
|
---|
83 | CONSTRAINT [PK_dbo.Downtime] PRIMARY KEY ([DowntimeId])
|
---|
84 | )
|
---|
85 | CREATE TABLE [dbo].[Job](
|
---|
86 | [JobId] UniqueIdentifier NOT NULL,
|
---|
87 | [Name] VarChar(MAX) NOT NULL,
|
---|
88 | [Description] VarChar(MAX),
|
---|
89 | [ResourceIds] VarChar(MAX),
|
---|
90 | [OwnerUserId] UniqueIdentifier NOT NULL,
|
---|
91 | [DateCreated] DateTime NOT NULL,
|
---|
92 | CONSTRAINT [PK_dbo.Job] PRIMARY KEY ([JobId])
|
---|
93 | )
|
---|
94 | CREATE TABLE [dbo].[TaskData](
|
---|
95 | [TaskId] UniqueIdentifier RowGuidCol NOT NULL,
|
---|
96 | [Data] VarBinary(MAX) Filestream NOT NULL,
|
---|
97 | [LastUpdate] DateTime NOT NULL,
|
---|
98 | CONSTRAINT [PK_dbo.TaskData] PRIMARY KEY ([TaskId])
|
---|
99 | )
|
---|
100 | CREATE TABLE [dbo].[PluginData](
|
---|
101 | [PluginDataId] UniqueIdentifier RowGuidCol NOT NULL,
|
---|
102 | [PluginId] UniqueIdentifier NOT NULL,
|
---|
103 | [Data] VarBinary(MAX) FileStream NOT NULL,
|
---|
104 | [FileName] VarChar(MAX) NOT NULL,
|
---|
105 | CONSTRAINT [PK_dbo.PluginData] PRIMARY KEY ([PluginDataId])
|
---|
106 | )
|
---|
107 | CREATE TABLE [dbo].[StateLog](
|
---|
108 | [StateLogId] UniqueIdentifier NOT NULL,
|
---|
109 | [State] VarChar(30) NOT NULL,
|
---|
110 | [DateTime] DateTime NOT NULL,
|
---|
111 | [TaskId] UniqueIdentifier NOT NULL,
|
---|
112 | [UserId] UniqueIdentifier,
|
---|
113 | [SlaveId] UniqueIdentifier,
|
---|
114 | [Exception] VarChar(MAX),
|
---|
115 | CONSTRAINT [PK_dbo.StateLog] PRIMARY KEY ([StateLogId])
|
---|
116 | )
|
---|
117 | CREATE TABLE [dbo].[JobPermission](
|
---|
118 | [JobId] UniqueIdentifier NOT NULL,
|
---|
119 | [GrantedUserId] UniqueIdentifier NOT NULL,
|
---|
120 | [GrantedByUserId] UniqueIdentifier NOT NULL,
|
---|
121 | [Permission] VarChar(15) NOT NULL,
|
---|
122 | CONSTRAINT [PK_dbo.JobPermission] PRIMARY KEY ([JobId], [GrantedUserId])
|
---|
123 | )
|
---|
124 | CREATE TABLE [Lifecycle](
|
---|
125 | [LifecycleId] Int NOT NULL,
|
---|
126 | [LastCleanup] DateTime NOT NULL,
|
---|
127 | CONSTRAINT [PK_Lifecycle] PRIMARY KEY ([LifecycleId])
|
---|
128 | )
|
---|
129 | CREATE TABLE [UserPriority](
|
---|
130 | [UserId] UniqueIdentifier NOT NULL,
|
---|
131 | [DateEnqueued] DateTime NOT NULL,
|
---|
132 | CONSTRAINT [PK_UserPriority] PRIMARY KEY ([UserId])
|
---|
133 | )
|
---|
134 | CREATE TABLE [DeletedJobStatistics](
|
---|
135 | [UserId] UniqueIdentifier NOT NULL,
|
---|
136 | [ExecutionTimeS] float NOT NULL,
|
---|
137 | [ExecutionTimeSFinishedJobs] float NOT NULL,
|
---|
138 | [StartToEndTimeS] float NOT NULL,
|
---|
139 | [DeletedJobStatisticsId] UniqueIdentifier NOT NULL,
|
---|
140 | CONSTRAINT [PK_DeletedJobStatistics] PRIMARY KEY ([DeletedJobStatisticsId])
|
---|
141 | )
|
---|
142 | CREATE TABLE [UserStatistics](
|
---|
143 | [StatisticsId] UniqueIdentifier NOT NULL,
|
---|
144 | [UserId] UniqueIdentifier NOT NULL,
|
---|
145 | [ExecutionTimeMs] float NOT NULL,
|
---|
146 | [UsedCores] Int NOT NULL,
|
---|
147 | [ExecutionTimeMsFinishedJobs] float NOT NULL,
|
---|
148 | [StartToEndTimeMs] float NOT NULL,
|
---|
149 | CONSTRAINT [PK_UserStatistics] PRIMARY KEY ([StatisticsId], [UserId])
|
---|
150 | )
|
---|
151 | CREATE TABLE [SlaveStatistics](
|
---|
152 | [StatisticsId] UniqueIdentifier NOT NULL,
|
---|
153 | [SlaveId] UniqueIdentifier NOT NULL,
|
---|
154 | [Cores] Int NOT NULL,
|
---|
155 | [FreeCores] Int NOT NULL,
|
---|
156 | [CpuUtilization] float NOT NULL,
|
---|
157 | [Memory] Int NOT NULL,
|
---|
158 | [FreeMemory] Int NOT NULL,
|
---|
159 | CONSTRAINT [PK_SlaveStatistics] PRIMARY KEY ([StatisticsId], [SlaveId])
|
---|
160 | )
|
---|
161 | CREATE TABLE [Statistics](
|
---|
162 | [StatisticsId] UniqueIdentifier NOT NULL,
|
---|
163 | [Timestamp] DateTime NOT NULL,
|
---|
164 | CONSTRAINT [PK_Statistics] PRIMARY KEY ([StatisticsId])
|
---|
165 | )
|
---|
166 | ALTER TABLE [dbo].[AssignedResources]
|
---|
167 | ADD CONSTRAINT [Resource_AssignedResource] FOREIGN KEY ([ResourceId]) REFERENCES [dbo].[Resource]([ResourceId])
|
---|
168 | ALTER TABLE [dbo].[AssignedResources]
|
---|
169 | ADD CONSTRAINT [Task_AssignedResource] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[Task]([TaskId])
|
---|
170 | ALTER TABLE [dbo].[RequiredPlugins]
|
---|
171 | ADD CONSTRAINT [Plugin_RequiredPlugin] FOREIGN KEY ([PluginId]) REFERENCES [dbo].[Plugin]([PluginId])
|
---|
172 | ALTER TABLE [dbo].[RequiredPlugins]
|
---|
173 | ADD CONSTRAINT [Task_RequiredPlugin] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[Task]([TaskId])
|
---|
174 | ALTER TABLE [dbo].[Resource]
|
---|
175 | ADD CONSTRAINT [Resource_Resource] FOREIGN KEY ([ParentResourceId]) REFERENCES [dbo].[Resource]([ResourceId])
|
---|
176 | ALTER TABLE [dbo].[ResourcePermission]
|
---|
177 | ADD CONSTRAINT [Resource_ResourcePermission] FOREIGN KEY ([ResourceId]) REFERENCES [dbo].[Resource]([ResourceId])
|
---|
178 | ALTER TABLE [dbo].[Task]
|
---|
179 | ADD CONSTRAINT [Task_Task] FOREIGN KEY ([ParentTaskId]) REFERENCES [dbo].[Task]([TaskId])
|
---|
180 | ALTER TABLE [dbo].[Task]
|
---|
181 | ADD CONSTRAINT [Job_Job] FOREIGN KEY ([JobId]) REFERENCES [dbo].[Job]([JobId])
|
---|
182 | ALTER TABLE [dbo].[Downtime]
|
---|
183 | ADD CONSTRAINT [Resource_Downtime] FOREIGN KEY ([ResourceId]) REFERENCES [dbo].[Resource]([ResourceId])
|
---|
184 | ALTER TABLE [dbo].[TaskData]
|
---|
185 | ADD CONSTRAINT [Task_TaskData] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[Task]([TaskId])
|
---|
186 | ALTER TABLE [dbo].[PluginData]
|
---|
187 | ADD CONSTRAINT [Plugin_PluginData] FOREIGN KEY ([PluginId]) REFERENCES [dbo].[Plugin]([PluginId])
|
---|
188 | ALTER TABLE [dbo].[StateLog]
|
---|
189 | ADD CONSTRAINT [Task_StateLog] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[Task]([TaskId])
|
---|
190 | ALTER TABLE [dbo].[StateLog]
|
---|
191 | ADD CONSTRAINT [Resource_StateLog] FOREIGN KEY ([SlaveId]) REFERENCES [dbo].[Resource]([ResourceId])
|
---|
192 | ALTER TABLE [dbo].[JobPermission]
|
---|
193 | ADD CONSTRAINT [Job_JobPermission] FOREIGN KEY ([JobId]) REFERENCES [dbo].[Job]([JobId])
|
---|
194 | ALTER TABLE [UserStatistics]
|
---|
195 | ADD CONSTRAINT [Statistics_UserStatistics] FOREIGN KEY ([StatisticsId]) REFERENCES [Statistics]([StatisticsId])
|
---|
196 | ALTER TABLE [SlaveStatistics]
|
---|
197 | ADD CONSTRAINT [Statistics_SlaveStatistics] FOREIGN KEY ([StatisticsId]) REFERENCES [Statistics]([StatisticsId])
|
---|
198 |
|
---|
199 | GO
|
---|
200 | CREATE SCHEMA [statistics]
|
---|
201 | GO
|
---|
202 |
|
---|
203 | CREATE TABLE [statistics].[DimTime] (
|
---|
204 | [Time] DATETIME NOT NULL,
|
---|
205 | [Hour] DATETIME NOT NULL,
|
---|
206 | [Day] DATE NOT NULL,
|
---|
207 | [Month] DATE NOT NULL,
|
---|
208 | [Year] DATE NOT NULL,
|
---|
209 | CONSTRAINT [PK_DimTime] PRIMARY KEY CLUSTERED ([Time] ASC)
|
---|
210 | );
|
---|
211 | CREATE TABLE [statistics].[DimClient] (
|
---|
212 | [Id] UNIQUEIDENTIFIER CONSTRAINT [DF_DimClient_Id] DEFAULT (newsequentialid()) NOT NULL,
|
---|
213 | [Name] VARCHAR (MAX) NOT NULL,
|
---|
214 | [ResourceId] UNIQUEIDENTIFIER NOT NULL,
|
---|
215 | [ExpirationTime] DATETIME NULL,
|
---|
216 | [ResourceGroupId] UNIQUEIDENTIFIER NULL,
|
---|
217 | [ResourceGroup2Id] UNIQUEIDENTIFIER NULL,
|
---|
218 | CONSTRAINT [PK_DimClient] PRIMARY KEY CLUSTERED ([Id] ASC)
|
---|
219 | );
|
---|
220 | CREATE TABLE [statistics].[DimJob] (
|
---|
221 | [JobId] UNIQUEIDENTIFIER NOT NULL,
|
---|
222 | [UserId] UNIQUEIDENTIFIER NOT NULL,
|
---|
223 | [JobName] VARCHAR (MAX) NOT NULL,
|
---|
224 | [UserName] VARCHAR (MAX) NOT NULL,
|
---|
225 | CONSTRAINT [PK_DimJob] PRIMARY KEY CLUSTERED ([JobId] ASC)
|
---|
226 | );
|
---|
227 | CREATE TABLE [statistics].[DimUser] (
|
---|
228 | [UserId] UNIQUEIDENTIFIER NOT NULL,
|
---|
229 | [Name] VARCHAR (MAX) NOT NULL,
|
---|
230 | CONSTRAINT [PK_DimUser] PRIMARY KEY CLUSTERED ([UserId] ASC)
|
---|
231 | );
|
---|
232 | CREATE TABLE [statistics].[FactClientInfo] (
|
---|
233 | [ClientId] UNIQUEIDENTIFIER NOT NULL,
|
---|
234 | [Time] DATETIME NOT NULL,
|
---|
235 | [UserId] UNIQUEIDENTIFIER NOT NULL,
|
---|
236 | [NumUsedCores] INT NOT NULL,
|
---|
237 | [NumTotalCores] INT NOT NULL,
|
---|
238 | [UsedMemory] INT NOT NULL,
|
---|
239 | [TotalMemory] INT NOT NULL,
|
---|
240 | [CpuUtilization] FLOAT (53) NOT NULL,
|
---|
241 | [SlaveState] VarChar(15) NOT NULL,
|
---|
242 | [TotalTimeIdle] FLOAT (53) NOT NULL,
|
---|
243 | [TotalTimeCalculating] FLOAT (53) NOT NULL,
|
---|
244 | [TotalTimeTransferring] FLOAT (53) NOT NULL,
|
---|
245 | [TotalTimeOffline] FLOAT (53) NOT NULL,
|
---|
246 | [TotalTimeUnavailable] FLOAT (53) NOT NULL,
|
---|
247 | CONSTRAINT [PK_FactClientInfo] PRIMARY KEY CLUSTERED ([ClientId] ASC, [Time] ASC, [UserId] ASC),
|
---|
248 | CONSTRAINT [FK_FactClientInfo_DimTime] FOREIGN KEY ([Time]) REFERENCES [statistics].[DimTime] ([Time]),
|
---|
249 | CONSTRAINT [FK_FactClientInfo_DimClient] FOREIGN KEY ([ClientId]) REFERENCES [statistics].[DimClient] ([Id]),
|
---|
250 | CONSTRAINT [FK_FactClientInfo_DimUser] FOREIGN KEY ([UserId]) REFERENCES [statistics].[DimUser] ([UserId])
|
---|
251 | );
|
---|
252 | CREATE TABLE [statistics].[FactTask] (
|
---|
253 | [TaskId] UNIQUEIDENTIFIER NOT NULL,
|
---|
254 | [TotalRuntime] FLOAT (53) NOT NULL,
|
---|
255 | [TotalWaitingTime] FLOAT (53) NOT NULL,
|
---|
256 | [TotalTransferTime] FLOAT (53) NOT NULL,
|
---|
257 | [NumCalculationRuns] INT NOT NULL,
|
---|
258 | [NumRetries] INT NOT NULL,
|
---|
259 | [CoresRequired] INT NOT NULL,
|
---|
260 | [MemoryRequired] INT NOT NULL,
|
---|
261 | [Priority] INT NOT NULL,
|
---|
262 | [LastClientId] UNIQUEIDENTIFIER NULL,
|
---|
263 | [JobId] UNIQUEIDENTIFIER NOT NULL,
|
---|
264 | [StartTime] DATETIME NOT NULL,
|
---|
265 | [EndTime] DATETIME NULL,
|
---|
266 | [TaskState] VARCHAR (30) NOT NULL,
|
---|
267 | [Exception] VARCHAR (MAX) NULL,
|
---|
268 | CONSTRAINT [PK_FactTask] PRIMARY KEY CLUSTERED ([TaskId] ASC),
|
---|
269 | CONSTRAINT [FK_FactTask_DimClient] FOREIGN KEY ([LastClientId]) REFERENCES [statistics].[DimClient] ([Id]),
|
---|
270 | CONSTRAINT [FK_FactTask_DimJob] FOREIGN KEY ([JobId]) REFERENCES [statistics].[DimJob] ([JobId]),
|
---|
271 | CONSTRAINT [FK_FactTask_DimTimeStart] FOREIGN KEY ([StartTime]) REFERENCES [statistics].[DimTime] ([Time]),
|
---|
272 | CONSTRAINT [FK_FactTask_DimTimeEnd] FOREIGN KEY ([EndTime]) REFERENCES [statistics].[DimTime] ([Time])
|
---|
273 | );
|
---|
274 |
|
---|
275 | /* dummy for nullable userIds in FactClientInfo */
|
---|
276 | INSERT INTO [statistics].[DimUser] ([UserId], [Name])
|
---|
277 | VALUES ('00000000-0000-0000-0000-000000000000', 'NULL'); |
---|