Redash is an open source BI tool that provides web-based database queries and visualization capabilities. DolphinDB supports DolphinDB data through THE HTTPS POST and GET interfaces. You can use JSON and urls in Redash to connect to DolphinDB databases.

1. Connect to DolphinDB using JSON data sources

Redash currently only supports JSON in the online version (SAAS), so users using the online version can choose this connection. DolphinDB can be accessed from the Internet. To use the Redash version, you need to register and log in to the Redash website.

After login, create a data source on the home page and configure the data source as follows:

(1) Establish new data sources

(2) Select JSON data source

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

(4) Click the Create button to Create a Query

JSON data sources need to be edited in YAML format.

Query needs to contain three basic elements: URL, Method, and JSON.

  • Url: DolphinDB data nodes that receive data, such as http://host:port
  • Method: indicates the HTTP submission mode. The JSON interface must use the POST mode
  • Json: Indicates the JSON data submitted. The DolphinDB interface must provide fixed key values for clients and queries, for example: {client:”redash”,”queries”:”[SQL query]”}, users can use any SQL statements to replace the [SQL Query] part.

The complete query example is as follows:

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

2. Connect to DolphinDB using the URL data source

Redash’s URL data source is supported not only in the online version, but also in the open source independently deployed version. As a result, DolphinDB users can connect to DolphinDB in this way.

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

Set the name and path of the data source in the URL. The URL base path is the address of the data source. Set it to the address of a DolphinDB data node in http://host:port format.

Create a new Query and enter the content of the query as a URL parameter string in the edit area. The format of the query is as follows:

  • The subpath must be/JSON.
  • The query parameter must contain:clientandqueriesTwo keys, whereclientSpecifies a fixed value ofredash

The complete query example is as follows:

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

Note:

As redash encodes and verifies url parameters, some special characters need to be manually encoded to pass the verification. For example, characters such as ://,+,& in query need to be replaced with %3a%2f% 2F,%2b, and %26 to pass the verification. For example, DolphinDB’s distributed database path DFS ://dbpath needs to be replaced with the URL code DFS %3a%2f% 2fdbPath to pass redash.

Query to submit:

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

What is actually written to the redash editor is:

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