Skip to content

Commit 10fb2d7

Browse files
authored
SQLiteWriter only allow flat files (#68)
* SQLiteWriter only allow flat files * Error in shape * Test with and without sqlite writer * Try this out * Update datastation * Fix go install/ * Try failing in ps1
1 parent ba33348 commit 10fb2d7

File tree

8 files changed

+44
-21
lines changed

8 files changed

+44
-21
lines changed

.github/workflows/pull_requests.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ jobs:
2929

3030
- run: ./scripts/ci/prepare_linux.sh
3131
- run: go build -trimpath -buildmode=pie -mod=readonly -modcacherw
32-
- run: ./scripts/test.py
32+
- name: Test defaults
33+
run: ./scripts/test.py
34+
- name: Test without SQLite writer
35+
run: DSQ_NO_SQLITE_WRITER=true ./scripts/test.py
3336

3437
dsq-tests-windows:
3538
runs-on: windows-latest
@@ -46,9 +49,11 @@ jobs:
4649
shell: bash
4750

4851
# Subtle behavioral differences between powershell/cmd and bash. For example nested double quotes must be escaped.
49-
- run: python3 ./scripts/test.py
52+
- name: Test with powershell
53+
run: python3 ./scripts/test.py
5054
shell: powershell
51-
- run: python3 ./scripts/test.py
55+
- name: Test with cmd.exe
56+
run: python3 ./scripts/test.py
5257
shell: cmd
5358

5459
dsq-tests-macos:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ go 1.18
88
require (
99
github.com/chzyer/readline v1.5.0
1010
github.com/google/uuid v1.3.0
11-
github.com/multiprocessio/datastation/runner v0.0.0-20220614050412-e3776fe304bc
11+
github.com/multiprocessio/datastation/runner v0.0.0-20220616090857-d42388371862
1212
github.com/olekukonko/tablewriter v0.0.5
1313
)
1414

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,8 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
445445
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
446446
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
447447
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
448-
github.com/multiprocessio/datastation/runner v0.0.0-20220614050412-e3776fe304bc h1:PZrwLRdb13fjcblFznyzFjTZisKKLl15VTrN5Bp3EFw=
449-
github.com/multiprocessio/datastation/runner v0.0.0-20220614050412-e3776fe304bc/go.mod h1:UCms/xK08DspNqDDZ5XsaIlc39AuREmeELspFYghMGI=
448+
github.com/multiprocessio/datastation/runner v0.0.0-20220616090857-d42388371862 h1:bgzazkNqaktd7lQqOcG6TXG1iz8S1GeGbwEcy0/Zh9k=
449+
github.com/multiprocessio/datastation/runner v0.0.0-20220616090857-d42388371862/go.mod h1:UCms/xK08DspNqDDZ5XsaIlc39AuREmeELspFYghMGI=
450450
github.com/multiprocessio/go-json v0.0.0-20220308002443-61d497dd7b9e h1:NlPl7amllnQyVAkZgjBvFEkKxJSba/R8ZpaTodc7SIQ=
451451
github.com/multiprocessio/go-json v0.0.0-20220308002443-61d497dd7b9e/go.mod h1:huI4M/MrI5px/SgmXYi0a2byKikSLgDrnMQuXOqKtw4=
452452
github.com/multiprocessio/go-openoffice v0.0.0-20220110232726-064f5dda1956 h1:WVofL03Eq+z3LbDOfH5eKzu2U85LFZZngOMBlNaO/H0=

main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ type args struct {
347347

348348
func getArgs() (*args, error) {
349349
args := &args{}
350+
351+
args.noSQLiteWriter = strings.ToLower(os.Getenv("DSQ_NO_SQLITE_WRITER")) == "true"
352+
args.convertNumbers = strings.ToLower(os.Getenv("DSQ_CONVERT_NUMBERS")) == "true"
353+
args.cacheSettings.Enabled = strings.ToLower(os.Getenv("DSQ_CACHE")) == "true"
354+
350355
osArgs := os.Args[1:]
351356
for i := 0; i < len(osArgs); i++ {
352357
arg := osArgs[i]
@@ -597,10 +602,7 @@ func _main() error {
597602
}
598603
mtm := runner.MimeType(mt)
599604
useSQLiteWriter = useSQLiteWriter && (mtm == runner.CSVMimeType ||
600-
mtm == runner.ParquetMimeType ||
601-
mtm == runner.AvroMimeType ||
602605
mtm == runner.TSVMimeType ||
603-
mtm == runner.JSONLinesMimeType ||
604606
mtm == runner.RegexpLinesMimeType)
605607
if !useSQLiteWriter {
606608
break

scripts/ci/prepare_windows.ps1

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1+
Set-StrictMode -Version Latest
2+
$ErrorActionPreference = "Stop"
3+
$PSDefaultParameterValues['*:ErrorAction']='Stop'
4+
function ThrowOnNativeFailure {
5+
if (-not $?)
6+
{
7+
throw 'Native Failure'
8+
}
9+
}
10+
111
iwr -useb 'https://raw.githubusercontent.com/scoopinstaller/install/master/install.ps1' -outfile 'install.ps1'
212
.\install.ps1 -RunAsAdmin
313
Join-Path (Resolve-Path ~).Path "scoop\shims" >> $Env:GITHUB_PATH
4-
scoop install jq zip curl 7zip
14+
scoop install jq
15+
scoop install zip
16+
scoop install curl
17+
scoop install 7zip
18+
scoop install go@1.18.3
519

6-
curl -L -O "https://go.dev/dl/go1.18.windows-amd64.zip"
7-
unzip go1.18.windows-amd64.zip
8-
Join-Path $pwd "go\bin" >> $Env:GITHUB_PATH
20+
# curl -L -O "https://go.dev/dl/go1.18.windows-amd64.zip"
21+
# unzip go1.18.windows-amd64.zip
22+
# Join-Path $pwd "go\bin" >> $Env:GITHUB_PATH
923

1024
7z e testdata/taxi.csv.7z

scripts/test.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def test(name, to_run, want, fail=False, sort=False, winSkip=False, within_secon
3434
if arg == '-f' or arg == '--filter':
3535
if sys.argv[i+1].lower() not in name.lower():
3636
return
37+
if arg == '-fo' or arg == '--filter-out':
38+
if sys.argv[i+1].lower() in name.lower():
39+
return
3740

3841
tests += 1
3942
skipped = True
@@ -297,13 +300,7 @@ def test(name, to_run, want, fail=False, sort=False, winSkip=False, within_secon
297300
cat taxi.csv | ./dsq --cache -s csv 'SELECT passenger_count, COUNT(*), AVG(total_amount) FROM {} GROUP BY passenger_count ORDER BY COUNT(*) DESC'
298301
"""
299302

300-
test("Caching from pipe (second time so import not required sqlitewriter)", to_run, want, sort=True, winSkip=True, within_seconds=5)
301-
302-
to_run = """
303-
cat taxi.csv | ./dsq --no-sqlite-writer --cache -s csv 'SELECT passenger_count, COUNT(*), AVG(total_amount) FROM {} GROUP BY passenger_count ORDER BY COUNT(*) DESC'
304-
"""
305-
306-
test("Caching from pipe (second time so import not required, jsonwriter)", to_run, want, sort=True, winSkip=True, within_seconds=5)
303+
test("Caching from pipe (second time so import not required)", to_run, want, sort=True, winSkip=True, within_seconds=5)
307304

308305
to_run = """
309306
cat testdata/taxi_trunc.csv | ./dsq --cache -s csv 'SELECT passenger_count, COUNT(*), AVG(total_amount) FROM {} GROUP BY passenger_count ORDER BY COUNT(*) DESC'"""
@@ -340,6 +337,10 @@ def test(name, to_run, want, fail=False, sort=False, winSkip=False, within_secon
340337
want = '[{"a": 1, "b": 2, "c": "[1,2]"}]'
341338
test("https://github.com/multiprocessio/dsq/issues/36", to_run, want, sort=True)
342339

340+
to_run = """./dsq ./testdata/regr/67.jsonl 'SELECT COUNT(1) AS count FROM {}'"""
341+
want = '[{"count": 1}]'
342+
test("https://github.com/multiprocessio/dsq/issues/67", to_run, want, sort=True)
343+
343344
# END OF REGRESSION TESTS
344345

345346
print(f"{tests - failures} of {tests} succeeded.")

sqlite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func (sw *SQLiteResultItemWriter) WriteRow(r any, written int) error {
133133
for _, field := range sw.fields {
134134
v := m[field]
135135
switch t := v.(type) {
136-
case map[string]any:
136+
case []any:
137137
bs, err := json.Marshal(t)
138138
if err != nil {
139139
return err

testdata/regr/67.jsonl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"foo":[]}

0 commit comments

Comments
 (0)