Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Provider Deprecations in Trino #44717

Merged
merged 4 commits into from
Dec 10, 2024

Conversation

Prab-27
Copy link
Contributor

@Prab-27 Prab-27 commented Dec 6, 2024

Related: #44559

Remove deprecated code from trino provider from operators and test. Update Changelog


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@Prab-27 Prab-27 changed the title remove provider deprecations in trino Remove Provider Deprecations in Trino Dec 6, 2024
@potiuk
Copy link
Member

potiuk commented Dec 8, 2024

Can you fix the tests please ?

@Prab-27
Copy link
Contributor Author

Prab-27 commented Dec 9, 2024

Would you please tell me how to fix this test ?

There is only one deprecated class TrinoOperator in providers/src/airflow/providers/trino/operators/trino.py

When I fixed mypy and removed that files , they showed me deprecated module error

To fix I have added that files again but but it failed here.

@potiuk
Copy link
Member

potiuk commented Dec 9, 2024

This tests uses TrinoOperator:

    @mock.patch.dict("os.environ", AIRFLOW_CONN_TRINO_DEFAULT="trino://airflow@trino:8080/")
    def test_openlineage_methods(self):
        op = TrinoOperator(task_id="trino_test", sql="SELECT name FROM tpch.sf1.customer LIMIT 3")
        op.execute({})
        lineage = op.get_openlineage_facets_on_start()
        assert lineage.inputs[0].namespace == "trino://trino:8080"
        assert lineage.inputs[0].name == "tpch.sf1.customer"
        assert "schema" in lineage.inputs[0].facets
        assert lineage.job_facets["sql"].query == "SELECT name FROM tpch.sf1.customer LIMIT 3"

Replace with SQLExecuteQueryOperator -as suggested by deprecation message.

@Prab-27
Copy link
Contributor Author

Prab-27 commented Dec 10, 2024

Done!

@potiuk potiuk merged commit 43ad2ca into apache:main Dec 10, 2024
48 checks passed
Comment on lines -59 to -109
def test_execute_openlineage_events():
DB_NAME = "tpch"
DB_SCHEMA_NAME = "sf1"

class TrinoHookForTests(TrinoHook):
get_conn = mock.MagicMock(name="conn")
get_connection = mock.MagicMock()

def get_first(self, *_):
return [f"{DB_NAME}.{DB_SCHEMA_NAME}"]

dbapi_hook = TrinoHookForTests()

sql = "SELECT name FROM tpch.sf1.customer LIMIT 3"
op = SQLExecuteQueryOperator(task_id="trino-operator", sql=sql, conn_id=TRINO_DEFAULT)
op._hook = dbapi_hook
rows = [
(DB_SCHEMA_NAME, "customer", "custkey", 1, "bigint", DB_NAME),
(DB_SCHEMA_NAME, "customer", "name", 2, "varchar(25)", DB_NAME),
(DB_SCHEMA_NAME, "customer", "address", 3, "varchar(40)", DB_NAME),
(DB_SCHEMA_NAME, "customer", "nationkey", 4, "bigint", DB_NAME),
(DB_SCHEMA_NAME, "customer", "phone", 5, "varchar(15)", DB_NAME),
(DB_SCHEMA_NAME, "customer", "acctbal", 6, "double", DB_NAME),
]
dbapi_hook.get_connection.return_value = Connection(
conn_id=TRINO_DEFAULT,
conn_type="trino",
host="trino",
port=8080,
)
dbapi_hook.get_conn.return_value.cursor.return_value.fetchall.side_effect = [rows, []]

lineage = op.get_openlineage_facets_on_start()
assert lineage.inputs == [
Dataset(
namespace="trino://trino:8080",
name=f"{DB_NAME}.{DB_SCHEMA_NAME}.customer",
facets={
"schema": SchemaDatasetFacet(
fields=[
SchemaDatasetFacetFields(name="custkey", type="bigint"),
SchemaDatasetFacetFields(name="name", type="varchar(25)"),
SchemaDatasetFacetFields(name="address", type="varchar(40)"),
SchemaDatasetFacetFields(name="nationkey", type="bigint"),
SchemaDatasetFacetFields(name="phone", type="varchar(15)"),
SchemaDatasetFacetFields(name="acctbal", type="double"),
]
)
},
)
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this was suppose to be removed?
this is testing open lineage integration with TrinoHook
cc @kacpermuda @mobuchowski

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i think it should be adjusted after the removal of deprecated code and not fully removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this was probably removed by mistake.

@Prab-27 can you revert that test?

Copy link
Contributor

@kacpermuda kacpermuda Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was probably removed as the operators/trino.py file has been removed, so it makes sense that the corresponding test file is removed, but IMHO we should still keep this test in the trino provider (maybe in a differently named file).

@@ -50,7 +50,7 @@ def test_should_record_records_with_kerberos_auth(self):

@mock.patch.dict("os.environ", AIRFLOW_CONN_TRINO_DEFAULT="trino://airflow@trino:8080/")
def test_openlineage_methods(self):
op = TrinoOperator(task_id="trino_test", sql="SELECT name FROM tpch.sf1.customer LIMIT 3")
op = SQLExecuteQueryOperator(task_id="trino_test", sql="SELECT name FROM tpch.sf1.customer LIMIT 3")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add conn_id="trino_default" as this test is failing now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right it was removed by mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya I'll correct that id

@Prab-27
Copy link
Contributor Author

Prab-27 commented Dec 10, 2024

I am Sorry
Could you please tell me where I can add this test code ?

providers/tests/trino/hooks/test_trino.py ? here ?

@eladkal
Copy link
Contributor

eladkal commented Dec 10, 2024

providers/tests/trino/hooks/test_trino.py ? here ?

That would be ok

@Prab-27
Copy link
Contributor Author

Prab-27 commented Dec 10, 2024

Would you please tell me which test I should run to check if it is okay or not ?

Does this work ?
breeze testing providers-tests --test-type "Providers[trino]"

it passed at that time

@kacpermuda
Copy link
Contributor

Here is an example where this test failed. It was triggered with ./scripts/ci/testing/run_integration_tests_with_retry.sh providers "trino", maybe try that?

@kacpermuda
Copy link
Contributor

Ah, sorry you meant the other test. Yes, the breeze command looks good.

@Prab-27
Copy link
Contributor Author

Prab-27 commented Dec 10, 2024

No, you are right. I am asking about the provider test, not Breeze, so I can know about that.
The Breeze tests failed due to my mistakes.
Sorry, I am a newbie, so I don’t know about all this. I am trying to learn

@Prab-27
Copy link
Contributor Author

Prab-27 commented Dec 10, 2024

@eladkal ,I am confused. Would You please tell me if I should add this method here

providers/tests/integration/trino/hooks/test_trino.py because this file contains similar methods
or [providers/tests/trino/hooks/test_trino.py]

@eladkal
Copy link
Contributor

eladkal commented Dec 10, 2024

I'm not sure I follow the issue.
The test this PR removed was in providers/tests/trino/operators/test_trino.py
So we just need to bring it back, the best candidate is providers/tests/trino/hooks/test_trino.py

Why are we discussing system tests path?

@Prab-27
Copy link
Contributor Author

Prab-27 commented Dec 10, 2024

Sorry , You are right I have noticed a similar method test_openlineage_methods at here so I asked providers/tests/integration/trino/hooks/test_trino.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants