@@ -58,4 +58,141 @@ describe('parquetQuery', () => {
58
58
const futureRows = parquetQuery ( { file, orderBy : 'nonexistent' } )
59
59
await expect ( futureRows ) . rejects . toThrow ( 'parquet columns not found: nonexistent' )
60
60
} )
61
+
62
+ it ( 'reads data with filter' , async ( ) => {
63
+ const file = await asyncBufferFromFile ( 'test/files/datapage_v2.snappy.parquet' )
64
+ const rows = await parquetQuery ( { file, filter : { c : 2 } } )
65
+ expect ( toJson ( rows ) ) . toEqual ( [
66
+ { a : 'abc' , b : 1 , c : 2 , d : true , e : [ 1 , 2 , 3 ] } ,
67
+ { a : 'abc' , b : 5 , c : 2 , d : true , e : [ 1 , 2 ] } ,
68
+ ] )
69
+ } )
70
+
71
+ it ( 'reads data with filter and rowStart/rowEnd' , async ( ) => {
72
+ const file = await asyncBufferFromFile ( 'test/files/datapage_v2.snappy.parquet' )
73
+ const rows = await parquetQuery ( { file, filter : { c : 2 } , rowStart : 1 , rowEnd : 5 } )
74
+ expect ( toJson ( rows ) ) . toEqual ( [ { a : 'abc' , b : 5 , c : 2 , d : true , e : [ 1 , 2 ] } ] )
75
+ } )
76
+
77
+ it ( 'reads data with filter and orderBy' , async ( ) => {
78
+ const file = await asyncBufferFromFile ( 'test/files/datapage_v2.snappy.parquet' )
79
+ const rows = await parquetQuery ( { file, filter : { c : 2 } , orderBy : 'b' } )
80
+ expect ( toJson ( rows ) ) . toEqual ( [
81
+ { a : 'abc' , b : 1 , c : 2 , d : true , e : [ 1 , 2 , 3 ] } ,
82
+ { a : 'abc' , b : 5 , c : 2 , d : true , e : [ 1 , 2 ] } ,
83
+ ] )
84
+ } )
85
+
86
+ it ( 'reads data with filter, orderBy, and rowStart/rowEnd' , async ( ) => {
87
+ const file = await asyncBufferFromFile ( 'test/files/datapage_v2.snappy.parquet' )
88
+ const rows = await parquetQuery ( { file, filter : { c : 2 } , orderBy : 'b' , rowStart : 1 , rowEnd : 2 } )
89
+ expect ( toJson ( rows ) ) . toEqual ( [ { a : 'abc' , b : 5 , c : 2 , d : true , e : [ 1 , 2 ] } ] )
90
+ } )
91
+
92
+ it ( 'reads data with $and filter' , async ( ) => {
93
+ const file = await asyncBufferFromFile ( 'test/files/datapage_v2.snappy.parquet' )
94
+ const rows = await parquetQuery ( { file, filter : { $and : [ { c : 2 } , { e : [ 1 , 2 , 3 ] } ] } } )
95
+ expect ( toJson ( rows ) ) . toEqual ( [
96
+ { a : 'abc' , b : 1 , c : 2 , d : true , e : [ 1 , 2 , 3 ] } ,
97
+ ] )
98
+ } )
99
+
100
+ it ( 'reads data with $or filter' , async ( ) => {
101
+ const file = await asyncBufferFromFile ( 'test/files/datapage_v2.snappy.parquet' )
102
+ const rows = await parquetQuery ( { file, filter : { $or : [ { c : 2 } , { d : false } ] } } )
103
+ expect ( toJson ( rows ) ) . toEqual ( [
104
+ { a : 'abc' , b : 1 , c : 2 , d : true , e : [ 1 , 2 , 3 ] } ,
105
+ { a : null , b : 4 , c : 5 , d : false , e : [ 1 , 2 , 3 ] } ,
106
+ { a : 'abc' , b : 5 , c : 2 , d : true , e : [ 1 , 2 ] } ,
107
+ ] )
108
+ } )
109
+
110
+ it ( 'reads data with $not filter' , async ( ) => {
111
+ const file = await asyncBufferFromFile ( 'test/files/datapage_v2.snappy.parquet' )
112
+ const rows = await parquetQuery ( { file, filter : { $not : { c : 2 } } } )
113
+ expect ( toJson ( rows ) ) . toEqual ( [
114
+ { a : 'abc' , b : 2 , c : 3 , d : true } ,
115
+ { a : 'abc' , b : 3 , c : 4 , d : true } ,
116
+ { a : null , b : 4 , c : 5 , d : false , e : [ 1 , 2 , 3 ] } ,
117
+ ] )
118
+ } )
119
+
120
+ it ( 'reads data with $not value filter' , async ( ) => {
121
+ const file = await asyncBufferFromFile ( 'test/files/datapage_v2.snappy.parquet' )
122
+ const rows = await parquetQuery ( { file, filter : { c : { $not : 2 } } } )
123
+ expect ( toJson ( rows ) ) . toEqual ( [
124
+ { a : 'abc' , b : 2 , c : 3 , d : true } ,
125
+ { a : 'abc' , b : 3 , c : 4 , d : true } ,
126
+ { a : null , b : 4 , c : 5 , d : false , e : [ 1 , 2 , 3 ] } ,
127
+ ] )
128
+ } )
129
+
130
+ it ( 'reads data with $gt filter' , async ( ) => {
131
+ const file = await asyncBufferFromFile ( 'test/files/datapage_v2.snappy.parquet' )
132
+ const rows = await parquetQuery ( { file, filter : { b : { $gt : 3 } } } )
133
+ expect ( toJson ( rows ) ) . toEqual ( [
134
+ { a : null , b : 4 , c : 5 , d : false , e : [ 1 , 2 , 3 ] } ,
135
+ { a : 'abc' , b : 5 , c : 2 , d : true , e : [ 1 , 2 ] } ,
136
+ ] )
137
+ } )
138
+
139
+
140
+ it ( 'reads data with $gte filter' , async ( ) => {
141
+ const file = await asyncBufferFromFile ( 'test/files/datapage_v2.snappy.parquet' )
142
+ const rows = await parquetQuery ( { file, filter : { b : { $gte : 3 } } } )
143
+ expect ( toJson ( rows ) ) . toEqual ( [
144
+ { a : 'abc' , b : 3 , c : 4 , d : true } ,
145
+ { a : null , b : 4 , c : 5 , d : false , e : [ 1 , 2 , 3 ] } ,
146
+ { a : 'abc' , b : 5 , c : 2 , d : true , e : [ 1 , 2 ] } ,
147
+ ] )
148
+ } )
149
+
150
+ it ( 'reads data with $lt filter' , async ( ) => {
151
+ const file = await asyncBufferFromFile ( 'test/files/datapage_v2.snappy.parquet' )
152
+ const rows = await parquetQuery ( { file, filter : { b : { $lt : 3 } } } )
153
+ expect ( toJson ( rows ) ) . toEqual ( [
154
+ { a : 'abc' , b : 1 , c : 2 , d : true , e : [ 1 , 2 , 3 ] } ,
155
+ { a : 'abc' , b : 2 , c : 3 , d : true } ,
156
+ ] )
157
+ } )
158
+
159
+ it ( 'reads data with $lte filter' , async ( ) => {
160
+ const file = await asyncBufferFromFile ( 'test/files/datapage_v2.snappy.parquet' )
161
+ const rows = await parquetQuery ( { file, filter : { b : { $lte : 3 } } } )
162
+ expect ( toJson ( rows ) ) . toEqual ( [
163
+ { a : 'abc' , b : 1 , c : 2 , d : true , e : [ 1 , 2 , 3 ] } ,
164
+ { a : 'abc' , b : 2 , c : 3 , d : true } ,
165
+ { a : 'abc' , b : 3 , c : 4 , d : true } ,
166
+ ] )
167
+ } )
168
+
169
+ it ( 'reads data with $ne filter' , async ( ) => {
170
+ const file = await asyncBufferFromFile ( 'test/files/datapage_v2.snappy.parquet' )
171
+ const rows = await parquetQuery ( { file, filter : { b : { $ne : 3 } } } )
172
+ expect ( toJson ( rows ) ) . toEqual ( [
173
+ { a : 'abc' , b : 1 , c : 2 , d : true , e : [ 1 , 2 , 3 ] } ,
174
+ { a : 'abc' , b : 2 , c : 3 , d : true } ,
175
+ { a : null , b : 4 , c : 5 , d : false , e : [ 1 , 2 , 3 ] } ,
176
+ { a : 'abc' , b : 5 , c : 2 , d : true , e : [ 1 , 2 ] } ,
177
+ ] )
178
+ } )
179
+
180
+ it ( 'reads data with $in filter' , async ( ) => {
181
+ const file = await asyncBufferFromFile ( 'test/files/datapage_v2.snappy.parquet' )
182
+ const rows = await parquetQuery ( { file, filter : { b : { $in : [ 2 , 4 ] } } } )
183
+ expect ( toJson ( rows ) ) . toEqual ( [
184
+ { a : 'abc' , b : 2 , c : 3 , d : true } ,
185
+ { a : null , b : 4 , c : 5 , d : false , e : [ 1 , 2 , 3 ] } ,
186
+ ] )
187
+ } )
188
+
189
+ it ( 'reads data with $nin filter' , async ( ) => {
190
+ const file = await asyncBufferFromFile ( 'test/files/datapage_v2.snappy.parquet' )
191
+ const rows = await parquetQuery ( { file, filter : { b : { $nin : [ 2 , 4 ] } } } )
192
+ expect ( toJson ( rows ) ) . toEqual ( [
193
+ { a : 'abc' , b : 1 , c : 2 , d : true , e : [ 1 , 2 , 3 ] } ,
194
+ { a : 'abc' , b : 3 , c : 4 , d : true } ,
195
+ { a : 'abc' , b : 5 , c : 2 , d : true , e : [ 1 , 2 ] } ,
196
+ ] )
197
+ } )
61
198
} )
0 commit comments