File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ from pyarrow import flight
2+ from datafusion import SessionContext
3+
4+ ctx = SessionContext ()
5+
6+ test_data = [
7+ {
8+ "id" : 1 ,
9+ "created_at" : "2024-09-07 10:01:05" ,
10+ "content" : "First entry in first minute" ,
11+ },
12+ {
13+ "id" : 2 ,
14+ "created_at" : "2024-09-07 10:01:45" ,
15+ "content" : "Second entry in first minute" ,
16+ },
17+ {
18+ "id" : 3 ,
19+ "created_at" : "2024-09-07 10:03:10" ,
20+ "content" : "First entry in third minute" ,
21+ },
22+ {
23+ "id" : 4 ,
24+ "created_at" : "2024-09-07 10:03:55" ,
25+ "content" : "Second entry in third minute" ,
26+ },
27+ ]
28+
29+ ctx .from_pylist (test_data , "count_me" )
30+
31+ sql = """ SELECT
32+ DATE_BIN(INTERVAL '1 minute', created_at) AS time_window,
33+ COUNT(*) AS count
34+ FROM
35+ count_me
36+
37+ GROUP BY
38+ time_window
39+ ORDER BY
40+ time_window;"""
41+
42+ df = ctx .sql (sql )
43+ df .to_arrow_table ()
You can’t perform that action at this time.
0 commit comments