-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptsteps.html
209 lines (181 loc) · 6.42 KB
/
optsteps.html
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!--
<title>
Visual Optsteps
</title>
<body>
SQL:
<pre id="sql" style="padding: 5px 0px; overflow-x:auto; tab-size:4">
SELECT 1+1 AS two, 2+2 AS four
</pre>
<pre id="sql" style="padding: 5px 0px; overflow-x:auto; tab-size:4">
project
├── columns: two:1!null four:2!null
├── values
│ └── ()
└── projections
├── 1 + 1 [as=two:1]
└── 2 + 2 [as=four:2]
</pre>
</body>
-->
<!DOCTYPE html>
<html lang="en-us">
<title>Optsteps</title>
<body>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.1/styles/github.min.css" />
<link
rel="stylesheet"
type="text/css"
href="https://cdn.jsdelivr.net/npm/diff2html/bundles/css/diff2html.min.css"
/>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/diff2html/bundles/js/diff2html-ui-base.min.js"></script>
</head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pako/2.0.3/pako.min.js"></script>
<script>
var compressed = window.location.search;
if (compressed.length <= 1) {
compressed = window.location.hash
}
compressed = compressed.substring(1)
// Decode base64 (convert ascii to binary).
var strData = atob(compressed.replace(/-/g, '+').replace(/_/g, '/'));
// Convert binary string to character-number array
var charData = strData.split('').map(function(x){return x.charCodeAt(0);});
// Turn number array into byte-array
var binData = new Uint8Array(charData);
// Pako magic
var data = pako.inflate(binData);
var strData = new TextDecoder("utf-8").decode(data)
var data = JSON.parse(strData);
document.addEventListener('DOMContentLoaded', function () {
var sqlBox = document.getElementById("sql");
var normDiv = document.getElementById('normalization');
var exploreDiv = document.getElementById('exploration');
var radioNorm = document.getElementById("norm_radio");
var radioExplore = document.getElementById("explore_radio");
radioNorm.onchange = function(r) {
if (radioNorm.checked) {
normDiv.style = ""
exploreDiv.style = "display: none"
} else {
normDiv.style = "display: none"
exploreDiv.style = ""
}
}
radioExplore.onchange = radioNorm.onchange
// Populate the SQL.
document.getElementById("sql").innerHTML = data.SQL;
var configuration = {
inputFormat: 'json',
drawFileList: true,
fileListToggle: false,
fileListStartVisible: false,
fileContentToggle: false,
matching: 'lines',
outputFormat: 'side-by-side',
synchronisedScroll: true,
highlight: false,
renderNothingWhenEmpty: false,
};
var normDiff = data.NormDiff;
if (!normDiff) {
// Backward compatibility.
normDiff = data.Normdiff;
}
var exploreDiff = data.ExploreDiff;
var diff1 = new Diff2HtmlUI(normDiv, normDiff, configuration);
diff1.draw();
var diff2 = new Diff2HtmlUI(exploreDiv, exploreDiff, configuration);
diff2.draw();
var titleSpans = document.getElementsByClassName('d2h-file-list-title')
titleSpans[1].innerHTML = titleSpans[1].innerHTML.replace('Files changed', 'Normalization steps');
titleSpans[2].innerHTML = titleSpans[2].innerHTML.replace('Files changed', 'Exploration steps');
// Do some very basic syntax highlighting. We pick the pattern that
// matches at the earliest index, and among those we pick the first in the
// list. Each pattern has a "token" capture group, and optionally a
// "prefix" group. We add a <span> around the token inside the parens and
// repeat with the rest of the string.
var patterns = [
// All fields that are followed by a colon are attributes (not operators).
{
style: 'hljs-attribute',
match: /(?<prefix>(├|└)── )(?<token>[a-zA-Z][^:]*):/,
},
// Top-level attributes.
{
style: 'hljs-attribute',
match: /(?<prefix>(├|└)── )(?<token>immutable|mutable|stable|volatile|mutations|has-placeholder|)/
},
// Other attributes.
{
style: 'hljs-attribute',
match: /(?<token>\b(outer|constraints|fd|tight)\b)/,
},
// Operators.
{
style: 'hljs-title',
match: /(?<prefix>^|(├|└)── )(?<token>[a-zA-Z][^: ]*)/,
},
{
style: 'hljs-number',
match: /(?<token>(\b[0-9][0-9]*))/,
},
{
style: 'hljs-number',
match: /(?<token>\bNULL\b)/,
},
{
style: 'hljs-built_in',
match: /(?<token>!null)/,
},
]
var codeLines = document.getElementsByClassName('d2h-code-line-ctn')
for (var i = 0; i < codeLines.length; i++) {
var cl = codeLines[i];
var str = cl.innerHTML;
var out = "";
while (true) {
var bestMatch = null;
var style = null;
patterns.forEach(function (pattern) {
var match = str.match(pattern.match);
if (match && (!bestMatch || match.index < bestMatch.index)) {
bestMatch = match;
style = pattern.style;
}
})
if (!bestMatch) {
break
}
var tokenStart = bestMatch.index
if (bestMatch.groups.prefix) {
tokenStart += bestMatch.groups.prefix.length
}
out += str.substr(0, tokenStart) + '<span class="' + style + '">' + bestMatch.groups.token + '</span>';
str = str.substr(tokenStart + bestMatch.groups.token.length);
}
cl.innerHTML = out + str;
}
})
</script>
<body>
<div class="d2h-file-list-title">Query:</div>
<div style="margin-left:5%;">
<pre id="sql" style="padding: 5px 0px; overflow-x:auto; tab-size:4">
No data provided via URL fragment or query
</pre>
</div>
<label style="cursor:pointer;">
<input type="radio" id="norm_radio" name="radio" checked style="margin-right:.5em;">Normalization steps
</label>
<label style="cursor:pointer;">
<input type="radio" id="explore_radio" name="radio" style="margin-left:2em;margin-right:.5em;">Exploration steps
</label>
<br>
<br>
<div id="normalization"></div>
<div id="exploration" style="display: none"></div>
</body>
</html>