Convert query argument based on map
You can translate the document:
Goal
This document describes how to convert a query argument based on a map.
Content
Sometimes, in order to facilitate querying, it can be useful to expand the possibilities of the types of parameters that a query or a service accepts. For instance, a view that only accepts integer IDs as input parameter. It might be interesting to additionally support an input string parameter, with the name of the queried entity, although the internal query against the view will still rely on the required integer ID.
As an example, we want to build a web service that invokes cities by city name, that relies on a view that only takes a city ID as input parameter. This could be expanded with a query over it, where the web service can be called with city name as input parameter, without needing to change the internal view definition, that only accepts an integer ID. To do this, we will need to build an additional map between the city ID and the city name string, and connect both together.
There might be multiple reasons for such implementation constraints. For example, the entity city might be already stored, however only in one language, and maybe we want to expand query possibilities in different languages, therefore the stored information might not be sufficient to adapt the queries, and such mapping might be useful.
Assuming this mapping between the internal city ID and the city name string is known previously, it can be done by creating a new table or a new csv file that contains the mapped information. Then, a join view can be created from the table with the mapped information and the originally queried table. Finally, the join view is queried with the newly accepted string input parameter.
Example:
A web service will be able to query by city name , with a string argument ‘London’ but then queries a view with integer ‘1’. Somehow ‘London’ has to be mapped to ‘1’.
To use the solution suggested above, first create a delimited file that contains the mapped information, e.g.
STRING INT
London 1
Paris 2
Rome 3
… …
Then create a Delimited File data source and base view accessing the new delimited file. Next, create a Join view from the newly created “delimited File” base view, and the original queried view. This Join view will contain all the columns of the originally queried view plus an additional column called STRING. The required parameter city ID in the original view will be in the join criteria, matched with the ID or our new mapping table. Additionally, we define an input text parameter for this Join view, with the new STRING available if we want to restrict the query in the new service.
Now, the join view can be published as a web service and can be queried using a string. If ‘London’ is the input then only tuples that have ‘1’ as ID will be returned.
The information provided in the Denodo Knowledge Base is intended to assist our users in advanced uses of Denodo. Please note that the results from the application of processes and configurations detailed in these documents may vary depending on your specific environment. Use them at your own discretion.
For an official guide of supported features, please refer to the User Manuals. For questions on critical systems or complex environments we recommend you to contact your Denodo Customer Success Manager.
