Files
redash/client/app/services/databricks-data-source.js
Gabriel Dutra 24c95379ca Introduce caching to the Databricks Schema Browser (#5038)
* Add refresh button in the bottom

* Add caching

* Drop allSettled

* Simplify refresh button

* Update error to return 500

* Load tables before loading columns

* Don't mutate schema

* Reset db name and schemas when changing data source

* Load both tables and columns

* Return error with code 200

* Code review updates

* Add expiration time to the cache Keys

* Back with RQ
2020-07-30 15:16:14 +03:00

44 lines
1.3 KiB
JavaScript

import { has } from "lodash";
import { axios } from "@/services/axios";
import DataSource from "@/services/data-source";
import { fetchDataFromJob } from "@/services/query-result";
function fetchDataFromJobOrReturnData(data) {
return has(data, "job.id") ? fetchDataFromJob(data.job.id, 1000) : data;
}
function rejectErrorResponse(data) {
return has(data, "error") ? Promise.reject(new Error(data.error.message)) : data;
}
export default {
...DataSource,
getDatabases: ({ id }, refresh = false) => {
const params = {};
if (refresh) {
params.refresh = true;
}
return axios
.get(`api/databricks/databases/${id}`, { params })
.then(fetchDataFromJobOrReturnData)
.then(rejectErrorResponse);
},
getDatabaseTables: (data, databaseName, refresh = false) => {
const params = {};
if (refresh) {
params.refresh = true;
}
return axios
.get(`api/databricks/databases/${data.id}/${databaseName}/tables`, { params })
.then(fetchDataFromJobOrReturnData)
.then(rejectErrorResponse);
},
getTableColumns: (data, databaseName, tableName) =>
axios
.get(`api/databricks/databases/${data.id}/${databaseName}/columns/${tableName}`)
.then(fetchDataFromJobOrReturnData)
.then(rejectErrorResponse),
};