Reputation: 61
I have installed astr cli recently and tried to load a csv file to gcp bigquery. I get a error
File "/usr/local/lib/python3.11/site-packages/astro/databases/base.py", line 788, in create_schema_if_applicable
statement = self._create_schema_statement.format(schema)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: Replacement index 1 out of range for positional args tuple
As per the astro documentation it asks for only one argument. But for some reason it throw index 1 out of range error. Attached screenshot reference from the astro documentation.
My code below
from airflow.decorators import dag, task
from datetime import datetime
from airflow.operators.python_operator import PythonOperator
from airflow.models.baseoperator import chain
from airflow.providers.google.cloud.transfers.local_to_gcs import LocalFilesystemToGCSOperator
from airflow.providers.google.cloud.operators.bigquery import \
BigQueryCheckOperator, BigQueryCreateEmptyDatasetOperator, BigQueryCreateEmptyTableOperator, \
BigQueryDeleteDatasetOperator
from astro import sql as aql
from astro.files import File
from astro.sql.table import Table, Metadata
from astro.constants import FileType
@dag(
start_date = datetime(2023,1,1),
schedule = None,
catchup=False,
tags = ['retail'],
)
def retail():
gcs_to_raw = aql.load_file(
task_id='gcs_to_raw',
input_file=File(
'gs://cloudbuild_3445455665/raw/online_Retail.csv',
conn_id='gcp',
filetype=FileType.CSV,
),
output_table=Table(
name='raw_invoices',
conn_id='gcp',
metadata=Metadata(schema="retail",)),
use_native_support=False,
)
The command I use to execute the DAG task
airflow tasks test retail gcs_to_raw 2023-01-01
My error screen shot
Any help is appriciated.
Upvotes: 2
Views: 60
Reputation: 11
I got the same error, but when trying to run a transform, not a load.
I managed to make it work by doing the following:
assume_schema_exists=True
to the function (I think this might work for you)With this I got it running, hope it helps you
Upvotes: 1