-
Notifications
You must be signed in to change notification settings - Fork 39
/
test_transform.py
721 lines (611 loc) · 23.3 KB
/
test_transform.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
import os
import pathlib
import tempfile
import pandas as pd
import pytest
from airflow.decorators import task
from astro import sql as aql
from astro.airflow.datasets import DATASET_SUPPORT
from astro.constants import Database
from astro.databases.databricks.load_options import DeltaLoadOptions
from astro.files import File
from astro.table import Metadata, Table
from tests.sql.operators import utils as test_utils
cwd = pathlib.Path(__file__).parent
@pytest.mark.integration
@pytest.mark.parametrize(
"database_table_fixture",
[
{"database": Database.SNOWFLAKE},
{"database": Database.BIGQUERY},
{"database": Database.POSTGRES},
{"database": Database.SQLITE},
{"database": Database.REDSHIFT},
{"database": Database.MSSQL},
{"database": Database.MYSQL},
{"database": Database.DUCKDB},
],
indirect=True,
ids=["snowflake", "bigquery", "postgresql", "sqlite", "redshift", "mssql", "mysql", "duckdb"],
)
def test_dataframe_transform(database_table_fixture, sample_dag):
_, test_table = database_table_fixture
@aql.dataframe
def get_dataframe():
return pd.DataFrame({"numbers": [1, 2, 3], "colors": ["red", "white", "blue"]})
@aql.transform
def sample_pg(input_table: Table):
return "SELECT * FROM {{input_table}}"
@aql.dataframe
def validate_dataframe(df: pd.DataFrame):
df.columns = df.columns.str.lower()
df = df.sort_values(by=df.columns.tolist()).reset_index(drop=True)
assert df.equals(pd.DataFrame({"numbers": [1, 2, 3], "colors": ["red", "white", "blue"]}))
with sample_dag:
my_df = get_dataframe(output_table=test_table)
pg_df = sample_pg(my_df)
validate_dataframe(pg_df)
aql.cleanup()
test_utils.run_dag(sample_dag)
@pytest.mark.integration
@pytest.mark.parametrize(
"database_table_fixture",
[
{"database": Database.SNOWFLAKE},
{"database": Database.BIGQUERY},
{"database": Database.POSTGRES},
{"database": Database.SQLITE},
{"database": Database.REDSHIFT},
{"database": Database.DELTA},
{"database": Database.DUCKDB},
{"database": Database.MYSQL},
],
indirect=True,
ids=["snowflake", "bigquery", "postgresql", "sqlite", "redshift", "delta", "duckdb", "mysql"],
)
def test_transform(database_table_fixture, sample_dag):
_, test_table = database_table_fixture
@aql.transform
def sample_function(input_table: Table):
return "SELECT * FROM {{input_table}} LIMIT 10"
@aql.dataframe
def validate_table(df: pd.DataFrame):
assert len(df) == 10
with sample_dag:
homes_file = aql.load_file(
input_file=File(path=str(cwd) + "/../../../data/homes.csv"),
output_table=test_table,
load_options=[DeltaLoadOptions.get_default_delta_options()],
)
first_model = sample_function(
input_table=homes_file,
)
inherit_model = sample_function(
input_table=first_model,
)
validate_table(inherit_model)
aql.cleanup()
test_utils.run_dag(sample_dag)
@pytest.mark.integration
@pytest.mark.parametrize(
"database_table_fixture",
[
{"database": Database.MSSQL},
],
indirect=True,
ids=["mssql"],
)
def test_transform_mssql(database_table_fixture, sample_dag):
_, test_table = database_table_fixture
@aql.transform
def sample_function(input_table: Table):
return "SELECT TOP 10 * FROM {{input_table}}"
@aql.dataframe
def validate_table(df: pd.DataFrame):
assert len(df) == 10
with sample_dag:
homes_file = aql.load_file(
input_file=File(path=str(cwd) + "/../../../data/homes.csv"),
output_table=test_table,
)
first_model = sample_function(
input_table=homes_file,
)
inherit_model = sample_function(
input_table=first_model,
)
validate_table(inherit_model)
test_utils.run_dag(sample_dag)
@pytest.mark.parametrize(
"database_table_fixture",
[
{"database": Database.SNOWFLAKE},
{"database": Database.BIGQUERY},
{"database": Database.POSTGRES},
{"database": Database.SQLITE},
{"database": Database.REDSHIFT},
{"database": Database.DELTA},
{"database": Database.DUCKDB},
{"database": Database.MYSQL},
],
indirect=True,
ids=["snowflake", "bigquery", "postgresql", "sqlite", "redshift", "delta", "duckdb", "mysql"],
)
def test_raw_sql(database_table_fixture, sample_dag):
db, test_table = database_table_fixture
@aql.run_raw_sql
def raw_sql_query(my_input_table: Table, created_table: Table, num_rows: int):
return "SELECT * FROM {{my_input_table}} LIMIT {{num_rows}}"
@task
def validate_raw_sql(cur: pd.DataFrame):
from sqlalchemy.engine.row import LegacyRow
if db.sql_type == "delta":
for c in cur:
assert isinstance(c, list)
else:
for c in cur:
assert isinstance(c, LegacyRow)
with sample_dag:
homes_file = aql.load_file(
input_file=File(path=str(cwd) + "/../../../data/homes.csv"),
output_table=test_table,
load_options=[DeltaLoadOptions.get_default_delta_options()],
)
raw_sql_result = raw_sql_query(
my_input_table=homes_file,
created_table=test_table,
num_rows=5,
handler=lambda cur: cur.fetchall(),
)
validate_raw_sql(raw_sql_result)
test_utils.run_dag(sample_dag)
@pytest.mark.parametrize(
"database_table_fixture",
[
{"database": Database.MSSQL},
],
indirect=True,
ids=["mssql"],
)
def test_raw_sql_for_mssql(database_table_fixture, sample_dag):
db, test_table = database_table_fixture
@aql.run_raw_sql
def raw_sql_query(my_input_table: Table, created_table: Table, num_rows: int):
return "SELECT TOP {{num_rows}} * FROM {{my_input_table}}"
@task
def validate_raw_sql(cur: pd.DataFrame):
from sqlalchemy.engine.row import LegacyRow
if db.sql_type == "delta":
for c in cur:
assert isinstance(c, list)
else:
for c in cur:
assert isinstance(c, LegacyRow)
with sample_dag:
homes_file = aql.load_file(
input_file=File(path=str(cwd) + "/../../../data/homes.csv"),
output_table=test_table,
)
raw_sql_result = raw_sql_query(
my_input_table=homes_file,
created_table=test_table,
num_rows=5,
handler=lambda cur: cur.fetchall(),
)
validate_raw_sql(raw_sql_result)
test_utils.run_dag(sample_dag)
@pytest.mark.integration
@pytest.mark.parametrize(
"database_table_fixture",
[
{
"database": Database.SQLITE,
"file": File(
"https://raw.githubusercontent.com/astronomer/astro-sdk/main/tests/data/imdb_v2.csv"
),
"table": Table(name="imdb", conn_id="sqlite_default"),
},
{
"database": Database.DUCKDB,
"file": File(
"https://raw.githubusercontent.com/astronomer/astro-sdk/main/tests/data/imdb_v2.csv"
),
"table": Table(name="imdb", conn_id="duckdb_conn"),
},
],
indirect=True,
ids=["sqlite", "duckdb"],
)
def test_transform_with_templated_table_name(database_table_fixture, sample_dag):
"""Test table creation via select statement when the output table uses an Airflow template in its name"""
database, imdb_table = database_table_fixture
@aql.transform
def top_five_animations(input_table: Table) -> str:
return """
SELECT title, rating
FROM {{ input_table }}
WHERE genre1=='Animation'
ORDER BY rating desc
LIMIT 5;
"""
with sample_dag:
target_table = Table(name="test_is_{{ ds_nodash }}", conn_id=imdb_table.conn_id)
top_five_animations(input_table=imdb_table, output_table=target_table)
test_utils.run_dag(sample_dag)
expected_target_table = target_table.create_similar_table()
expected_target_table.name = "test_is_True"
database.drop_table(expected_target_table)
assert not database.table_exists(expected_target_table)
@pytest.mark.integration
@pytest.mark.parametrize(
"database_table_fixture",
[
{
"database": Database.SQLITE,
"file": File(
"https://raw.githubusercontent.com/astronomer/astro-sdk/main/tests/data/imdb_v2.csv"
),
"table": Table(conn_id="sqlite_default"),
},
],
indirect=True,
ids=["sqlite"],
)
def test_transform_astro_data_team(database_table_fixture, sample_dag):
"""Test case that represents a usage from the Astronomer Data team"""
database, imdb_table = database_table_fixture
def query(sql: str) -> Table:
"""
Takes sql or sql file path and returns result as a Table.
"""
return sql
sample_query = f"""
SELECT title, rating
FROM {imdb_table.name}
WHERE genre1=='Animation'
ORDER BY rating desc
LIMIT 5;
"""
with tempfile.NamedTemporaryFile(mode="w", suffix=".sql") as temp_file:
temp_file.write(sample_query)
temp_file.flush()
with sample_dag:
# table_from_inline_sql = aql.transform(
# conn_id="sqlite_default",
# task_id="table_from_inline_sql",
# )(query)(sql=sample_query)
aql.transform(
conn_id="sqlite_default",
task_id="table_from_sql_file",
)(
query
)(sql=temp_file.name)
test_utils.run_dag(sample_dag)
@pytest.mark.integration
@pytest.mark.parametrize(
"database_table_fixture",
[
{
"database": Database.MYSQL,
"file": File(
"https://raw.githubusercontent.com/astronomer/astro-sdk/main/tests/data/imdb_v2.csv"
),
"table": Table(name="imdb", conn_id="mysql_conn"),
},
],
indirect=True,
ids=["mysql"],
)
def test_transform_with_templated_table_for_mysql(database_table_fixture, sample_dag):
"""Test table creation via select statement when the output table uses an Airflow template in its name"""
database, imdb_table = database_table_fixture
@aql.transform
def top_five_animations(input_table: Table) -> str:
return """
SELECT title, rating
FROM {{ input_table }}
WHERE genre1='Animation'
ORDER BY rating desc
LIMIT 5;
"""
with sample_dag:
target_table = Table(name="test_is_{{ ds_nodash }}", conn_id=imdb_table.conn_id)
top_five_animations(input_table=imdb_table, output_table=target_table)
test_utils.run_dag(sample_dag)
expected_target_table = target_table.create_similar_table()
expected_target_table.name = "test_is_True"
database.drop_table(expected_target_table)
assert not database.table_exists(expected_target_table)
@pytest.mark.integration
@pytest.mark.parametrize(
"database_table_fixture",
[
{
"database": Database.MSSQL,
"file": File(
"https://raw.githubusercontent.com/astronomer/astro-sdk/main/tests/data/imdb_v2.csv"
),
"table": Table(name="imdb", conn_id="mssql_conn"),
}
],
indirect=True,
ids=["mssql"],
)
def test_transform_with_templated_table_name_for_mssql(database_table_fixture, sample_dag):
"""Test table creation via select statement when the output table uses an Airflow template in its name"""
database, imdb_table = database_table_fixture
@aql.transform
def top_five_animations(input_table: Table) -> str:
# Don't use quote at the end of the query here due to below error
# sqlalchemy.exc.ProgrammingError: (pymssql._pymssql.ProgrammingError) (102, b"Incorrect syntax near ';'
# use TOP as LIMIT does not work in mssql
return """
SELECT TOP 5 title, rating
FROM {{ input_table }}
WHERE genre1='Animation'
ORDER BY rating desc
"""
with sample_dag:
target_table = Table(name="test_is_{{ ds_nodash }}", conn_id="mssql_conn")
top_five_animations(input_table=imdb_table, output_table=target_table)
test_utils.run_dag(sample_dag)
expected_target_table = target_table.create_similar_table()
expected_target_table.name = "test_is_True"
database.drop_table(expected_target_table)
assert not database.table_exists(expected_target_table)
@pytest.mark.integration
@pytest.mark.parametrize(
"database_table_fixture",
[
{
"database": Database.SQLITE,
"file": File(
"https://raw.githubusercontent.com/astronomer/astro-sdk/main/tests/data/imdb_v2.csv"
),
"table": Table(name="imdb", conn_id="sqlite_default"),
},
{
"database": Database.DUCKDB,
"file": File(
"https://raw.githubusercontent.com/astronomer/astro-sdk/main/tests/data/imdb_v2.csv"
),
"table": Table(name="imdb", conn_id="duckdb_conn"),
},
],
indirect=True,
ids=["sqlite", "duckdb"],
)
def test_transform_with_file(database_table_fixture, sample_dag):
"""Test table creation via select statement in a SQL file"""
database, imdb_table = database_table_fixture
@aql.dataframe
def validate(df: pd.DataFrame):
assert df.columns.tolist() == ["title", "rating"]
with sample_dag:
target_table = Table(name="test_is_{{ ds_nodash }}", conn_id=imdb_table.conn_id)
table_from_query = aql.transform_file(
file_path="tests_integration/sql/operators/transform/test.sql",
parameters={"input_table": imdb_table},
op_kwargs={"output_table": target_table},
)
validate(table_from_query)
test_utils.run_dag(sample_dag)
expected_target_table = target_table.create_similar_table()
expected_target_table.name = "test_is_True"
database.drop_table(expected_target_table)
assert not database.table_exists(expected_target_table)
@pytest.mark.integration
@pytest.mark.parametrize(
"database_table_fixture",
[
{
"database": Database.MSSQL,
"file": File(
"https://raw.githubusercontent.com/astronomer/astro-sdk/main/tests/data/imdb_v2.csv"
),
"table": Table(name="imdb", conn_id="mssql_conn"),
},
],
indirect=True,
ids=["mssql"],
)
def test_transform_with_file_for_mssql(database_table_fixture, sample_dag):
"""Test table creation via select statement in a SQL file"""
database, imdb_table = database_table_fixture
@aql.dataframe
def validate(df: pd.DataFrame):
assert df.columns.tolist() == ["title", "rating"]
with sample_dag:
target_table = Table(name="test_is_{{ ds_nodash }}", conn_id="mssql_conn")
table_from_query = aql.transform_file(
file_path="tests_integration/sql/operators/transform/test_mssql.sql",
parameters={"input_table": imdb_table},
op_kwargs={"output_table": target_table},
)
validate(table_from_query)
test_utils.run_dag(sample_dag)
expected_target_table = target_table.create_similar_table()
expected_target_table.name = "test_is_True"
database.drop_table(expected_target_table)
assert not database.table_exists(expected_target_table)
@pytest.mark.integration
@pytest.mark.parametrize(
"database_table_fixture",
[
{
"database": Database.MYSQL,
"file": File(
"https://raw.githubusercontent.com/astronomer/astro-sdk/main/tests/data/imdb_v2.csv"
),
"table": Table(name="imdb", conn_id="mysql_conn"),
},
],
indirect=True,
ids=["mysql"],
)
def test_transform_with_file_for_mysql(database_table_fixture, sample_dag):
"""Test table creation via select statement in a SQL file"""
database, imdb_table = database_table_fixture
@aql.dataframe
def validate(df: pd.DataFrame):
assert df.columns.tolist() == ["title", "rating"]
with sample_dag:
target_table = Table(name="test_is_{{ ds_nodash }}", conn_id="mysql_conn")
table_from_query = aql.transform_file(
file_path="tests_integration/sql/operators/transform/test_mysql.sql",
parameters={"input_table": imdb_table},
op_kwargs={"output_table": target_table},
)
validate(table_from_query)
test_utils.run_dag(sample_dag)
expected_target_table = target_table.create_similar_table()
expected_target_table.name = "test_is_True"
database.drop_table(expected_target_table)
assert not database.table_exists(expected_target_table)
def test_transform_using_table_metadata(sample_dag):
"""
Test that load file and transform when database and schema is available in table metadata instead of conn
"""
with sample_dag:
test_table = Table(
conn_id="snowflake_conn_1",
metadata=Metadata(
database=os.environ["SNOWFLAKE_DATABASE"],
schema=os.environ["SNOWFLAKE_SCHEMA"],
),
)
homes_file = aql.load_file(
input_file=File(path=str(cwd) + "/../../../data/homes.csv"),
output_table=test_table,
)
@aql.transform
def select(input_table: Table):
return "SELECT * FROM {{input_table}} LIMIT 4;"
select(input_table=homes_file, output_table=Table(conn_id="snowflake_conn_1"))
aql.cleanup()
test_utils.run_dag(sample_dag)
@pytest.mark.integration
def test_transform_using_table_metadata_mssql(sample_dag):
"""
Test that load file and transform work when database and schema is available in table metadata instead of conn
"""
with sample_dag:
test_table = Table(
conn_id="mssql_conn",
metadata=Metadata(
database=os.environ["MSSQL_DB"],
schema="dbo",
),
)
homes_file = aql.load_file(
input_file=File(path=str(cwd) + "/../../../data/homes.csv"),
output_table=test_table,
)
@aql.transform
def select(input_table: Table):
return "SELECT TOP 4 * FROM {{input_table}}"
select(input_table=homes_file, output_table=Table(conn_id="mssql_conn"))
aql.cleanup()
test_utils.run_dag(sample_dag)
@pytest.mark.integration
def test_transform_using_table_metadata_mysql(sample_dag):
"""
Test that load file and transform work when schema is available in table metadata instead of conn
Note that schema is synonymous with database in mysql
"""
with sample_dag:
test_table = Table(
conn_id="mysql_conn",
metadata=Metadata(
schema=os.environ["MYSQL_DB"],
),
)
homes_file = aql.load_file(
input_file=File(path=str(cwd) + "/../../../data/homes.csv"),
output_table=test_table,
)
@aql.transform
def select(input_table: Table):
return "SELECT * FROM {{input_table}} LIMIT 4"
select(input_table=homes_file, output_table=Table(conn_id="mysql_conn"))
aql.cleanup()
test_utils.run_dag(sample_dag)
@pytest.mark.integration
def test_cross_db_transform_raise_exception(sample_dag):
"""Test the transform operator raise exception if input and output is not for same database source"""
@aql.transform
def top_five_animations(input_table: Table) -> str:
return """
SELECT title, rating
FROM {{ input_table }}
WHERE genre1=='Animation'
ORDER BY rating desc
LIMIT 5;
"""
with sample_dag:
input_table = Table(conn_id="snowflake_conn", name="test1", metadata=Metadata(schema="test"))
output_table = Table(conn_id="bigquery", name="test2", metadata=Metadata(schema="test"))
top_five_animations(input_table=input_table, output_table=output_table)
with pytest.raises(ValueError) as exec_info:
test_utils.run_dag(sample_dag)
assert exec_info.value.args[0] == "source and target table must belong to the same datasource"
@pytest.mark.integration
def test_transform_region(sample_dag):
"""Test the transform operator raise exception if input and output is not for same database source"""
@aql.transform
def select_all(input_table: Table) -> str:
return """
SELECT *
FROM {{ input_table }}
"""
with sample_dag:
input_table = Table(
conn_id="google_cloud_default", name="do_not_delete", metadata=Metadata(schema="testing_region")
)
select_all(input_table=input_table)
aql.cleanup()
test_utils.run_dag(sample_dag)
@pytest.mark.integration
@pytest.mark.skipif(not DATASET_SUPPORT, reason="Inlets/Outlets will only be added for Airflow >= 2.4")
def test_inlets_outlets_supported_ds():
"""Test Datasets are set as inlets and outlets"""
imdb_table = (Table(name="imdb", conn_id="sqlite_default"),)
output_table = Table(name="test_name")
@aql.transform
def top_five_animations(input_table: Table) -> str:
return "SELECT title, rating FROM {{ input_table }} LIMIT 5;"
task = top_five_animations(input_table=imdb_table, output_table=output_table)
assert task.operator.outlets == [output_table]
@pytest.mark.integration
@pytest.mark.skipif(not DATASET_SUPPORT, reason="Inlets/Outlets will only be added for Airflow >= 2.4")
def test_inlets_outlets_supported_ds_mssql():
"""Test Datasets are set as inlets and outlets"""
imdb_table = (Table(name="imdb", conn_id="mssql_conn"),)
output_table = Table(name="test_name")
@aql.transform
def top_five_animations(input_table: Table) -> str:
return "SELECT TOP 5 title, rating FROM {{ input_table }}"
task = top_five_animations(input_table=imdb_table, output_table=output_table)
assert task.operator.outlets == [output_table]
@pytest.mark.integration
@pytest.mark.skipif(DATASET_SUPPORT, reason="Inlets/Outlets will only be added for Airflow >= 2.4")
def test_inlets_outlets_non_supported_ds():
"""Test inlets and outlets are not set if Datasets are not supported"""
imdb_table = (Table(name="imdb", conn_id="sqlite_default"),)
output_table = Table(name="test_name")
@aql.transform
def top_five_animations(input_table: Table) -> str:
return "SELECT title, rating FROM {{ input_table }} LIMIT 5;"
task = top_five_animations(input_table=imdb_table, output_table=output_table)
assert task.operator.outlets == []
@pytest.mark.integration
@pytest.mark.skipif(DATASET_SUPPORT, reason="Inlets/Outlets will only be added for Airflow >= 2.4")
def test_inlets_outlets_non_supported_ds_mssql():
"""Test inlets and outlets are not set if Datasets are not supported"""
imdb_table = (Table(name="imdb", conn_id="mssql_conn"),)
output_table = Table(name="test_name")
@aql.transform
def top_five_animations(input_table: Table) -> str:
return "SELECT TOP 5 title, rating FROM {{ input_table }}"
task = top_five_animations(input_table=imdb_table, output_table=output_table)
assert task.operator.outlets == []