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

modify client request and response #1378

Open
li9hu opened this issue Nov 4, 2022 · 8 comments
Open

modify client request and response #1378

li9hu opened this issue Nov 4, 2022 · 8 comments

Comments

@li9hu
Copy link

li9hu commented Nov 4, 2022

How to modify result and request of a database query for a client in a MySQL protocolo

@fulghum
Copy link
Contributor

fulghum commented Nov 4, 2022

Hey @ewan9hu, thanks for your interest in the go-mysql-server project! Can you share more specific details about what you're looking to accomplish? Are you just looking for hook that gives you access to a request before it gets processed and/or a result before it gets returned?

Let us know if you can share some more specific details with us and we'll see if we can help figure out a good way to accomplish it.

@li9hu
Copy link
Author

li9hu commented Nov 5, 2022

@fulghum thank you for your reply! Yes, that's exactly what I want to do, I want to get the results of the request and response, and modify them before returning

@fulghum
Copy link
Contributor

fulghum commented Nov 7, 2022

That seems like it could be a generally useful hook depending on how it was designed. I'm not aware of anything we have currently that provides that today.

We'd potentially be open for a contribution here, but there are a few interesting design choices around the interface that we'd want to discuss ahead of time and get agreement on. The biggest that come to mind is the representation of the query and results. Working from a query as a text string would be an easy interface to expose; using the plan tree nodes could be more powerful, but seems much more fragile and difficult to work with. Some sort of callback function for processing each returned Row would be fairly simple, but it would be worth thinking about the constraints (e.g. only being able to transform returned rows, not creating new rows to return).

@zachmu – is this something you've thought through before? Any existing hook like this?

@ywadi
Copy link

ywadi commented Nov 28, 2022

I think a good starting point is a hook for the initial query string. How can this be helpful?
I have been struggling with connecting with some BI tools, sometimes a simple query fix can help big time. A simple string replace, can solve tons of problems. Also being able to hook to the query can help us capture all the "queries' sent by different platforms and log them centrally as they have been exactly sent so we know how to handle them.

@fulghum
Copy link
Contributor

fulghum commented Nov 28, 2022

A hook that works on the incoming query string seems like a reasonable place to start. This likely won't be a high priority change for us to take on directly, but if you or anyone else is interested in sending a contribution, we'd be happy to consider it.

@ywadi
Copy link

ywadi commented Nov 28, 2022

I can work on it, I already think it has to be part of the /server/handler.go in the early stages of the doQuery() function.
Let me look into it and get back to you on that.

@ywadi
Copy link

ywadi commented Nov 29, 2022

I suggest it is added to the Event Servers ServerEventListener interface
And probably call it QueryRecieved, and add it just before the start of the function doQuery() in the server/handler.go
Should we go for that ?

@fulghum
Copy link
Contributor

fulghum commented Nov 30, 2022

Hey @ywadi, I chatted with the team and I think we've got an even easier approach for you...

The Vitess project is what provides our SQL grammar/parser as well as the MySQL wire communication protocol implementation. If you check out the Handler interface in that package, you can see that's how Vitess dispatches the incoming requests to our handler.

Our implementation of Vitess' Handler interface is in go-mysql-server/server/handler.go. We instantiate that handler implementation in server.go.

You could create your own Handler implementation that wraps our existing implementation, but adds any custom logic before or after you delegate to our Handler implementation. One idea for achieving that could be creating a new construction method (e.g. NewServerWithHandler) that lets you specify the handler to use.

Give that a shot and see what you think. That should give you what you're looking for, and will require much fewer changes and design decisions, so should get you what you're looking for faster, too.

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

No branches or pull requests

3 participants