Skip to content

Commit

Permalink
console: bigquery support
Browse files Browse the repository at this point in the history
Co-authored-by: Abhijeet Singh Khangarot <[email protected]>
Co-authored-by: Aleksandra Sikora <[email protected]>
GitOrigin-RevId: 177f57b
  • Loading branch information
3 people authored and hasura-bot committed Apr 16, 2021
1 parent 7f17b26 commit e3fd4d3
Showing 41 changed files with 1,454 additions and 281 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
## Next release
(Add entries here in the order of: server, console, cli, docs, others)

- console: add bigquery support (#1000)

## v2.0.0-alpha.8

42 changes: 15 additions & 27 deletions console/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion console/package.json
Original file line number Diff line number Diff line change
@@ -198,7 +198,7 @@
"font-awesome": "4.7.0",
"font-awesome-webpack": "0.0.4",
"fork-ts-checker-webpack-plugin": "4.1.3",
"husky": "4.2.3",
"husky": "^4.2.3",
"identity-obj-proxy": "^3.0.0",
"ignore-loader": "0.1.2",
"jest": "26.6.3",
1 change: 1 addition & 0 deletions console/src/components/Common/NotSupportedNote/index.tsx
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ const driverToLabel: Record<Driver, string> = {
mysql: 'MySQL',
postgres: 'PostgreSQL',
mssql: 'MS Server',
bigquery: 'Big Query',
};

type NotSupportedNoteProps = {
4 changes: 2 additions & 2 deletions console/src/components/Common/utils/v1QueryUtils.ts
Original file line number Diff line number Diff line change
@@ -16,8 +16,8 @@ export const getRunSqlQuery = (
driver = currentDriver
) => {
let type = 'run_sql';
if (driver === 'mssql') {
type = 'mssql_run_sql';
if (driver === 'mssql' || driver === 'bigquery') {
type = `${driver}_run_sql`;
}

return {
Original file line number Diff line number Diff line change
@@ -8,8 +8,12 @@ import {
getTableModifyRoute,
getFunctionModifyRoute,
} from '../../../Common/utils/routesUtils';
import { dataSource } from '../../../../dataSources';
import { findTable, escapeTableColumns } from '../../../../dataSources/common';
import { dataSource, currentDriver } from '../../../../dataSources';
import {
findTable,
escapeTableColumns,
getQualifiedTableDef,
} from '../../../../dataSources/common';
import { exportMetadata } from '../../../../metadata/actions';
import {
getUntrackTableQuery,
@@ -39,21 +43,24 @@ const addExistingTableSql = (name, customSchema, skipRouting = false) => {
: getState().tables.currentSchema;
const currentDataSource = getState().tables.currentDataSource;
const tableName = name ? name : state.tableName.trim();
const tableDef = { name: tableName, schema: currentSchema };

const tableDef = getQualifiedTableDef(
{
name: tableName,
schema: currentSchema,
},
currentDriver
);

const table = findTable(getState().tables.allSchemas, tableDef);

const requestBodyUp = getTrackTableQuery({
tableDef,
source: currentDataSource,
customColumnNames: escapeTableColumns(table),
});

const requestBodyDown = getUntrackTableQuery(
{
name: tableName,
schema: currentSchema,
},
currentDataSource
);
const requestBodyDown = getUntrackTableQuery(tableDef, currentDataSource);

const migrationName = `add_existing_table_or_view_${currentSchema}_${tableName}`;

@@ -67,19 +74,20 @@ const addExistingTableSql = (name, customSchema, skipRouting = false) => {
t => t.table_name === tableName && t.table_schema === currentSchema
);
const isTableType = dataSource.isTable(newTable);
const nextRoute = isTableType
? getTableModifyRoute(
currentSchema,
currentDataSource,
tableName,
isTableType
)
: getTableBrowseRoute(
currentSchema,
currentDataSource,
tableName,
isTableType
);
const nextRoute =
isTableType && currentDriver !== 'bigquery'
? getTableModifyRoute(
currentSchema,
currentDataSource,
tableName,
isTableType
)
: getTableBrowseRoute(
currentSchema,
currentDataSource,
tableName,
isTableType
);
if (!skipRouting) {
dispatch(_push(nextRoute));
}
@@ -178,12 +186,17 @@ const addAllUntrackedTablesSql = tableList => {
dispatch(showSuccessNotification('Adding...'));
const bulkQueryUp = [];
const bulkQueryDown = [];

for (let i = 0; i < tableList.length; i++) {
if (tableList[i].table_name !== 'schema_migrations') {
const tableDef = {
name: tableList[i].table_name,
schema: currentSchema,
};
const tableDef = getQualifiedTableDef(
{
name: tableList[i].table_name,
schema: currentSchema,
},
currentDriver
);

const table = findTable(getState().tables.allSchemas, tableDef);
bulkQueryUp.push(
getTrackTableQuery({
@@ -197,14 +210,17 @@ const addAllUntrackedTablesSql = tableList => {
{
table: {
name: tableList[i].table_name,
schema: currentSchema,
[currentDriver === 'bigquery'
? 'dataset'
: 'schema']: currentSchema,
},
},
currentDataSource
)
);
}
}

const migrationName = 'add_all_existing_table_or_view_' + currentSchema;

const requestMsg = 'Adding existing table/view...';
35 changes: 25 additions & 10 deletions console/src/components/Services/Data/DataActions.js
Original file line number Diff line number Diff line change
@@ -26,7 +26,11 @@ import {
cascadeUpQueries,
getDependencyError,
} from './utils';
import { mergeDataMssql, mergeLoadSchemaDataPostgres } from './mergeData';
import {
mergeDataMssql,
mergeLoadSchemaDataPostgres,
mergeDataBigQuery,
} from './mergeData';
import _push from './push';
import { convertArrayToJson } from './TableModify/utils';
import { CLI_CONSOLE_MODE, SERVER_CONSOLE_MODE } from '../../../constants';
@@ -146,7 +150,9 @@ const loadSchema = configOptions => {
(!configOptions.tables || configOptions.tables.length === 0))
) {
configOptions = {
schemas: [getState().tables.currentSchema],
schemas: [
getState().tables.currentSchema || getState().tables.schemaList[0],
],
};
}

@@ -171,7 +177,6 @@ const loadSchema = configOptions => {
);
}
}

const body = {
type: 'bulk',
source,
@@ -225,6 +230,9 @@ const loadSchema = configOptions => {
case 'mssql':
mergedData = mergeDataMssql(data, metadataTables);
break;
case 'bigquery':
mergedData = mergeDataBigQuery(data, metadataTables);
break;
default:
}

@@ -308,9 +316,14 @@ const setConsistentSchema = data => ({
const fetchDataInit = (source, driver) => (dispatch, getState) => {
const url = Endpoints.query;

const { schemaFilter } = getState().tables;
const currentSource = source || getState().tables.currentDataSource;
let { schemaFilter } = getState().tables;

if (driver === 'bigquery')
schemaFilter = getState().metadata.metadataObject.sources.find(
x => x.name === source
).configuration.datasets;

const currentSource = source || getState().tables.currentDataSource;
const query = getRunSqlQuery(
dataSource.schemaListSql(schemaFilter),
currentSource,
@@ -340,7 +353,6 @@ const fetchDataInit = (source, driver) => (dispatch, getState) => {
type: FETCH_SCHEMA_LIST,
schemaList,
});

let newSchema = '';
if (schemaList.length) {
newSchema =
@@ -350,7 +362,6 @@ const fetchDataInit = (source, driver) => (dispatch, getState) => {
: schemaList.sort(Intl.Collator().compare)[0];
}
dispatch({ type: UPDATE_CURRENT_SCHEMA, currentSchema: newSchema });

return dispatch(updateSchemaInfo()); // TODO
},
error => {
@@ -558,7 +569,6 @@ export const getDatabaseTableTypeInfo = (
resolve({});
});
}

const url = Endpoints.query;
const sql = services[sourceType].getTableInfo(tables);
const query = getRunSqlQuery(sql, sourceName, false, false, sourceType);
@@ -582,13 +592,18 @@ export const getDatabaseTableTypeInfo = (
try {
if (currentDriver === 'mssql') {
res = JSON.parse(result.slice(1).join());
} else if (currentDriver === 'bigquery') {
res = result.slice(1).map(t => ({
table_name: t[0],
table_schema: t[1],
table_type: t[2],
}));
} else {
res = JSON.parse(result[1]);
}
} catch {
} catch (err) {
res = [];
}

res.forEach(i => {
if (
!trackedTables.some(
4 changes: 2 additions & 2 deletions console/src/components/Services/Data/DataSourceContainer.tsx
Original file line number Diff line number Diff line change
@@ -83,6 +83,7 @@ const DataSourceContainer = ({
dispatch({ type: UPDATE_CURRENT_SCHEMA, currentSchema: schema });
return;
}
// eslint-disable-next-line no-useless-return
if (!dataLoaded) return;

let newSchema = '';
@@ -94,11 +95,10 @@ const DataSourceContainer = ({
? dataSource.defaultRedirectSchema
: schemaList.sort(Intl.Collator().compare)[0];
}

if (location.pathname.includes('schema')) {
dispatch(push(`/data/${source}/schema/${newSchema}`));
}
}, [dispatch, schema, schemaList, source, location, dataLoaded]);
}, [dispatch, schema, schemaList, location, source, dataLoaded]);

useEffect(() => {
const driver = getSourceDriver(dataSources, currentSource);
Loading

0 comments on commit e3fd4d3

Please sign in to comment.