Skip to content

Equivalent for Airflow templating via Parameters? #3217

Answered by cicdw
bogdanstate asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @bogdanstate - remember that all Prefect tasks represent deferred computation. So when you format your query using a Parameter object (which has not run and produced a value yet), it's expected that you get a weird result. To properly achieve your goal, you need to place all this logic within the Flow so that it executes using runtime information:

source_table = Parameter("source_table")
bigquery = BigQueryTask([...]) # all init kwargs but NOT the query kwarg as it is not known yet


@task
def construct_query(source_table):
    return """
SELECT [columns]
FROM `fh-bigquery.reddit_comments.{source_table}`
""".format(source_table=source_table)


with Flow("BigQuery-template") as flow:
    

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@bogdanstate
Comment options

@cicdw
Comment options

Answer selected by bogdanstate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants