|
1 | | -import { Firebolt } from "../../../src/index"; |
| 1 | +import { Firebolt } from "../../../src"; |
2 | 2 | import BigNumber from "bignumber.js"; |
| 3 | +import stream from "node:stream"; |
3 | 4 |
|
4 | 5 | const connectionParams = { |
5 | 6 | auth: { |
@@ -158,4 +159,153 @@ describe("test type casting on fetch", () => { |
158 | 159 | await connection.execute("DROP TABLE IF EXISTS test_struct_helper"); |
159 | 160 | } |
160 | 161 | }); |
| 162 | + //todo fix nullable types FIR-45354 |
| 163 | + it("select all types", async () => { |
| 164 | + const firebolt = Firebolt({ |
| 165 | + apiEndpoint: process.env.FIREBOLT_API_ENDPOINT as string |
| 166 | + }); |
| 167 | + |
| 168 | + const connection = await firebolt.connect({ |
| 169 | + ...connectionParams, |
| 170 | + engineName: process.env.FIREBOLT_ENGINE_NAME as string |
| 171 | + }); |
| 172 | + const statement = await connection.execute( |
| 173 | + "select 1 as col_int,\n" + |
| 174 | + " null::int as col_int_null,\n" + |
| 175 | + " 30000000000 as col_long,\n" + |
| 176 | + " null::bigint as col_long_null,\n" + |
| 177 | + " 1.23::float4 as col_float,\n" + |
| 178 | + " null::float4 as col_float_null,\n" + |
| 179 | + " 1.23456789012 as col_double,\n" + |
| 180 | + " null::double as col_double_null,\n" + |
| 181 | + " 'text' as col_text,\n" + |
| 182 | + " null::text as col_text_null,\n" + |
| 183 | + " '2021-03-28'::date as col_date,\n" + |
| 184 | + " null::date as col_date_null,\n" + |
| 185 | + " '2019-07-31 01:01:01'::timestamp as col_timestamp,\n" + |
| 186 | + " null::timestamp as col_timestamp_null,\n" + |
| 187 | + " '1111-01-05 17:04:42.123456'::timestamptz as col_timestamptz,\n" + |
| 188 | + " null::timestamptz as col_timestamptz_null,\n" + |
| 189 | + " true as col_boolean,\n" + |
| 190 | + " null::bool as col_boolean_null,\n" + |
| 191 | + " [1,2,3,4] as col_array,\n" + |
| 192 | + // " null::array(int) as col_array_null,\n" + |
| 193 | + " '1231232.123459999990457054844258706536'::decimal(38, 30) as col_decimal,\n" + |
| 194 | + // " null::decimal(38, 30) as col_decimal_null,\n" + |
| 195 | + " 'abc123'::bytea as col_bytea,\n" + |
| 196 | + " null::bytea as col_bytea_null,\n" + |
| 197 | + " 'point(1 2)'::geography as col_geography,\n" + |
| 198 | + " null::geography as col_geography_null," |
| 199 | + ); |
| 200 | + const { data, meta } = await statement.fetchResult(); |
| 201 | + const metaObjects = [ |
| 202 | + { name: "col_int", type: "int" }, |
| 203 | + { name: "col_int_null", type: "int null" }, |
| 204 | + { name: "col_long", type: "long" }, |
| 205 | + { name: "col_long_null", type: "long null" }, |
| 206 | + { name: "col_float", type: "float" }, |
| 207 | + { name: "col_float_null", type: "float null" }, |
| 208 | + { name: "col_double", type: "double" }, |
| 209 | + { name: "col_double_null", type: "double null" }, |
| 210 | + { name: "col_text", type: "text" }, |
| 211 | + { name: "col_text_null", type: "text null" }, |
| 212 | + { name: "col_date", type: "date" }, |
| 213 | + { name: "col_date_null", type: "date null" }, |
| 214 | + { name: "col_timestamp", type: "timestamp" }, |
| 215 | + { name: "col_timestamp_null", type: "timestamp null" }, |
| 216 | + { name: "col_timestamptz", type: "timestamptz" }, |
| 217 | + { name: "col_timestamptz_null", type: "timestamptz null" }, |
| 218 | + { name: "col_boolean", type: "boolean" }, |
| 219 | + { name: "col_boolean_null", type: "boolean null" }, |
| 220 | + { name: "col_array", type: "array(int)" }, |
| 221 | + // { name: "col_array_null", type: "array(int) null" }, |
| 222 | + // { name: "col_decimal", type: "decimal(38, 30)" }, |
| 223 | + { name: "col_decimal", type: "decimal" }, |
| 224 | + // { name: "col_decimal_null", type: "decimal(38, 30) null" }, |
| 225 | + { name: "col_bytea", type: "bytea" }, |
| 226 | + { name: "col_bytea_null", type: "bytea null" }, |
| 227 | + { name: "col_geography", type: "geography" }, |
| 228 | + { name: "col_geography_null", type: "geography null" } |
| 229 | + ]; |
| 230 | + for (let i = 0; i < meta.length; i++) { |
| 231 | + expect(meta[i]).toEqual(metaObjects[i]); |
| 232 | + } |
| 233 | + }); |
| 234 | + //todo fix nullable types FIR-45354 |
| 235 | + it("select all types in streaming", async () => { |
| 236 | + const firebolt = Firebolt({ |
| 237 | + apiEndpoint: process.env.FIREBOLT_API_ENDPOINT as string |
| 238 | + }); |
| 239 | + |
| 240 | + const connection = await firebolt.connect({ |
| 241 | + ...connectionParams, |
| 242 | + engineName: process.env.FIREBOLT_ENGINE_NAME as string |
| 243 | + }); |
| 244 | + const statement = await connection.executeStream( |
| 245 | + "select 1 as col_int,\n" + |
| 246 | + " null::int as col_int_null,\n" + |
| 247 | + " 30000000000 as col_long,\n" + |
| 248 | + " null::bigint as col_long_null,\n" + |
| 249 | + " 1.23::float4 as col_float,\n" + |
| 250 | + " null::float4 as col_float_null,\n" + |
| 251 | + " 1.23456789012 as col_double,\n" + |
| 252 | + " null::double as col_double_null,\n" + |
| 253 | + " 'text' as col_text,\n" + |
| 254 | + " null::text as col_text_null,\n" + |
| 255 | + " '2021-03-28'::date as col_date,\n" + |
| 256 | + " null::date as col_date_null,\n" + |
| 257 | + " '2019-07-31 01:01:01'::timestamp as col_timestamp,\n" + |
| 258 | + " null::timestamp as col_timestamp_null,\n" + |
| 259 | + " '1111-01-05 17:04:42.123456'::timestamptz as col_timestamptz,\n" + |
| 260 | + " null::timestamptz as col_timestamptz_null,\n" + |
| 261 | + " true as col_boolean,\n" + |
| 262 | + " null::bool as col_boolean_null,\n" + |
| 263 | + " [1,2,3,4] as col_array,\n" + |
| 264 | + // " null::array(int) as col_array_null,\n" + |
| 265 | + " '1231232.123459999990457054844258706536'::decimal(38, 30) as col_decimal,\n" + |
| 266 | + // " null::decimal(38, 30) as col_decimal_null,\n" + |
| 267 | + " 'abc123'::bytea as col_bytea,\n" + |
| 268 | + " null::bytea as col_bytea_null,\n" + |
| 269 | + " 'point(1 2)'::geography as col_geography,\n" + |
| 270 | + " null::geography as col_geography_null," |
| 271 | + ); |
| 272 | + const { data } = await statement.streamResult(); |
| 273 | + const [meta] = await stream.once(data, "meta"); |
| 274 | + const metaObjects = [ |
| 275 | + { name: "col_int", type: "int" }, |
| 276 | + // { name: "col_int_null", type: "int null" }, |
| 277 | + { name: "col_int_null", type: "integer null" }, |
| 278 | + { name: "col_long", type: "long" }, |
| 279 | + // { name: "col_long_null", type: "long null" }, |
| 280 | + { name: "col_long_null", type: "bigint null" }, |
| 281 | + { name: "col_float", type: "float" }, |
| 282 | + // { name: "col_float_null", type: "float null" }, |
| 283 | + { name: "col_float_null", type: "real null" }, |
| 284 | + { name: "col_double", type: "double" }, |
| 285 | + // { name: "col_double_null", type: "double null" }, |
| 286 | + { name: "col_double_null", type: "double precision null" }, |
| 287 | + { name: "col_text", type: "text" }, |
| 288 | + { name: "col_text_null", type: "text null" }, |
| 289 | + { name: "col_date", type: "date" }, |
| 290 | + { name: "col_date_null", type: "date null" }, |
| 291 | + { name: "col_timestamp", type: "timestamp" }, |
| 292 | + { name: "col_timestamp_null", type: "timestamp null" }, |
| 293 | + { name: "col_timestamptz", type: "timestamptz" }, |
| 294 | + { name: "col_timestamptz_null", type: "timestamptz null" }, |
| 295 | + { name: "col_boolean", type: "boolean" }, |
| 296 | + { name: "col_boolean_null", type: "boolean null" }, |
| 297 | + { name: "col_array", type: "array(int)" }, |
| 298 | + // { name: "col_array_null", type: "array(int) null" }, |
| 299 | + // { name: "col_decimal", type: "decimal(38, 30)" }, |
| 300 | + { name: "col_decimal", type: "decimal" }, |
| 301 | + // { name: "col_decimal_null", type: "decimal(38, 30) null" }, |
| 302 | + { name: "col_bytea", type: "bytea" }, |
| 303 | + { name: "col_bytea_null", type: "bytea null" }, |
| 304 | + { name: "col_geography", type: "geography" }, |
| 305 | + { name: "col_geography_null", type: "geography null" } |
| 306 | + ]; |
| 307 | + for (let i = 0; i < meta.length; i++) { |
| 308 | + expect(meta[i]).toEqual(metaObjects[i]); |
| 309 | + } |
| 310 | + }); |
161 | 311 | }); |
0 commit comments