Dry goods丨How to connect DolphinDB data source with Redash

Redash is an open source BI tool that provides web-based database query and visualization functions. DolphinDB supports obtaining data through the POST and GET interfaces of the https protocol. You can use the JSON and URL data sources in Redash to connect to the DolphinDB database.

1. Use JSON data source to connect to DolphinDB

Redash currently only supports JSON in the online version (SAAS), so users who use the online version can choose this connection method. This method requires DolphinDB to be accessible from the Internet. To use the Redash version, you need to register and log in on the Redash official website .

After logging in, create a data source on the home page and configure it according to the following steps:

(1) Establish a new data source

f3b02b405cb11784e520c938a796284e.jpeg

(2) Select JSON data source

1dd84478a03a5603a0be50803bee044b.png

(3) Configure the data source name in Name and save

b3b0a5d3509bade38046f2b74dcc92e7.png

(4) Click the Create button to create a Query

2eaa6fea9366fd89abc00bbae9f60f77.png

The JSON data source needs to be edited in yaml format.

The query needs to contain three basic elements: url, method and json.

  • url: The address that receives the data, that is, the DolphinDB data node, such as http:// host:port
  • method: http submission method, JSON interface must use POST method
  • json: Submitted JSON data, DolphinDB interface needs to provide fixed key values ​​client and queries, such as: {client:"redash","queries":"[sql query]"}, users can use any sql statement to replace [ sql query] part.

The complete query example is as follows:

 url: http://115.239.209.226:18531
 method: "post"
 json: {'client':'redash','queries':'select * from typeTable'}

2. Connect to DolphinDB using URL data source

The url data source of redash is not only supported in the online version, but also in the open source and independently deployed version. Therefore, users who use standalone deployment can connect to DolphinDB in this way.

The method of connecting and configuring the data source is basically the same as the JSON method. When selecting the data source, select the URL type data source, as shown below:

f897de1369b9006ca6c44dd82bf54b88.png

Configure the data source name and path in the URL. The URL base path is the address to obtain the data, and it can be configured as the address of the data node of DolphinDB, the format is http:// host:port。

76c14cc3c1b4b02b3fc2880da481ecaf.png

Create a new query and enter the query content in the form of a URL parameter string in the editing area. The query content format has the following requirements:

  • The subpath must be /json.
  • The query parameter must contain:  clientand queriestwo keys, which clientspecify a fixed valueredash

The complete query example is as follows:

/json?client=redash&queries=select * from typeTable where id between (1..10)

note:

Since redash url parameters on the way to be encoded check, so some special characters need to be done manually by checking the url encoding, such as query appear ://, +, &characters, need to be replaced %3a%2f%2f, %2b, %26to pass the check. For example, the distributed database path in DolphinDB dfs://dbpathneeds to be replaced with url encoding dfs%3a%2f%2fdbpathto pass redash verification.

The query that needs to be submitted:

/json?client=redash&queries=login('admin','123456');select avg(ofr-bid) from loadTable('dfs://TAQ','quotes') group by minute(time) as minute

The content actually written in redash's editor is:

/json?client=redash&queries=login('admin','123456');select avg(ofr-bid) from loadTable('dfs%3a%2f%2fTAQ','q


Guess you like

Origin blog.51cto.com/15022783/2595137