@@ -27,15 +27,15 @@ const runtimes = new RuntimeList(databasesFromEnvironmentOr(allDatabases));
27
27
28
28
describe . each ( runtimes . runtimeList ) (
29
29
'compound atomic datatypes %s' ,
30
- ( databaseName , runtime ) => {
30
+ ( conName , runtime ) => {
31
31
// mtoy todo dialect flag
32
- const supportsNestedArrays = ! [ 'bigquery' ] . includes ( databaseName ) ;
32
+ const supportsNestedArrays = ! [ 'bigquery' ] . includes ( conName ) ;
33
33
const quote = runtime . dialect . sqlMaybeQuoteIdentifier ;
34
34
function literalNum ( num : Number ) : Expr {
35
35
const literal = num . toString ( ) ;
36
36
return { node : 'numberLiteral' , literal, sql : literal } ;
37
37
}
38
- const empty = `${ databaseName } .sql("SELECT 0 as z")` ;
38
+ const empty = `${ conName } .sql("SELECT 0 as z")` ;
39
39
function arraySelectVal ( ...val : Number [ ] ) : string {
40
40
const literal : ArrayLiteralNode = {
41
41
node : 'arrayLiteral' ,
@@ -78,18 +78,22 @@ describe.each(runtimes.runtimeList)(
78
78
function recordSelectVal ( fromObj : Record < string , number > ) : string {
79
79
return runtime . dialect . sqlLiteralRecord ( recordLiteral ( fromObj ) ) ;
80
80
}
81
+ const canReadCompoungSchema = conName !== 'mysql' && conName !== 'postgres' ;
81
82
82
83
// eslint-disable-next-line @typescript-eslint/no-unused-vars
83
84
const ab = recordSelectVal ( { a : 0 , b : 1 } ) ;
84
85
86
+ const malloySizes = 'sizes is {s is 0, m is 1, l is 2, xl is 3}' ;
85
87
const sizesObj = { s : 0 , m : 1 , l : 2 , xl : 3 } ;
86
88
const sizesSQL = recordSelectVal ( sizesObj ) ;
87
- const sizes = `${ databaseName } .sql("""
88
- SELECT ${ sizesSQL } AS ${ quote ( 'sizes' ) }
89
- """)` ;
89
+ // Keeping the pipeline simpler makes debugging easier, so don't add
90
+ // and extra stage unless you have to
91
+ const sizes = canReadCompoungSchema
92
+ ? `${ conName } .sql(""" SELECT ${ sizesSQL } AS ${ quote ( 'sizes' ) } """)`
93
+ : `${ conName } .sql('SELECT 0 AS O') -> { select: ${ malloySizes } }` ;
90
94
const evensObj = [ 2 , 4 , 6 , 8 ] ;
91
95
const evensSQL = arraySelectVal ( ...evensObj ) ;
92
- const evens = `${ databaseName } .sql("""
96
+ const evens = `${ conName } .sql("""
93
97
SELECT ${ evensSQL } AS ${ quote ( 'evens' ) }
94
98
""")` ;
95
99
@@ -105,7 +109,7 @@ describe.each(runtimes.runtimeList)(
105
109
run: ${ evens } ->{select: nn is evens}
106
110
` ) . malloyResultMatches ( runtime , { nn : evensObj } ) ;
107
111
} ) ;
108
- test ( 'array-un-nest on each' , async ( ) => {
112
+ test ( 'schema read allows array-un-nest on each' , async ( ) => {
109
113
await expect ( `
110
114
run: ${ evens } ->{ select: n is evens.each }
111
115
` ) . malloyResultMatches (
@@ -198,8 +202,16 @@ describe.each(runtimes.runtimeList)(
198
202
[ `${ name } /xl` ] : 3 ,
199
203
} ;
200
204
}
201
- test ( 'record literal dialect function' , async ( ) => {
202
- await expect ( `run: ${ sizes } ` ) . malloyResultMatches ( runtime , rec_eq ( ) ) ;
205
+ test ( 'record literal object' , async ( ) => {
206
+ await expect ( `
207
+ run: ${ conName } .sql("select 0 as o")
208
+ -> { select: ${ malloySizes } }
209
+ ` ) . malloyResultMatches ( runtime , rec_eq ( ) ) ;
210
+ } ) ;
211
+ test ( 'can read schema of record object' , async ( ) => {
212
+ await expect ( `run: ${ conName } .sql("""
213
+ SELECT ${ sizesSQL } AS ${ quote ( 'sizes' ) }
214
+ """)` ) . malloyResultMatches ( runtime , rec_eq ( ) ) ;
203
215
} ) ;
204
216
test ( 'simple record.property access' , async ( ) => {
205
217
await expect ( `
@@ -210,7 +222,7 @@ describe.each(runtimes.runtimeList)(
210
222
} ) ;
211
223
test ( 'nested data looks like a record' , async ( ) => {
212
224
await expect ( `
213
- run: ${ databaseName } .sql('SELECT 1 as ${ quote ( 'o' ) } ') -> {
225
+ run: ${ conName } .sql('SELECT 1 as ${ quote ( 'o' ) } ') -> {
214
226
group_by: row is 'one_row'
215
227
nest: sizes is {
216
228
aggregate:
@@ -237,7 +249,7 @@ describe.each(runtimes.runtimeList)(
237
249
test ( 'select record literal from a source' , async ( ) => {
238
250
await expect ( `
239
251
run: ${ empty } -> {
240
- extend: { dimension: sizes is {s is 0, m is 1, l is 2, xl is 3 } }
252
+ extend: { dimension: ${ malloySizes } }
241
253
select: sizes
242
254
}
243
255
` ) . malloyResultMatches ( runtime , rec_eq ( ) ) ;
@@ -325,7 +337,7 @@ describe.each(runtimes.runtimeList)(
325
337
326
338
test ( 'repeated record from nest' , async ( ) => {
327
339
await expect ( `
328
- run: ${ databaseName } .sql("""
340
+ run: ${ conName } .sql("""
329
341
SELECT
330
342
10 as ${ quote ( 'a' ) } ,
331
343
11 as ${ quote ( 'b' ) }
@@ -336,7 +348,7 @@ describe.each(runtimes.runtimeList)(
336
348
} ) ;
337
349
test ( 'select repeated record from literal dialect functions' , async ( ) => {
338
350
await expect ( `
339
- run: ${ databaseName } .sql(""" ${ selectAB ( 'ab' ) } """)
351
+ run: ${ conName } .sql(""" ${ selectAB ( 'ab' ) } """)
340
352
` ) . malloyResultMatches ( runtime , { ab : ab_eq } ) ;
341
353
} ) ;
342
354
test ( 'repeat record from malloy literal' , async ( ) => {
@@ -347,7 +359,7 @@ describe.each(runtimes.runtimeList)(
347
359
} ) ;
348
360
test ( 'repeated record can be selected and renamed' , async ( ) => {
349
361
const src = `
350
- run: ${ databaseName } .sql("""
362
+ run: ${ conName } .sql("""
351
363
${ selectAB ( 'sqlAB' ) }
352
364
""") -> { select: ab is sqlAB }
353
365
` ;
@@ -362,7 +374,7 @@ describe.each(runtimes.runtimeList)(
362
374
} ) ;
363
375
test ( 'deref repeat record passed down pipeline' , async ( ) => {
364
376
await expect ( `
365
- run: ${ databaseName } .sql("""
377
+ run: ${ conName } .sql("""
366
378
${ selectAB ( 'sqlAB' ) }
367
379
""") -> { select: ab is sqlAB }
368
380
-> { select: ab.a, ab.b }
0 commit comments