Skip to content

Commit 5a50d7f

Browse files
authored
Unify bounds checks across all sheet-like format (#233)
* More bounds checks * Add comments * Fix comment * Fix comment * Fixes for rendering missing data * Fix for fmt * Clarify more * Fix for fmt * Embed version in runner binary * Fix override variables * Fix for gofmt * Try separate installs * More specific versions * Bump everything to 1.18.1 * All the retries * Drop effects * Fixes for tsc * Fixes for dark mode * Drop useless r curl * Revert select and radio defaults * Rebuild windows
1 parent 9de174a commit 5a50d7f

File tree

18 files changed

+262
-121
lines changed

18 files changed

+262
-121
lines changed

desktop/panel/file.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ for (const subprocessName of RUNNERS) {
199199
file: path.join('testdata', 'csv', 'missing_columns.csv'),
200200
expected: [
201201
{ a: '3', b: '4' },
202-
{ a: '1', b: '2' },
203-
{ a: '5', b: '6' },
202+
{ a: '1', b: '2', C: '3' },
203+
{ a: '5', b: '6', C: null },
204204
],
205205
name: 'missing columns in csv',
206206
},

desktop/scripts/desktop.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ setenv UI_CONFIG_OVERRIDES "window.DS_CONFIG_MODE = 'desktop';"
22
yarn build-ui
33

44
# Flags from various package management guidelines: https://wiki.archlinux.org/title/Go_package_guidelines
5-
cd runner && go build -trimpath -buildmode=pie -mod=readonly -modcacherw -ldflags="-s -w" -o ../build/go_desktop_runner{required_ext} cmd/main.go
5+
setenv_default VERSION "development"
6+
cd runner && go build -trimpath -buildmode=pie -mod=readonly -modcacherw -ldflags="-s -w -X main.VERSION={VERSION}" -o ../build/go_desktop_runner{required_ext} cmd/main.go
67

78
yarn esbuild desktop/preload.ts --external:electron --sourcemap --bundle --outfile=build/preload.js
89
yarn esbuild desktop/runner.ts --bundle --platform=node --sourcemap --external:better-sqlite3 --external:react-native-fs --external:react-native-fetch-blob "--external:@elastic/elasticsearch" "--external:wasm-brotli" --external:prometheus-query --external:snowflake-sdk --external:ssh2 --external:ssh2-promise --external:ssh2-sftp-client --external:cpu-features --external:electron --target=node10.4 --outfile=build/desktop_runner.js

desktop/scripts/release.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
rm -rf build
22
yarn
33
setenv UI_ESBUILD_ARGS "--minify"
4+
setenv VERSION {arg0}
45
yarn build-desktop
56
prepend "window.DS_CONFIG_MODE='desktop';" build/ui.js
67
prepend "window.DS_CONFIG_VERSION='{arg0}';" build/ui.js

runner/cmd/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import (
66
"github.com/multiprocessio/datastation/runner"
77
)
88

9-
const VERSION = "development"
10-
const APP_NAME = "DataStation Runner (Go)"
9+
// Overridden during build
10+
var (
11+
VERSION = "development"
12+
APP_NAME = "DataStation Runner (Go)"
13+
)
1114

1215
func main() {
1316
runner.Verbose = true

runner/file.go

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,33 @@ import (
2525

2626
var preferredParallelism = runtime.NumCPU() * 2
2727

28+
func indexToExcelColumn(i int) string {
29+
i -= 1
30+
31+
if i/26 > 0 {
32+
return indexToExcelColumn(i/26) + string(rune(i%26+65))
33+
}
34+
35+
return string(rune(i%26 + 65))
36+
}
37+
38+
func recordToMap[T any](row map[string]any, fields *[]string, record []T) {
39+
i := -1 // This is only set to 0 if len(record) > 0
40+
var el T
41+
for i, el = range record {
42+
if i >= len(*fields) {
43+
*fields = append(*fields, indexToExcelColumn(i+1))
44+
}
45+
46+
(row)[(*fields)[i]] = el
47+
}
48+
49+
// If the record has less fields than we've seen already, set all unseen fields to nil
50+
for _, field := range (*fields)[i+1:] {
51+
(row)[field] = nil
52+
}
53+
}
54+
2855
func transformCSV(in io.Reader, out io.Writer, delimiter rune) error {
2956
r := csv.NewReader(in)
3057
r.Comma = delimiter
@@ -55,13 +82,7 @@ func transformCSV(in io.Reader, out io.Writer, delimiter rune) error {
5582
continue
5683
}
5784

58-
for i, field := range fields {
59-
if i < len(record) {
60-
row[field] = record[i]
61-
} else {
62-
row[field] = nil
63-
}
64-
}
85+
recordToMap(row, &fields, record)
6586

6687
err = w.EncodeRow(row)
6788
if err != nil {
@@ -159,9 +180,8 @@ func transformORC(in *orc.Reader, out io.Writer) error {
159180
for c.Stripes() {
160181
for c.Next() {
161182
r := c.Row()
162-
for i, col := range cols {
163-
row[col] = r[i]
164-
}
183+
184+
recordToMap(row, &cols, r)
165185

166186
err := w.EncodeRow(row)
167187
if err != nil {
@@ -197,13 +217,7 @@ func writeSheet(rows [][]string, w *jsonutil.StreamEncoder) error {
197217
continue
198218
}
199219

200-
for i, name := range header {
201-
var cell any = nil
202-
if i < len(r) {
203-
cell = r[i]
204-
}
205-
row[name] = cell
206-
}
220+
recordToMap(row, &header, r)
207221

208222
err := w.EncodeRow(row)
209223
if err != nil {

runner/file_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,68 @@ import (
1717
"github.com/stretchr/testify/assert"
1818
)
1919

20+
func Test_indexToExcelColumn(t *testing.T) {
21+
tests := []struct {
22+
input int
23+
output string
24+
}{
25+
{26, "Z"},
26+
{51, "AY"},
27+
{52, "AZ"},
28+
{80, "CB"},
29+
{676, "YZ"},
30+
{702, "ZZ"},
31+
{705, "AAC"},
32+
}
33+
34+
for _, test := range tests {
35+
assert.Equal(t, indexToExcelColumn(test.input), test.output)
36+
}
37+
}
38+
39+
func Test_recordToMap(t *testing.T) {
40+
tests := []struct {
41+
fields []string
42+
record []string
43+
expect map[string]any
44+
}{
45+
{
46+
[]string{"a", "b"},
47+
[]string{"1"},
48+
map[string]any{"a": "1", "b": nil},
49+
},
50+
{
51+
[]string{"a", "b"},
52+
[]string{"1", "2", "3"},
53+
map[string]any{"a": "1", "b": "2", "C": "3"},
54+
},
55+
{
56+
[]string{"a", "b"},
57+
[]string{},
58+
map[string]any{"a": nil, "b": nil},
59+
},
60+
{
61+
[]string{},
62+
[]string{
63+
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
64+
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
65+
"21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
66+
},
67+
map[string]any{
68+
"A": "1", "B": "2", "C": "3", "D": "4", "E": "5", "F": "6", "G": "7", "H": "8", "I": "9", "J": "10",
69+
"K": "11", "L": "12", "M": "13", "N": "14", "O": "15", "P": "16", "Q": "17", "R": "18", "S": "19", "T": "20",
70+
"U": "21", "V": "22", "W": "23", "X": "24", "Y": "25", "Z": "26", "AA": "27", "AB": "28", "AC": "29", "AD": "30",
71+
},
72+
},
73+
}
74+
75+
for _, test := range tests {
76+
m := map[string]any{}
77+
recordToMap(m, &test.fields, test.record)
78+
assert.Equal(t, test.expect, m)
79+
}
80+
}
81+
2082
func Test_transformJSONLines(t *testing.T) {
2183
longString := strings.Repeat("Omnis ut ut voluptatem provident eaque necessitatibus quia. Eos veniam qui. ", 1024) // 76kb
2284
tests := []struct {

scripts/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def eval_line(line):
123123
quote_line(line, show=True)
124124
return
125125
if line[0] == 'setenv':
126-
os.environ[line[1]] = line[2]
126+
os.environ[line[1]] = line[2].format(**BUILTIN_VARIABLES, **os.environ)
127127
quote_line(line, show=True)
128128
return
129129
if line[0] == 'setenv_default':

scripts/ci/prepare_go.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
set -ex
44

55
# Set up Go
6-
sudo curl -LO https://go.dev/dl/go1.18.linux-amd64.tar.gz
6+
sudo curl -LO https://go.dev/dl/go1.18.1.linux-amd64.tar.gz
77
sudo rm -rf /usr/local/go
8-
sudo tar -C /usr/local -xzf go1.18.linux-amd64.tar.gz
8+
sudo tar -C /usr/local -xzf go1.18.1.linux-amd64.tar.gz
99
sudo ln -s /usr/local/go/bin/go /usr/local/bin/go
1010
sudo ln -s /usr/local/go/bin/gofmt /usr/local/bin/gofmt

scripts/ci/prepare_linux_integration_test_setup_only.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,16 @@ function retry {
146146
docker ps
147147

148148
# Load influx1 data
149-
retry 3 'curl -XPOST "http://localhost:8087/query?u=test&p=testtest" --data-urlencode "q=CREATE DATABASE test"'
150-
retry 3 "curl -XPOST 'http://localhost:8087/write?db=test&u=test&p=testtest' --data-binary @testdata/influx/noaa-ndbc-data-sample.lp"
149+
retry 10 'curl -XPOST "http://localhost:8087/query?u=test&p=testtest" --data-urlencode "q=CREATE DATABASE test"'
150+
retry 10 "curl -XPOST 'http://localhost:8087/write?db=test&u=test&p=testtest' --data-binary @testdata/influx/noaa-ndbc-data-sample.lp"
151151

152152
# Load influx2 data
153-
retry 3 "curl -XPOST 'http://localhost:8086/api/v2/write?org=test&bucket=test&precision=ns' --header 'Authorization: Token test' --data-binary @testdata/influx/noaa-ndbc-data-sample.lp"
153+
retry 10 "curl -XPOST 'http://localhost:8086/api/v2/write?org=test&bucket=test&precision=ns' --header 'Authorization: Token test' --data-binary @testdata/influx/noaa-ndbc-data-sample.lp"
154154

155155
# Load Elasticsearch data
156-
retry 3 "curl -X PUT http://localhost:9200/test"
156+
retry 10 "curl -X PUT http://localhost:9200/test"
157157
for t in $(ls testdata/documents/*.json); do
158-
retry 3 "curl -X POST -H 'Content-Type: application/json' -d @$t http://localhost:9200/test/_doc"
158+
retry 10 "curl -X POST -H 'Content-Type: application/json' -d @$t http://localhost:9200/test/_doc"
159159
done
160160

161161
# Configure scylla

scripts/ci/prepare_macos.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ brew install cmake jq r julia node@16 npm go-jsonnet
77
brew link --overwrite node@16
88

99
# Install go
10-
sudo curl -LO https://go.dev/dl/go1.18.darwin-amd64.tar.gz
10+
sudo curl -LO https://go.dev/dl/go1.18.1.darwin-amd64.tar.gz
1111
sudo rm -rf /usr/local/go
12-
sudo tar -C /usr/local -xzf go1.18.darwin-amd64.tar.gz
12+
sudo tar -C /usr/local -xzf go1.18.1.darwin-amd64.tar.gz
1313
sudo mv /usr/local/go/bin/go /usr/local/bin/go
1414
sudo mv /usr/local/go/bin/gofmt /usr/local/bin/gofmt
1515

0 commit comments

Comments
 (0)