Skip to content

Commit be0b96b

Browse files
authored
Update Arrow helper tests to test iteration over results (#2786)
1 parent 821e77e commit be0b96b

File tree

1 file changed

+58
-9
lines changed

1 file changed

+58
-9
lines changed

test/unit/helpers/esql.test.ts

+58-9
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,35 @@ test('ES|QL helper', t => {
121121
const result = await client.helpers.esql({ query: 'FROM sample_data' }).toArrowTable()
122122
t.ok(result instanceof arrow.Table)
123123

124+
const testRecords = [
125+
[
126+
['amount', 4.900000095367432],
127+
['date', 1729532586965]
128+
],
129+
[
130+
['amount', 8.199999809265137],
131+
['date', 1729446186965],
132+
],
133+
[
134+
['amount', 15.5],
135+
['date', 1729359786965],
136+
],
137+
[
138+
['amount', 9.899999618530273],
139+
['date', 1729273386965],
140+
],
141+
[
142+
['amount', 13.899999618530273],
143+
['date', 1729186986965],
144+
]
145+
]
146+
147+
let count = 0
124148
const table = [...result]
125-
t.same(table[0], [
126-
["amount", 4.900000095367432],
127-
["date", 1729532586965],
128-
])
149+
for (const record of table) {
150+
t.same(record, testRecords[count])
151+
count++
152+
}
129153
t.end()
130154
})
131155

@@ -182,11 +206,36 @@ test('ES|QL helper', t => {
182206
const result = await client.helpers.esql({ query: 'FROM sample_data' }).toArrowReader()
183207
t.ok(result.isStream())
184208

185-
const recordBatch = result.next().value
186-
t.same(recordBatch.get(0)?.toJSON(), {
187-
amount: 4.900000095367432,
188-
date: 1729532586965,
189-
})
209+
const testRecords = [
210+
{
211+
amount: 4.900000095367432,
212+
date: 1729532586965,
213+
},
214+
{
215+
amount: 8.199999809265137,
216+
date: 1729446186965,
217+
},
218+
{
219+
amount: 15.5,
220+
date: 1729359786965,
221+
},
222+
{
223+
amount: 9.899999618530273,
224+
date: 1729273386965,
225+
},
226+
{
227+
amount: 13.899999618530273,
228+
date: 1729186986965,
229+
},
230+
]
231+
let count = 0
232+
for (const recordBatch of result) {
233+
for (const record of recordBatch) {
234+
t.same(record.toJSON(), testRecords[count])
235+
count++
236+
}
237+
}
238+
190239
t.end()
191240
})
192241

0 commit comments

Comments
 (0)