Skip to content

Add support for Oracle as backend database#89

Closed
posulliv wants to merge 1 commit intotrinodb:mainfrom
posulliv:add-oracle-db-support
Closed

Add support for Oracle as backend database#89
posulliv wants to merge 1 commit intotrinodb:mainfrom
posulliv:add-oracle-db-support

Conversation

@posulliv
Copy link
Copy Markdown
Contributor

@posulliv posulliv commented Nov 8, 2023

No description provided.

@cla-bot cla-bot bot added the cla-signed label Nov 8, 2023
return QueryHistory.upcast(QueryHistory.findBySQL(String.join(" ",
sql,
"order by created desc",
"limit 2000")));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed this hard-coded SQL since LIMIT is not supported in Oracle.

* @param resourceGroupDetail
*/
public static void create(ResourceGroups model, ResourceGroupsDetail resourceGroupDetail) {
model.set(resourceGroupId, resourceGroupDetail.getResourceGroupId());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I made this change to ensure auto-increment resource group ID column is used.

Copy link
Copy Markdown
Contributor

@willmostly willmostly left a comment

Choose a reason for hiding this comment

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

Just a few minor comments, thanks for the submission!

String sql = "select * from query_history";
if (user.isPresent()) {
sql += " where user_name = '" + user.get() + "'";
return QueryHistory.upcast(QueryHistory.where("user_name = '" + user.get() + "'").limit(2000).orderBy("created desc"));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use QueryHistory.userName instead of "user_name" and QueryHistory.created instead of "created"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It appears all the attributes of the activejdbc models are private. Should we add getters for them? Not sure what the typical activejdbc pattern is for this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should make these public IMO

CREATE INDEX query_history_created_idx ON query_history(created);

CREATE TABLE resource_groups (
resource_group_id NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't know Oracle very well, but would a LONG be a better choice than a NUMBER? Iiuc a NUMBER with unspecified scale supports real numbers as well as integers. Not that it probably matters much

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

a LONG in oracle is not actually a numeric data type confusingly enough :) https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Data-Types.html#GUID-F6309DF8-162F-48A4-9454-FEE59EC6644F

I would vote to use NUMBER as the data type for the identity column here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

After reviewing, I'd agree

CREATE TABLE IF NOT EXISTS resource_groups (
resource_group_id BIGINT NOT NULL AUTO_INCREMENT,
name VARCHAR(250) NOT NULL UNIQUE,
name VARCHAR(250) NOT NULL,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we changing the MySQL sql for this PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I updated it to match the schema in trino for consistency - https://github.com/trinodb/trino/blob/master/plugin/trino-resource-group-managers/src/main/resources/db/migration/mysql/V2__add_resource_groups.sql

Happy to revert if unique names need to be enforced for gateway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

One use case for non-unique names I have had in the past with Trino is storing the same resource group definitions for different environments in the same database. This is possible since resource groups are determined by the environment column of the resource_groups table. So you could use a single database and have the same resource group definitions for multiple environments.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure. Trino clusters require an environment name set, while the gateway could front backends with different environment names. So environment could be less meaningful in the gateway context. OTOH, this is defined by the user, and they can choose not to complicate things.

I guess being able to import a set of policies from Trino to the gateway probably wins out.

@vishalya
Copy link
Copy Markdown
Member

Also, a general comment here - we are supporting almost 3 dbs now, will it be a good idea to use migrations now than actual DDL like Flyway.

@mosabua
Copy link
Copy Markdown
Member

mosabua commented Nov 10, 2023

Also, a general comment here - we are supporting almost 3 dbs now, will it be a good idea to use migrations now than actual DDL like Flyway.

Totally agree .. that could also help with installation/ bootstrap .. and we need to figure out testing for the different backends.

@posulliv
Copy link
Copy Markdown
Contributor Author

Also, a general comment here - we are supporting almost 3 dbs now, will it be a good idea to use migrations now than actual DDL like Flyway.

We are using flyway in trino for resource group migrations so could likely reuse some of what we did there. Are we good with doing this in a follow up PR though?

@posulliv posulliv force-pushed the add-oracle-db-support branch from 219b650 to 6469a13 Compare November 15, 2023 16:29
@willmostly
Copy link
Copy Markdown
Contributor

Are we good with doing this in a follow up PR though?
I agree that we should split these up. Either first Oracle, then Flyway, or the other way round.

@mosabua
Copy link
Copy Markdown
Member

mosabua commented Jan 5, 2024

Fyi @ebyhr ... any thought of adding an abstraction layer like Flyway or so? Also given you are ripping over from activejdbc to jdbi it would be good to have a coherent plan in place

And @posulliv please rebase this PR so we can review again and look towards merging.

@posulliv posulliv force-pushed the add-oracle-db-support branch 2 times, most recently from 0ce3613 to 8595d29 Compare January 11, 2024 14:17
@posulliv
Copy link
Copy Markdown
Contributor Author

@willmostly @mosabua OK I rebased against latest master to resolve conflicts.

Copy link
Copy Markdown
Contributor

@willmostly willmostly left a comment

Choose a reason for hiding this comment

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

This looks ready to go. @posulliv and I have discussed offline and will begin work to introduce Flyway for schema management once this PR is merged

Comment thread pom.xml Outdated
@mosabua
Copy link
Copy Markdown
Member

mosabua commented Feb 2, 2024

At minimum a rebase has to be done. I can review more then ..

```$xslt
curl -X POST http://localhost:8080/trino/selector/create \
-d '{
"resourceGroupId": 1, \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

that seems like a bad idea .. how would you know what number to use? An id should be created automatically. Also .. this change should be independent and separate

Comment thread gateway-ha/src/main/java/io/trino/gateway/ha/persistence/dao/QueryHistory.java Outdated
Comment thread gateway-ha/pom.xml Outdated
@posulliv posulliv force-pushed the add-oracle-db-support branch from 8595d29 to 1b600dd Compare February 6, 2024 16:02
@posulliv posulliv force-pushed the add-oracle-db-support branch from 1b600dd to 8119bd0 Compare February 6, 2024 16:16
@posulliv
Copy link
Copy Markdown
Contributor Author

posulliv commented Feb 6, 2024

Rebased but tests failing now. Will try to figure it out when I get a chance this week.

@posulliv
Copy link
Copy Markdown
Contributor Author

posulliv commented Feb 7, 2024

@ebyhr the problem I'm facing now is that the SQL in QueryHistoryDao is not compatible with Oracle (limit is not supported in Oracle). Didn't have this issue with activejdbc when calling QueryHistory.limit().

Any suggestions on the preferred approach to deal with this in JDBI?

@ebyhr
Copy link
Copy Markdown
Member

ebyhr commented Mar 5, 2024

@posulliv We can call different dao methods based on the connection-url prefix jdbc:oracle.

@mosabua
Copy link
Copy Markdown
Member

mosabua commented Sep 5, 2024

Chatted with @willmostly .. I think this can be closed and restarted when it becomes relevant. Feel free to reopen after rebasing and adjusting

@mosabua mosabua closed this Sep 5, 2024
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