Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support parallel encoding - WIP #55

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,18 @@ func evalFileInto(file, mimetype string, out *os.File) error {
return fmt.Errorf("Unknown mimetype for file: %s.\n", file)
}

parallelEncoding := false
stat, err := os.Stat(file)
if err != nil {
return err
}
if stat.Size() > runner.ParallelEncodingMin {
parallelEncoding = true
}

return runner.TransformFile(file, runner.ContentTypeInfo{
Type: mimetype,
}, out)
}, out, parallelEncoding)
}

func getShape(resultFile, panelId string) (*runner.Shape, error) {
Expand Down
32 changes: 16 additions & 16 deletions scripts/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,27 +263,27 @@ def test(name, to_run, want, fail=False, sort=False, winSkip=False, within_secon
os.remove(f)

to_run = """
./dsq --cache taxi.csv "SELECT passenger_count, COUNT(*), AVG(total_amount) FROM {} GROUP BY passenger_count ORDER BY COUNT(*) DESC"
./dsq --cache taxi.csv "SELECT passenger_count, COUNT(*), ROUND(AVG(total_amount),10) FROM {} GROUP BY passenger_count ORDER BY COUNT(*) DESC"
"""
want = """
[{"AVG(total_amount)":17.641883306799908,"passenger_count":"1","COUNT(*)":1533197},
{"AVG(total_amount)":18.097587071145647,"passenger_count":"2","COUNT(*)":286461},
{"AVG(total_amount)":32.23715114825533,"passenger_count":"","COUNT(*)":128020},
{"AVG(total_amount)":17.915395871092315,"passenger_count":"3","COUNT(*)":72852},
{"AVG(total_amount)":17.270924817567234,"passenger_count":"5","COUNT(*)":50291},
{"passenger_count":"0","COUNT(*)":42228,"AVG(total_amount)":17.021401676615067},
{"passenger_count":"6","COUNT(*)":32623,"AVG(total_amount)":17.600296416636713},
{"passenger_count":"4","COUNT(*)":25510,"AVG(total_amount)":18.452774990196012},
{"COUNT(*)":2,"AVG(total_amount)":95.705,"passenger_count":"8"},
{"passenger_count":"7","COUNT(*)":2,"AVG(total_amount)":87.17},
{"passenger_count":"9","COUNT(*)":1,"AVG(total_amount)":113.6}]"""
[{"COUNT(*)": 1533197, "ROUND(AVG(total_amount),10)": 17.6418833068, "passenger_count": "1"},
{"COUNT(*)": 286461, "ROUND(AVG(total_amount),10)": 18.0975870711, "passenger_count": "2"},
{"COUNT(*)": 128020, "ROUND(AVG(total_amount),10)": 32.2371511483, "passenger_count": ""},
{"COUNT(*)": 72852, "ROUND(AVG(total_amount),10)": 17.9153958711, "passenger_count": "3"},
{"COUNT(*)": 50291, "ROUND(AVG(total_amount),10)": 17.2709248176, "passenger_count": "5"},
{"COUNT(*)": 42228, "ROUND(AVG(total_amount),10)": 17.0214016766, "passenger_count": "0"},
{"COUNT(*)": 32623, "ROUND(AVG(total_amount),10)": 17.6002964166, "passenger_count": "6"},
{"COUNT(*)": 25510, "ROUND(AVG(total_amount),10)": 18.4527749902, "passenger_count": "4"},
{"COUNT(*)": 2, "ROUND(AVG(total_amount),10)": 95.705, "passenger_count": "8"},
{"COUNT(*)": 2, "ROUND(AVG(total_amount),10)": 87.17, "passenger_count": "7"},
{"COUNT(*)": 1, "ROUND(AVG(total_amount),10)": 113.6, "passenger_count": "9"}]"""
want_stderr = "Cache invalid, re-import required.\n"

cmd("curl https://s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2021-04.csv -o taxi.csv", doNotReplaceWin=True)
test("Caching from file (first time so import is required)", to_run, want, want_stderr=want_stderr, sort=True)

to_run = """
cat taxi.csv | ./dsq --cache -s csv 'SELECT passenger_count, COUNT(*), AVG(total_amount) FROM {} GROUP BY passenger_count ORDER BY COUNT(*) DESC'
cat taxi.csv | ./dsq --cache -s csv 'SELECT passenger_count, COUNT(*), ROUND(AVG(total_amount),10) FROM {} GROUP BY passenger_count ORDER BY COUNT(*) DESC'
"""

test("Caching from pipe (second time so import not required)", to_run, want, sort=True, winSkip=True, within_seconds=5)
Expand All @@ -300,9 +300,9 @@ def test(name, to_run, want, fail=False, sort=False, winSkip=False, within_secon
f.write(''.join(lines))

to_run = """
cat taxi.csv | ./dsq --cache -s csv 'SELECT passenger_count, COUNT(*), AVG(total_amount) FROM {} GROUP BY passenger_count ORDER BY COUNT(*) DESC'"""
want = """[{"COUNT(*)":9,"AVG(total_amount)":20.571111111111115,"passenger_count":"1"},
{"passenger_count":"0","COUNT(*)":1,"AVG(total_amount)":43.67}]"""
cat taxi.csv | ./dsq --cache -s csv 'SELECT passenger_count, COUNT(*), ROUND(AVG(total_amount),10) FROM {} GROUP BY passenger_count ORDER BY COUNT(*) DESC'"""
want = """[{"COUNT(*)": 9, "ROUND(AVG(total_amount),10)": 20.5711111111, "passenger_count": "1"},
{"COUNT(*)": 1, "ROUND(AVG(total_amount),10)": 43.67, "passenger_count": "0"}]"""
want_stderr = "Cache invalid, re-import required.\n"

test("Re-imports when file changes with cache on", to_run, want, want_stderr=want_stderr, sort=True, winSkip=True)
Expand Down