@@ -74,6 +74,7 @@ describe("streams", () => {
7474 resolve ( null ) ;
7575 } ) ;
7676 } ) ;
77+ expect ( sum ) . toEqual ( 250000 ) ;
7778 } ) ;
7879 it ( "stream transformers" , async ( ) => {
7980 class SerializeRowStream extends stream . Transform {
@@ -153,4 +154,86 @@ describe("streams", () => {
153154 " ^"
154155 ) ;
155156 } ) ;
157+ it ( "check data types" , async ( ) => {
158+ const seriesNum = 2 ;
159+ const generateLargeResultQuery = ( rows : number ) => `
160+ SELECT
161+ i as id,
162+ 'user_' || i::string as username,
163+ 'email_' || i::string || '@example.com' as email,
164+ CASE WHEN i % 2 = 0 THEN 'active' ELSE 'inactive' END as status,
165+ CAST('100000000000000000' as BIGINT) as big_number,
166+ '2024-01-01'::date + (i % 365) as created_date,
167+ RANDOM() * 1000 as score,
168+ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' as description
169+ FROM generate_series(1, ${ rows } ) as i
170+ ` ;
171+
172+ const firebolt = Firebolt ( {
173+ apiEndpoint : process . env . FIREBOLT_API_ENDPOINT as string
174+ } ) ;
175+
176+ const connection = await firebolt . connect ( connectionParams ) ;
177+
178+ const statement = await connection . executeStream (
179+ generateLargeResultQuery ( seriesNum ) ,
180+ {
181+ response : {
182+ normalizeData : true
183+ }
184+ }
185+ ) ;
186+
187+ const { data } = await statement . streamResult ( ) ;
188+ let rowCount = 0 ;
189+ // const meta = await stream.once(data, "meta");
190+ data . on ( "meta" , meta => {
191+ console . log ( "Meta:" , meta ) ;
192+ } ) ;
193+ // console.log("Meta:", meta);
194+ // expect(meta).toEqual([
195+ // { name: "id", type: "int" },
196+ // { name: "username", type: "text" },
197+ // { name: "email", type: "text" },
198+ // { name: "status", type: "text" },
199+ // { name: "big_number", type: "bigint" },
200+ // { name: "created_date", type: "date" },
201+ // { name: "score", type: "double precision" },
202+ // { name: "description", type: "text" }
203+ // ]);
204+
205+ data . on ( "data" , row => {
206+ rowCount ++ ;
207+ // Verify first row data types
208+ if ( rowCount === 1 ) {
209+ expect ( typeof row [ 0 ] ) . toBe ( "number" ) ; // id
210+ expect ( typeof row [ 1 ] ) . toBe ( "string" ) ; // username
211+ expect ( typeof row [ 2 ] ) . toBe ( "string" ) ; // email
212+ expect ( typeof row [ 3 ] ) . toBe ( "string" ) ; // status
213+ expect ( typeof row [ 4 ] ) . toBe ( "number" ) ; // big_number (should be handled as number or BigNumber)
214+ expect ( row [ 5 ] ) . toBeInstanceOf ( Date ) ; // created_date
215+ expect ( typeof row [ 6 ] ) . toBe ( "number" ) ; // score
216+ expect ( typeof row [ 7 ] ) . toBe ( "string" ) ; // description
217+
218+ // Verify actual values for first row
219+ expect ( row [ 0 ] ) . toBe ( 1 ) ;
220+ expect ( row [ 1 ] ) . toBe ( "user_1" ) ;
221+ expect ( row [ 2 ] ) . toBe ( "[email protected] " ) ; 222+ expect ( row [ 3 ] ) . toBe ( "inactive" ) ; // i=1, 1%2=1, so 'inactive'
223+ expect ( row [ 4 ] ) . toBe ( 100000000000000000 ) ;
224+ expect ( row [ 5 ] ) . toEqual ( new Date ( "2024-01-02" ) ) ; // 2024-01-01 + 1 day
225+ expect ( typeof row [ 6 ] ) . toBe ( "number" ) ;
226+ expect ( row [ 7 ] ) . toBe (
227+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
228+ ) ;
229+ }
230+ } ) ;
231+
232+ await new Promise ( resolve => {
233+ data . on ( "end" , ( ) => {
234+ expect ( rowCount ) . toEqual ( seriesNum ) ;
235+ resolve ( null ) ;
236+ } ) ;
237+ } ) ;
238+ } ) ;
156239} ) ;
0 commit comments