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 unnecessary CONCAT function #375

Merged
merged 6 commits into from
Aug 15, 2024

Conversation

grahamplata
Copy link
Member

Description

Resolves the following error when using Spanner by Explicitly Cast text values in CONCAT function.

SELECT CONCAT(FLOOR(created / 1000 / 60)::text) AS minute,

Resolved the following error
trino-gateway org.jdbi.v3.core.statement.UnableToExecuteStatementException: org.postgresql.util.PSQLException: ERROR: Postgres function concat(double precision) is not supported - Statement: 'SELECT CONCAT(FLOOR(created / 1000 / 60)) AS minute,
trino-gateway        backend_url AS backend_url,
trino-gateway        COUNT(1) AS query_count
trino-gateway FROM query_history
trino-gateway WHERE created > $1
trino-gateway GROUP BY minute, backend_url
trino-gateway ' [statement:"SELECT CONCAT(FLOOR(created / 1000 / 60)) AS minute,
trino-gateway        backend_url AS backend_url,
trino-gateway        COUNT(1) AS query_count
trino-gateway FROM query_history
trino-gateway WHERE created > :created
trino-gateway GROUP BY minute, backend_url
trino-gateway ", arguments:{positional:{0:1717180785232}, named:{created:1717180785232}, finder:[]}]

Additional context and related issues

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text:

* 

Copy link

cla-bot bot commented May 31, 2024

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

Copy link
Member

@mosabua mosabua left a comment

Choose a reason for hiding this comment

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

I don't think this is valid syntax that will work in MySQL and PostgreSQL. Have you tested this in both?

Copy link
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

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

This isn't a valid syntax in case of MySQL.

@grahamplata
Copy link
Member Author

This isn't a valid syntax in case of MySQL.

Ahh, Yep. I see that. My apologies. In that case is CONCAT needed for this since its a singular input? If it is not a hard requirement dropping that should meet the need

@mosabua
Copy link
Member

mosabua commented Jun 1, 2024

Also note that Spanner is not really something we use or test. Currently only MySQL and PostgreSQL are used.

@mosabua
Copy link
Member

mosabua commented Jun 1, 2024

This isn't a valid syntax in case of MySQL.

Ahh, Yep. I see that. My apologies. In that case is CONCAT needed for this since its a singular input? If it is not a hard requirement dropping that should meet the need

Looking at this I think you might be right and its not really needed. Maybe update the PR to get rid of it and we can see .. will also have to check other database scripts and see if there is something related going on.

Copy link

cla-bot bot commented Jun 1, 2024

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@@ -62,7 +62,7 @@ SELECT count(1) FROM query_history
Long count(@Define("condition") String condition);

@SqlQuery("""
SELECT CONCAT(FLOOR(created / 1000 / 60)) AS minute,
SELECT FLOOR(created / 1000 / 60) AS minute,
Copy link
Member

Choose a reason for hiding this comment

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

Can you test with PostgreSQL and MySQL and share the screenshot of Web UI?

Copy link
Member Author

Choose a reason for hiding this comment

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

Screenshot 2024-06-03 at 11 38 22 AM Screenshot 2024-06-03 at 11 39 18 AM

Copy link
Member

@ebyhr ebyhr Jun 5, 2024

Choose a reason for hiding this comment

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

Thanks for testing, but the screenshot doesn't cover the actual situation. We should run a query before accessing the UI.

Note that current change causes NumberFormatException if the table isn't an empty. I would strongly recommend adding tests.

@mosabua
Copy link
Member

mosabua commented Jun 3, 2024

I started CI and it seems good. We will have to wait for you to submit a CLA and CLA processing. In the meantime .. @vishalya @willmostly @Chaho12 .. any concerns?

@grahamplata grahamplata changed the title Explicitly Cast text values in CONCAT function Remove unnecessary CONCAT function Jun 3, 2024
Copy link
Member

@Chaho12 Chaho12 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

ebyhr
ebyhr previously requested changes Jun 5, 2024
@@ -62,7 +62,7 @@ SELECT count(1) FROM query_history
Long count(@Define("condition") String condition);

@SqlQuery("""
SELECT CONCAT(FLOOR(created / 1000 / 60)) AS minute,
SELECT FLOOR(created / 1000 / 60) AS minute,
Copy link
Member

@ebyhr ebyhr Jun 5, 2024

Choose a reason for hiding this comment

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

Thanks for testing, but the screenshot doesn't cover the actual situation. We should run a query before accessing the UI.

Note that current change causes NumberFormatException if the table isn't an empty. I would strongly recommend adding tests.

Copy link

cla-bot bot commented Jun 12, 2024

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@grahamplata grahamplata requested a review from ebyhr July 5, 2024 21:41
@ebyhr ebyhr requested review from oneonestar and removed request for ebyhr July 5, 2024 22:03
@oneonestar
Copy link
Member

I guess the CONCAT() was added to convert the data type into String.
Without CONCAT(), mysql and postgres behave differently when access through JDBI (can't reproduce using database CLI):

postgres:
minute -> {Double@9333} 3.033864E7

mysql:
minute -> {BigDecimal@9775} "30338640"

Change from Long.parseLong(model.get("minute").toString()); to (long) Float.parseFloat(model.get("minute").toString()); does solve the problem.

The change is OK but the test doesn't cover the above issue.
Could you update the test? Also you need to sign a CLA before we can merge your code.

@grahamplata
Copy link
Member Author

I guess the CONCAT() was added to convert the data type into String. Without CONCAT(), mysql and postgres behave differently when access through JDBI (can't reproduce using database CLI):

postgres:
minute -> {Double@9333} 3.033864E7

mysql:
minute -> {BigDecimal@9775} "30338640"

Change from Long.parseLong(model.get("minute").toString()); to (long) Float.parseFloat(model.get("minute").toString()); does solve the problem.

The change is OK but the test doesn't cover the above issue. Could you update the test? Also you need to sign a CLA before we can merge your code.

I'll update that shortly and the CLA email was sent last week

@mosabua
Copy link
Member

mosabua commented Jul 16, 2024

CLA will be processed soon.

@mosabua
Copy link
Member

mosabua commented Jul 22, 2024

@cla-bot check

Copy link

cla-bot bot commented Jul 22, 2024

The cla-bot has been summoned, and re-checked this pull request!

@cla-bot cla-bot bot added the cla-signed label Jul 22, 2024
Copy link
Member

@mosabua mosabua left a comment

Choose a reason for hiding this comment

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

Looks good to me now. Thanks for working with us on iterating to the right fix @grahamplata

Any concerns with merging this @ebyhr and @oneonestar ?

@oneonestar
Copy link
Member

Waiting for the test to be updated.

@oneonestar
Copy link
Member

I'll update that shortly and the CLA email was sent last week

@grahamplata Any updates?

@grahamplata
Copy link
Member Author

I'll update that shortly and the CLA email was sent last week

@grahamplata Any updates?

Yep, sorry

@oneonestar oneonestar merged commit 407d7d6 into trinodb:main Aug 15, 2024
2 checks passed
@oneonestar
Copy link
Member

Thanks.

@github-actions github-actions bot added this to the 11 milestone Aug 15, 2024
@grahamplata grahamplata deleted the gplata/psql-updates branch August 15, 2024 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants