-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In my notebooks, I'm tired of loading `jsonl` files into arrays before inputting them into kaskada. So I made a new source to handle `jsonl` files directly.
- Loading branch information
Showing
11 changed files
with
199 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
Source | ||
CsvString | ||
JsonlFile | ||
JsonlString | ||
Pandas | ||
Parquet | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
"""Sources of data for Kaskada queries.""" | ||
from .arrow import CsvString, JsonlString, Pandas, Parquet, PyDict | ||
from .arrow import CsvString, JsonlFile, JsonlString, Pandas, Parquet, PyDict | ||
from .source import Source | ||
|
||
|
||
__all__ = ["Source", "CsvString", "Pandas", "JsonlString", "PyDict", "Parquet"] | ||
__all__ = ["Source", "CsvString", "Pandas", "JsonlFile", "JsonlString", "PyDict", "Parquet"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
python/pytests/golden/jsonl_file_source_test/test_read_jsonl_file.jsonl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{"_time":"1970-01-01T00:26:17.836800000","_key":"karen","id":"cb_001","purchase_time":1577836800000,"customer_id":"karen","vendor_id":"chum_bucket","amount":9,"subsort_id":0} | ||
{"_time":"1970-01-01T00:26:17.836800000","_key":"patrick","id":"kk_001","purchase_time":1577836800000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":3,"subsort_id":1} | ||
{"_time":"1970-01-01T00:26:17.923200000","_key":"karen","id":"cb_002","purchase_time":1577923200000,"customer_id":"karen","vendor_id":"chum_bucket","amount":2,"subsort_id":2} | ||
{"_time":"1970-01-01T00:26:17.923200000","_key":"patrick","id":"kk_002","purchase_time":1577923200000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":5,"subsort_id":3} | ||
{"_time":"1970-01-01T00:26:18.009600000","_key":"karen","id":"cb_003","purchase_time":1578009600000,"customer_id":"karen","vendor_id":"chum_bucket","amount":4,"subsort_id":4} | ||
{"_time":"1970-01-01T00:26:18.009600000","_key":"patrick","id":"kk_003","purchase_time":1578009600000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":12,"subsort_id":5} | ||
{"_time":"1970-01-01T00:26:18.096000000","_key":"patrick","id":"cb_004","purchase_time":1578096000000,"customer_id":"patrick","vendor_id":"chum_bucket","amount":5000,"subsort_id":6} | ||
{"_time":"1970-01-01T00:26:18.096000000","_key":"karen","id":"cb_005","purchase_time":1578096000000,"customer_id":"karen","vendor_id":"chum_bucket","amount":3,"subsort_id":7} | ||
{"_time":"1970-01-01T00:26:18.182400000","_key":"karen","id":"cb_006","purchase_time":1578182400000,"customer_id":"karen","vendor_id":"chum_bucket","amount":5,"subsort_id":8} | ||
{"_time":"1970-01-01T00:26:18.182400000","_key":"patrick","id":"kk_004","purchase_time":1578182400000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":9,"subsort_id":9} |
15 changes: 15 additions & 0 deletions
15
python/pytests/golden/jsonl_file_source_test/test_read_jsonl_file_1.jsonl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{"_time":"1970-01-01T00:26:17.836800000","_key":"karen","id":"cb_001","purchase_time":1577836800000,"customer_id":"karen","vendor_id":"chum_bucket","amount":9,"subsort_id":0} | ||
{"_time":"1970-01-01T00:26:17.836800000","_key":"patrick","id":"kk_001","purchase_time":1577836800000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":3,"subsort_id":1} | ||
{"_time":"1970-01-01T00:26:17.923200000","_key":"karen","id":"cb_002","purchase_time":1577923200000,"customer_id":"karen","vendor_id":"chum_bucket","amount":2,"subsort_id":2} | ||
{"_time":"1970-01-01T00:26:17.923200000","_key":"patrick","id":"kk_002","purchase_time":1577923200000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":5,"subsort_id":3} | ||
{"_time":"1970-01-01T00:26:18.009600000","_key":"karen","id":"cb_003","purchase_time":1578009600000,"customer_id":"karen","vendor_id":"chum_bucket","amount":4,"subsort_id":4} | ||
{"_time":"1970-01-01T00:26:18.009600000","_key":"patrick","id":"kk_003","purchase_time":1578009600000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":12,"subsort_id":5} | ||
{"_time":"1970-01-01T00:26:18.096000000","_key":"patrick","id":"cb_004","purchase_time":1578096000000,"customer_id":"patrick","vendor_id":"chum_bucket","amount":5000,"subsort_id":6} | ||
{"_time":"1970-01-01T00:26:18.096000000","_key":"karen","id":"cb_005","purchase_time":1578096000000,"customer_id":"karen","vendor_id":"chum_bucket","amount":3,"subsort_id":7} | ||
{"_time":"1970-01-01T00:26:18.182400000","_key":"karen","id":"cb_006","purchase_time":1578182400000,"customer_id":"karen","vendor_id":"chum_bucket","amount":5,"subsort_id":8} | ||
{"_time":"1970-01-01T00:26:18.182400000","_key":"patrick","id":"kk_004","purchase_time":1578182400000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":9,"subsort_id":9} | ||
{"_time":"1970-01-01T00:26:18.268800000","_key":"patrick","id":"kk_005","purchase_time":1578268800000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":2,"subsort_id":0} | ||
{"_time":"1970-01-01T00:26:18.268800000","_key":"spongebob","id":"wh_001","purchase_time":1578268800000,"customer_id":"spongebob","vendor_id":"weenie_hut","amount":7,"subsort_id":1} | ||
{"_time":"1970-01-01T00:26:18.355200000","_key":"spongebob","id":"cb_007","purchase_time":1578355200000,"customer_id":"spongebob","vendor_id":"chum_bucket","amount":34,"subsort_id":2} | ||
{"_time":"1970-01-01T00:26:18.441600000","_key":"karen","id":"wh_002","purchase_time":1578441600000,"customer_id":"karen","vendor_id":"weenie_hut","amount":8,"subsort_id":3} | ||
{"_time":"1970-01-01T00:26:18.441600000","_key":"patrick","id":"kk_006","purchase_time":1578441600000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":9,"subsort_id":4} |
10 changes: 10 additions & 0 deletions
10
python/pytests/golden/jsonl_file_source_test/test_read_jsonl_file_with_subsort.jsonl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{"_time":"1970-01-01T00:26:17.836800000","_key":"karen","id":"cb_001","purchase_time":1577836800000,"customer_id":"karen","vendor_id":"chum_bucket","amount":9,"subsort_id":0} | ||
{"_time":"1970-01-01T00:26:17.836800000","_key":"patrick","id":"kk_001","purchase_time":1577836800000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":3,"subsort_id":1} | ||
{"_time":"1970-01-01T00:26:17.923200000","_key":"karen","id":"cb_002","purchase_time":1577923200000,"customer_id":"karen","vendor_id":"chum_bucket","amount":2,"subsort_id":2} | ||
{"_time":"1970-01-01T00:26:17.923200000","_key":"patrick","id":"kk_002","purchase_time":1577923200000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":5,"subsort_id":3} | ||
{"_time":"1970-01-01T00:26:18.009600000","_key":"karen","id":"cb_003","purchase_time":1578009600000,"customer_id":"karen","vendor_id":"chum_bucket","amount":4,"subsort_id":4} | ||
{"_time":"1970-01-01T00:26:18.009600000","_key":"patrick","id":"kk_003","purchase_time":1578009600000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":12,"subsort_id":5} | ||
{"_time":"1970-01-01T00:26:18.096000000","_key":"patrick","id":"cb_004","purchase_time":1578096000000,"customer_id":"patrick","vendor_id":"chum_bucket","amount":5000,"subsort_id":6} | ||
{"_time":"1970-01-01T00:26:18.096000000","_key":"karen","id":"cb_005","purchase_time":1578096000000,"customer_id":"karen","vendor_id":"chum_bucket","amount":3,"subsort_id":7} | ||
{"_time":"1970-01-01T00:26:18.182400000","_key":"karen","id":"cb_006","purchase_time":1578182400000,"customer_id":"karen","vendor_id":"chum_bucket","amount":5,"subsort_id":8} | ||
{"_time":"1970-01-01T00:26:18.182400000","_key":"patrick","id":"kk_004","purchase_time":1578182400000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":9,"subsort_id":9} |
15 changes: 15 additions & 0 deletions
15
python/pytests/golden/jsonl_file_source_test/test_read_jsonl_file_with_subsort_1.jsonl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{"_time":"1970-01-01T00:26:17.836800000","_key":"karen","id":"cb_001","purchase_time":1577836800000,"customer_id":"karen","vendor_id":"chum_bucket","amount":9,"subsort_id":0} | ||
{"_time":"1970-01-01T00:26:17.836800000","_key":"patrick","id":"kk_001","purchase_time":1577836800000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":3,"subsort_id":1} | ||
{"_time":"1970-01-01T00:26:17.923200000","_key":"karen","id":"cb_002","purchase_time":1577923200000,"customer_id":"karen","vendor_id":"chum_bucket","amount":2,"subsort_id":2} | ||
{"_time":"1970-01-01T00:26:17.923200000","_key":"patrick","id":"kk_002","purchase_time":1577923200000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":5,"subsort_id":3} | ||
{"_time":"1970-01-01T00:26:18.009600000","_key":"karen","id":"cb_003","purchase_time":1578009600000,"customer_id":"karen","vendor_id":"chum_bucket","amount":4,"subsort_id":4} | ||
{"_time":"1970-01-01T00:26:18.009600000","_key":"patrick","id":"kk_003","purchase_time":1578009600000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":12,"subsort_id":5} | ||
{"_time":"1970-01-01T00:26:18.096000000","_key":"patrick","id":"cb_004","purchase_time":1578096000000,"customer_id":"patrick","vendor_id":"chum_bucket","amount":5000,"subsort_id":6} | ||
{"_time":"1970-01-01T00:26:18.096000000","_key":"karen","id":"cb_005","purchase_time":1578096000000,"customer_id":"karen","vendor_id":"chum_bucket","amount":3,"subsort_id":7} | ||
{"_time":"1970-01-01T00:26:18.182400000","_key":"karen","id":"cb_006","purchase_time":1578182400000,"customer_id":"karen","vendor_id":"chum_bucket","amount":5,"subsort_id":8} | ||
{"_time":"1970-01-01T00:26:18.182400000","_key":"patrick","id":"kk_004","purchase_time":1578182400000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":9,"subsort_id":9} | ||
{"_time":"1970-01-01T00:26:18.268800000","_key":"patrick","id":"kk_005","purchase_time":1578268800000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":2,"subsort_id":0} | ||
{"_time":"1970-01-01T00:26:18.268800000","_key":"spongebob","id":"wh_001","purchase_time":1578268800000,"customer_id":"spongebob","vendor_id":"weenie_hut","amount":7,"subsort_id":1} | ||
{"_time":"1970-01-01T00:26:18.355200000","_key":"spongebob","id":"cb_007","purchase_time":1578355200000,"customer_id":"spongebob","vendor_id":"chum_bucket","amount":34,"subsort_id":2} | ||
{"_time":"1970-01-01T00:26:18.441600000","_key":"karen","id":"wh_002","purchase_time":1578441600000,"customer_id":"karen","vendor_id":"weenie_hut","amount":8,"subsort_id":3} | ||
{"_time":"1970-01-01T00:26:18.441600000","_key":"patrick","id":"kk_006","purchase_time":1578441600000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":9,"subsort_id":4} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import kaskada as kd | ||
|
||
|
||
async def test_read_jsonl_file(golden) -> None: | ||
source = await kd.sources.JsonlFile.create( | ||
"../testdata/purchases/purchases_part1.jsonl", | ||
time_column="purchase_time", | ||
key_column="customer_id", | ||
) | ||
golden.jsonl(source) | ||
|
||
await source.add_file("../testdata/purchases/purchases_part2.jsonl") | ||
golden.jsonl(source) | ||
|
||
|
||
async def test_read_jsonl_file_with_subsort(golden) -> None: | ||
source = await kd.sources.JsonlFile.create( | ||
"../testdata/purchases/purchases_part1.jsonl", | ||
time_column="purchase_time", | ||
key_column="customer_id", | ||
subsort_column="subsort_id", | ||
) | ||
golden.jsonl(source) | ||
|
||
await source.add_file("../testdata/purchases/purchases_part2.jsonl") | ||
golden.jsonl(source) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{"id":"cb_001","purchase_time":1577836800000,"customer_id":"karen","vendor_id":"chum_bucket","amount":9,"subsort_id":0} | ||
{"id":"kk_001","purchase_time":1577836800000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":3,"subsort_id":1} | ||
{"id":"cb_002","purchase_time":1577923200000,"customer_id":"karen","vendor_id":"chum_bucket","amount":2,"subsort_id":2} | ||
{"id":"kk_002","purchase_time":1577923200000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":5,"subsort_id":3} | ||
{"id":"cb_003","purchase_time":1578009600000,"customer_id":"karen","vendor_id":"chum_bucket","amount":4,"subsort_id":4} | ||
{"id":"kk_003","purchase_time":1578009600000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":12,"subsort_id":5} | ||
{"id":"cb_004","purchase_time":1578096000000,"customer_id":"patrick","vendor_id":"chum_bucket","amount":5000,"subsort_id":6} | ||
{"id":"cb_005","purchase_time":1578096000000,"customer_id":"karen","vendor_id":"chum_bucket","amount":3,"subsort_id":7} | ||
{"id":"cb_006","purchase_time":1578182400000,"customer_id":"karen","vendor_id":"chum_bucket","amount":5,"subsort_id":8} | ||
{"id":"kk_004","purchase_time":1578182400000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":9,"subsort_id":9} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{"id":"kk_005","purchase_time":1578268800000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":2,"subsort_id":0} | ||
{"id":"wh_001","purchase_time":1578268800000,"customer_id":"spongebob","vendor_id":"weenie_hut","amount":7,"subsort_id":1} | ||
{"id":"cb_007","purchase_time":1578355200000,"customer_id":"spongebob","vendor_id":"chum_bucket","amount":34,"subsort_id":2} | ||
{"id":"wh_002","purchase_time":1578441600000,"customer_id":"karen","vendor_id":"weenie_hut","amount":8,"subsort_id":3} | ||
{"id":"kk_006","purchase_time":1578441600000,"customer_id":"patrick","vendor_id":"krusty_krab","amount":9,"subsort_id":4} |