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

Add support for Oracle as backend database #89

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

posulliv
Copy link

@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
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.

@@ -77,7 +77,6 @@ public static List<ResourceGroupsDetail> upcast(List<ResourceGroups> resourceGro
* @param resourceGroupDetail
*/
public static void create(ResourceGroups model, ResourceGroupsDetail resourceGroupDetail) {
model.set(resourceGroupId, resourceGroupDetail.getResourceGroupId());
Copy link
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
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!

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
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
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
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
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
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
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

@@ -18,7 +18,7 @@ CREATE INDEX query_history_created_idx ON query_history(created);

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
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
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
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
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
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
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
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?

@willmostly
Copy link
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
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
Author

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

Copy link
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

pom.xml Outdated Show resolved Hide resolved
@mosabua
Copy link
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
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

gateway-ha/pom.xml Outdated Show resolved Hide resolved
@posulliv
Copy link
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
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
Member

ebyhr commented Mar 5, 2024

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

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.

None yet

5 participants