Redshift & PostgreSQL
The Redshift data provider allows ChartFactor to interact with Redshift and PostgreSQL through a custom and open source HTTP API.
First, we include the library in the main html of our app:
| <script src="./cft-redshift-provider.min.js"></script>
|
The Provider JSON object requires the url parameter in addition to name and provider parameters. Example:
| var providers = [{
name:'Redshift',
provider:'redshift',
url:'http://localhost:3000'
}]
|
The configuration for Redshift also allows to specify headers in case they are required, for example for authentication purposes:
| var providers = [{
...
headers: { 'Authorization': authToken }
}]
|
Then, use the setProviders() method of ChartFactor to set your data provider definitions. Example:
| cf.setProviders(providers);
|
Configuration Parameters
- name (mandatory): The name of the provider. ej. redshift-local
- URL (mandatory): The URL of the data provider. ej. http://localhost:3000
- headers: sets the provider's headers in case they are needed such as for authentication purposes. If this property is set, it will override the
accessToken
property (below). Example:
| var providers = [{
...
headers: { 'Authorization': authToken }
}]
|
- OAuth2 parameters:
- bypassOAuth: If this parameter is provided as true the OAuth2 authentication process will be bypassed
- cognitoUrl: In this field you provide the Authorization Server such as Amazon Cognito domain. Example: https://your-domain-prefix.auth.your-amazon-region.amazoncognito.com
- clientId: In this field you have to provide the App client id
- redirectUrl: In this field you have to provide the redirect URL. The redirect URL has to be registered in the sign-in and sign-out URLs of the Amazon Cognito App Client Settings and should bring the authorization token that should be stored in the local storage with the key accessToken.
- redirectOnSameTab: When a token is acquired or renewed, the OAuth process opens a new window (tab) to authenticate the user. If this is set to true, the process redirects to the authentication page in the same window. Bbe aware that data on the current page could be lost.
- accessToken: generates an
Authorization
header with the content of the accessToken parameter
Oauth2 implicit workflow redirect URL implementation example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 | <!DOCTYPE html>
<body>
<script>
let url_string = window.location.href;
let url = new URL(url_string.replace('#', '?'));
let token = url.searchParams.get('id_token');
let error_description = url.searchParams.get('error_description');
if (token) {
console.log(`Login sucessfully with access token: ${token}`);
localStorage.setItem('access_token', token);
} else {
token = localStorage.getItem('access_token');
}
if (error_description) {
console.log('Login unsucessfull, access denied.');
} else if (token) {
window.location = 'index.html'; // Your app entry point or the latest before hit the auth
} else {
console.log('No access token, redirecting to the OAuth interface');
window.location = 'https://your-domain-prefix.auth.your-amazon-region.amazoncognito.com/login?response_type=token&client_id=your-client-id&redirect_uri=your-redirect-url';
}
</script>
</body>
</html>
|
Supported Aggregations Out-Of-The-Box
SUM
| var metric = cf.Metric("amount","sum");
|
AVG
| var metric = cf.Metric("amount","avg");
|
MIN
| var metric = cf.Metric("amount","min");
|
MAX
| var metric = cf.Metric("amount","max");
|
COUNT DISTINCT
| var metric = cf.Metric("my_attribute","unique");
|
PERCENTILES
| var metric = cf.Metric('commission', 'percentiles');
|
GEOHASH
GeoHash queries require the PostGIS extension installed in your Postgres database. Please refer to Geo Queries for more information on how to perform these queries.