-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[jdbc] Fix tableCaseSensitiveItemNames
for PostgreSQL/TimescaleDB
#17587
Conversation
Signed-off-by: JonathanvdGHU <jonathan.vandegiessen@student.hu.nl>
Thanks for the fix. I'll review this in the weekend. |
Good to hear. Is it a big problem I made a mess with the commits? I am trying to do a rebase but it's not really working. |
It seems some commits are incorrectly signed. If there is at least one correctly signed commit, I can use that when squash-merging. Otherwise you will need to rebase to fix it. |
Signed-off-by: JonathanvdGHU <jonathan.vandegiessen@student.hu.nl>
81f6e1e
to
563add6
Compare
Signed-off-by: JonathanvdGHU <jonathan.vandegiessen@student.hu.nl>
I fixed it. This was my first rebase so I am also a little proud about myself xD |
Signed-off-by: JonathanvdGHU <jonathan.vandegiessen@student.hu.nl>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix looks valid, but I have provided some feedback on the approach. I think it would be preferable to keep the DTO's unchanged and instead directly fix the queries which only concern PostgreSQL/TimescaleDB.
...rsistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java
Outdated
Show resolved
Hide resolved
...rsistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java
Outdated
Show resolved
Hide resolved
...rsistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java
Outdated
Show resolved
Hide resolved
...sistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcTimescaledbDAO.java
Outdated
Show resolved
Hide resolved
...sistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcTimescaledbDAO.java
Outdated
Show resolved
Hide resolved
...sistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcTimescaledbDAO.java
Outdated
Show resolved
Hide resolved
tableCaseSensitiveItemNames
for PostgreSQL/TimescaleDB
Signed-off-by: JonathanvdGHU <jonathan.vandegiessen@student.hu.nl>
I implemented your requested changes :) |
Signed-off-by: JonathanvdGHU <jonathan.vandegiessen@student.hu.nl>
Thanks! I'll take one more look. In the meantime, I see there are formatting changes for comments, why is that? I just want to avoid having this changed back and forth depending on some individual IDE settings, if that's the case. It also disturbs diff'ing. 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last batch of comments, I hope. 🙂
...rsistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java
Outdated
Show resolved
Hide resolved
...rsistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java
Outdated
Show resolved
Hide resolved
...rsistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java
Outdated
Show resolved
Hide resolved
...rsistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java
Outdated
Show resolved
Hide resolved
...rsistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java
Outdated
Show resolved
Hide resolved
...sistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcTimescaledbDAO.java
Outdated
Show resolved
Hide resolved
...rsistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java
Outdated
Show resolved
Hide resolved
I can see now after the latest changes the dilemma here when overridden queries differ only in table name being quoted. With the approach I suggested, those queries are now overridden, which feels like duplication. For example: sqlDropTable = "DROP TABLE \"#tableName#\""; overriding: protected String sqlDropTable = "DROP TABLE #tableName#"; With your original approach, instead we would have had to overload the methods only to call a different DTO method, which would have been even worse. So it seems we would need to do something different to fully avoid duplication. What would you think about introducing a protected method protected String getTableName(ItemsVO vo) {
return vo.getTableName();
} which could then be used from all query methods, i.e. This would allow for overriding this method for PostgreSQL to return the quoted table name, but without changing any query methods or queries when they are not otherwise needed to be adapted for PostgreSQL? This is just from the top of my head and all optional, and if you prefer to stick with your current implementation, that's fine as well. |
Signed-off-by: JonathanvdGHU <jonathan.vandegiessen@student.hu.nl>
It was the IDE 😅. |
I also thought it was duplication so that's why I added the function |
Signed-off-by: JonathanvdGHU <jonathan.vandegiessen@student.hu.nl>
I think it's now done. |
Signed-off-by: JonathanvdGHU <jonathan.vandegiessen@student.hu.nl> re-added deleted changed from rebase Signed-off-by: JonathanvdGHU <jonathan.vandegiessen@student.hu.nl> removed not related code to the bug Signed-off-by: JonathanvdGHU <jonathan.vandegiessen@student.hu.nl> implemented feedback Signed-off-by: JonathanvdGHU <jonathan.vandegiessen@student.hu.nl> changes also implied on itemsmanagetable Signed-off-by: JonathanvdGHU <jonathan.vandegiessen@student.hu.nl> reverted notes Signed-off-by: JonathanvdGHU <jonathan.vandegiessen@student.hu.nl> reverted missed notes removed unnecessary methods Signed-off-by: JonathanvdGHU <jonathan.vandegiessen@student.hu.nl>
…GHU/openhab-addons into timescaledb-table-bug
...rsistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks! I'll wait for confirmation that everything still works correctly after the latest changes. 🙂
The problem with that is that you would need to overload all methods in order to call the alternative DTO method, so that would generate even more duplication - it would just be duplicated methods rather than duplicated query strings.
That's fine, I'll see if I can find some time to refactor this later. |
Thanks for the patience for all this 😌 |
Likewise. 😉 Before merging, besides test confirmation, there is one more thing needed: When checking the failed DCO, I noticed that your real (full) name is missing in your signoffs. You can fix both issues by rebasing your commits. If you click "Details" right to "DCO", you can see how to do that. If you are not comfortable with that, I can fix the signoff when squash-merging the PR. In that case I'd just need your full name. Thanks! |
My full name is included in my email, that you can see in the signoff. I'll update it if I return for any future bug fixes! 😅. So you can use that name for squash-merging. I tested on another branch how to rebase successfully (there are a lot of merge conflicts) but I think it's the easiest way if you do it. |
What is your estimate when the pull request will be merged? |
I"ll merge when you have confirmed that everything is still working after the latest changes. |
Oh a small misunderstanding I guess. Everything related to the bug is working now, so it's fixed. |
@jlaur I double checked and found out I missed one table in the |
It would be highly appreciated if you could create a new PR with the fix. Using the same branch is a bit messy, because all the previous commits will appear again. Since it's a one-liner and since we use squash-merge, it will be fine this time. For your next contributions (hoping there will be some 😉) it is recommended to create a new branch from your local main branch after pulling latest changes. |
WHERE table_name='\"#tableName#\"' AND table_catalog='#jdbcUriDatabaseName#' AND table_schema=(SELECT table_schema FROM information_schema.tables WHERE table_type='BASE TABLE' \ | ||
AND table_name='\"#itemsManageTable#\"')\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JonathanvdGHU - I think the quotes here were a mistake, since the table names are not used for referencing the tables directly, but rather being used to query the information schema. Do you agree? See also #17597.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand what you mean, but to be honest I am not sure how postgreSQL reacts when you remove them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends how it internally stores the table names. Would it possibly for you to run a query so we can see?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will try it when I have the time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you try:
SELECT table_name
FROM information_schema.tables
I would expect it to return e.g. TotalUsage
rather than "TotalUsage"
.
Or to be specific as in your query (single quotes were missing):
SELECT *
FROM information_schema.tables
WHERE table_name = 'TotalUsage'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, thanks. So indeed the double-quotes should not be included in those queries, thus already fixed as part of #17597.
…penhab#17587) Signed-off-by: Jonathan van de Giessen <jonathan.vandegiessen@student.hu.nl>
…penhab#17587) Signed-off-by: Jonathan van de Giessen <jonathan.vandegiessen@student.hu.nl>
…penhab#17587) Signed-off-by: Jonathan van de Giessen <jonathan.vandegiessen@student.hu.nl> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
Case-sensitive tables working for TimescaleDB database via JDBC persistence service
Description
The following issue is resolved. My implementation is maybe not the best one because I didn't take the time to understand everything. So I don't mind if someone makes some small adjustments and makes a new pull request :)