3

I have a thrift server up and running, with users sending queries over a JDBC connection. Can I intercept and modify the queries as they come in, and then send the result of the modified query back to the user?

For example - I want the user to be able to send the query

SELECT * FROM table_x WHERE pid="123";

And have the query modified to

SELECT * FROM table_y WHERE pid="123";

and the results of the second query should be returned. This should be transparent to the user.

bendl
  • 1,583
  • 1
  • 18
  • 41
  • We did this by adding an hack in SparkThriftServer code, we used to intercept the query string within the hacked code and add extra filter userid= and then submit the query further – RockSolid Feb 24 '18 at 10:59
  • @RockSolid we've been thinking about that. Happen to have any pointers? – bendl Feb 24 '18 at 13:36
  • SparkExecuteStatementOperation and SparkSession is what we thought we would add our code. I am using (yet to go in prod) a simple rule based on some external policy, I change the name of table to a view in the SQL before passing ahead. Its a bit hacky though. – RockSolid Apr 25 '18 at 03:26

3 Answers3

0

SparkExecuteStatementOperation and SparkSession is what we thought we would add our code. I am using (yet to go in prod) a simple rule based on some external policy, I change the name of table to a view in the SQL before passing ahead. Its a bit hacky though.

RockSolid
  • 488
  • 1
  • 4
  • 12
0

There is no way to change the query in Spark Thrift Server.You can used other way to change the query before your Jdbc/odbc driver.Which takes several operation on it in complex query.You can use string modification in simple query.Only a table name change is easy but Parsing the query and modify the complex query is not easy.

0

You could use a database proxy to rewrite the queries as needed before they hit the database(s).

I'm not sure if it makes sense in your particular situation, but if it does, take a look at Gallium Data, that's a common use case.