Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Cassandra visualization #420

Merged
merged 1 commit into from Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/core/dialect/cql/index.ts
Expand Up @@ -153,12 +153,20 @@ export default class CQLDialect extends GenericDialect<CassandraLib.Client> impl
}

public async getTables(): Promise<DatabaseInterface.Table[]> {
const [queryResults] = await this.query(this.queries.fetchTables);
const [queryResults, numberOfColumnsResults] = await this.query(this.queries.fetchTables);
const numberOfColumnsMap: {string: {string: number}} = numberOfColumnsResults.results.reduce((prev, curr) => prev.concat(curr), []).reduce((acc, obj: any) => {
if (typeof acc[obj.keyspace_name] === 'undefined') {
acc[obj.keyspace_name] = {};
}
acc[obj.keyspace_name][obj.table_name] = parseInt(JSON.parse(obj.count), 10);
return acc;
}, {});
return queryResults.results.reduce((prev, curr) => prev.concat(curr), []).map((obj: any) => {
const table: DatabaseInterface.Table = {
name: obj.table_name,
isView: false,
tableSchema: obj.keyspace_name,
numberOfColumns: numberOfColumnsMap[obj.keyspace_name] ? numberOfColumnsMap[obj.keyspace_name][obj.table_name] : undefined,
tree: [obj.keyspace_name, 'tables', obj.table_name].join(TREE_SEP)
};
return table;
Expand All @@ -174,6 +182,7 @@ export default class CQLDialect extends GenericDialect<CassandraLib.Client> impl
type: obj.type,
isNullable: obj.kind === 'regular',
isPk: obj.kind !== 'regular',
isPartitionKey: obj.kind === 'partition_key',
tableSchema: obj.keyspace_name,
tree: [obj.keyspace_name, 'tables', obj.table_name, obj.column_name].join(TREE_SEP)
};
Expand Down
8 changes: 6 additions & 2 deletions packages/core/dialect/cql/queries.ts
Expand Up @@ -7,6 +7,10 @@ export default {
AND table_name = ':table'`,
fetchColumns: `SELECT * FROM system_schema.columns`,
fetchRecords: `SELECT * FROM :keyspace.:table LIMIT :limit`,
fetchTables: `SELECT * FROM system_schema.tables`,
fetchFunctions: `SELECT * FROM system_schema.functions`
fetchTables: `
SELECT * FROM system_schema.tables;
SELECT keyspace_name, table_name, COUNT(*)
FROM system_schema.columns
GROUP BY keyspace_name, table_name`,
fetchFunctions: `SELECT * FROM system_schema.functions`,
} as DialectQueries;
1 change: 1 addition & 0 deletions packages/core/plugin-api.d.ts
Expand Up @@ -140,6 +140,7 @@ export namespace DatabaseInterface {
tableCatalog?: string;
defaultValue?: string;
isNullable: boolean;
isPartitionKey?: boolean;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thankfully you choose a better naming for those keys 🎊

I'll rename isPk and isFk to make it more readable.

isPk?: boolean;
isFk?: boolean;
columnKey?: string;
Expand Down
4 changes: 4 additions & 0 deletions packages/extension/icons/partition-key-dark.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions packages/extension/icons/partition-key-light.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions packages/plugins/connection-manager/explorer/SidebarColumn.ts
Expand Up @@ -12,7 +12,7 @@ export default class SidebarColumn extends SidebarAbstractItem<null> {
}
public get description() {
let typeSize = '';
if (this.column.size !== null) {
if (typeof this.column.size !== 'undefined' && this.column.size !== null) {
typeSize = `(${this.column.size})`;
}
return `${(this.column.type || '').toUpperCase()}${typeSize}`;
Expand All @@ -35,6 +35,10 @@ export default class SidebarColumn extends SidebarAbstractItem<null> {
dark: context.asAbsolutePath('icons/fk-dark.svg'),
light: context.asAbsolutePath('icons/fk-light.svg'),
},
partitionKey: {
dark: context.asAbsolutePath('icons/partition-key-dark.svg'),
light: context.asAbsolutePath('icons/partition-key-light.svg'),
},
};
}
this.updateIconPath();
Expand All @@ -46,7 +50,10 @@ export default class SidebarColumn extends SidebarAbstractItem<null> {
}
public updateIconPath() {
this.iconPath = SidebarColumn.icons.default;
if (this.column.isPk) {
if (this.column.isPartitionKey) {
this.iconPath = SidebarColumn.icons.partitionKey;
}
else if (this.column.isPk) {
this.iconPath = SidebarColumn.icons.primaryKey;
}
else if (this.column.isFk) {
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/connection-manager/explorer/index.ts
Expand Up @@ -17,6 +17,7 @@ import logger from '@sqltools/core/log/vscode';
const DialectHierarchyChildNames = {
[DatabaseDialect.PostgreSQL]: ['Database', 'Schema'],
[DatabaseDialect['AWS Redshift']]: ['Database', 'Schema'],
[DatabaseDialect.Cassandra]: ['Keyspace'],
}


Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -1061,6 +1061,11 @@
"@types/minimatch" "*"
"@types/node" "*"

"@types/ibm_db@^2.0.5":
version "2.0.5"
resolved "https://registry.yarnpkg.com/@types/ibm_db/-/ibm_db-2.0.5.tgz#6804bb7f4b3ed5018ed2db54755ac37ae482f9cb"
integrity sha512-Tb4CRJ4xz+iwixGMjV0WJ5612WZBot/zwYMti/kRmnSLM6K0Wk57yuw+hyjAq9NJp5rY9tHQVzhDzkxh9QuQqQ==

"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz#42995b446db9a48a11a07ec083499a860e9138ff"
Expand Down