Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tatiana committed Mar 31, 2023
1 parent fd4d4de commit ceec0ab
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions python-sdk/src/astro/sql/operators/base_decorator.py
Expand Up @@ -214,6 +214,7 @@ def read_sql_from_function(self) -> None:
if self.sql.endswith(".sql"):
with open(self.sql) as file:
self.sql = file.read().replace("\n", " ")
self.op_kwargs.pop("sql", None)

def move_function_params_into_sql_params(self, context: dict) -> None:
"""
Expand Down
@@ -1,5 +1,6 @@
import os
import pathlib
import tempfile

import pandas as pd
import pytest
Expand Down Expand Up @@ -274,6 +275,60 @@ def top_five_animations(input_table: Table) -> str:
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",
Expand Down

0 comments on commit ceec0ab

Please sign in to comment.