Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: show partition tables in sql editor (#9577)
boojack4589a6d8e93c
diff --git a/backend/api/v1/database_service.go b/backend/api/v1/database_service.goindex b390724901..c745681f92 100644--- a/backend/api/v1/database_service.go+++ b/backend/api/v1/database_service.go@@ -2764,10 +2764,14 @@ func convertTableMetadata(table *storepb.TableMetadata, view v1pb.DatabaseMetadaClassification: table.Classification,UserComment: table.UserComment,}+ for _, partition := range table.Partitions {+ t.Partitions = append(t.Partitions, convertTablePartitionMetadata(partition))+ }// We only return the table info for basic view.if view != v1pb.DatabaseMetadataView_DATABASE_METADATA_VIEW_FULL {return t}+for _, column := range table.Columns {t.Columns = append(t.Columns, convertColumnMetadata(column))}@@ -2794,9 +2798,6 @@ func convertTableMetadata(table *storepb.TableMetadata, view v1pb.DatabaseMetadaMatchType: foreignKey.MatchType,})}- for _, partition := range table.Partitions {- t.Partitions = append(t.Partitions, convertTablePartitionMetadata(partition))- }return t}diff --git a/frontend/src/components/DatabaseOverviewPanel.vue b/frontend/src/components/DatabaseOverviewPanel.vueindex c5937c23d3..9f18aa91fa 100644--- a/frontend/src/components/DatabaseOverviewPanel.vue+++ b/frontend/src/components/DatabaseOverviewPanel.vue@@ -231,7 +231,7 @@ watch(await dbSchemaStore.getOrFetchDatabaseMetadata({database: database,skipCache: false,- view: DatabaseMetadataView.DATABASE_METADATA_VIEW_FULL,+ view: DatabaseMetadataView.DATABASE_METADATA_VIEW_BASIC,});if (schemaList.value.length > 0) {const schemaInQuery = route.query.schema as string;diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.tsindex b95a68e703..720fcb8d97 100644--- a/frontend/src/router/index.ts+++ b/frontend/src/router/index.ts@@ -1325,7 +1325,7 @@ router.beforeEach((to, from, next) => {.getOrFetchDatabaseMetadata({database: database.name,skipCache: false,- view: DatabaseMetadataView.DATABASE_METADATA_VIEW_FULL,+ view: DatabaseMetadataView.DATABASE_METADATA_VIEW_BASIC,}).then(() => {next();diff --git a/frontend/src/store/modules/sqlEditorTree.ts b/frontend/src/store/modules/sqlEditorTree.tsindex 7fe8c8b8d5..c12a99ae4e 100644--- a/frontend/src/store/modules/sqlEditorTree.ts+++ b/frontend/src/store/modules/sqlEditorTree.ts@@ -27,6 +27,7 @@ import {DEFAULT_PROJECT_V1_NAME,RichViewMetadata,TextTarget,+ RichPartitionTableMetadata,} from "@/types";import { Environment } from "@/types/proto/v1/environment_service";import { emptyConnection, getSemanticLabelValue, groupBy } from "@/utils";@@ -347,6 +348,13 @@ export const idForSQLEditorTreeNodeTarget = <T extends NodeType>(table.name}`;}+ if (type === "partition-table") {+ const { database, schema, table, partition } =+ target as RichPartitionTableMetadata;+ return `${database.name}/schemas/${schema.name || "-"}/tables/${+ table.name+ }/partitions/${partition.name}`;+ }if (type === "view") {const { database, schema, view } = target as RichViewMetadata;return `${database.name}/schemas/${schema.name || "-"}/views/${view.name}`;@@ -496,7 +504,7 @@ export const mapTreeNodeByType = <T extends NodeType>(meta: { type, target },parent,label: readableTargetByType(type, target),- isLeaf: LeafTreeNodeTypes.includes(type),+ isLeaf: isLeafNodeType(type),...overrides,};@@ -527,6 +535,9 @@ const readableTargetByType = <T extends NodeType>(if (type === "table") {return (target as RichTableMetadata).table.name;}+ if (type === "partition-table") {+ return (target as RichPartitionTableMetadata).partition.name;+ }if (type === "view") {return (target as RichViewMetadata).view.name;}@@ -542,6 +553,10 @@ const readableTargetByType = <T extends NodeType>(return (target as NodeTarget<"label">).value;};+const isLeafNodeType = (type: NodeType) => {+ return LeafTreeNodeTypes.includes(type);+};+const getSemanticFactorValue = (db: ComposedDatabase, factor: Factor) => {switch (factor) {case "environment":diff --git a/frontend/src/types/sqlEditorTree.ts b/frontend/src/types/sqlEditorTree.tsindex f5d0c3d257..2b07811e93 100644--- a/frontend/src/types/sqlEditorTree.ts+++ b/frontend/src/types/sqlEditorTree.ts@@ -6,6 +6,7 @@ import { Engine } from "./proto/v1/common";import {SchemaMetadata,TableMetadata,+ TablePartitionMetadata,ViewMetadata,} from "./proto/v1/database_service";import { Environment } from "./proto/v1/environment_service";@@ -31,6 +32,7 @@ export type SQLEditorTreeNodeType =| "table"| "label"| "view"+ | "partition-table"| "expandable-text" // Text nodes to display "Tables / Views / Functions / Triggers" etc.| "dummy"; // Dummy nodes to display "<Empty>" etc.@@ -43,6 +45,13 @@ export type RichTableMetadata = {schema: SchemaMetadata;table: TableMetadata;};+export type RichPartitionTableMetadata = {+ database: ComposedDatabase;+ schema: SchemaMetadata;+ table: TableMetadata;+ parentPartition?: TablePartitionMetadata;+ partition: TablePartitionMetadata;+};export type RichViewMetadata = {database: ComposedDatabase;schema: SchemaMetadata;@@ -69,6 +78,8 @@ export type SQLEditorTreeNodeTarget<T extends SQLEditorTreeNodeType = any> =? RichSchemaMetadata: T extends "table"? RichTableMetadata+ : T extends "partition-table"+ ? RichPartitionTableMetadata: T extends "view"? RichViewMetadata: T extends "label"@@ -108,6 +119,8 @@ export const ExpandableTreeNodeTypes: readonly SQLEditorTreeNodeType[] = ["instance","environment","project",+ "table",+ "partition-table","expandable-text","label",] as const;@@ -118,7 +131,6 @@ export const ConnectableTreeNodeTypes: readonly SQLEditorTreeNodeType[] = [] as const;export const LeafTreeNodeTypes: readonly SQLEditorTreeNodeType[] = [- "table","view","dummy",] as const;diff --git a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vueindex d33453195a..266e993a11 100644--- a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue+++ b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue@@ -385,7 +385,7 @@ const nodeProps = ({ option }: { option: TreeOption }) => {if (type === "instance" || type === "database") {setConnection(node);}- if (type === "table") {+ if (type === "table" || type === "partition-table") {maybeSelectTable(node);}}diff --git a/frontend/src/views/sql-editor/AsidePanel/TreeNode/Label.vue b/frontend/src/views/sql-editor/AsidePanel/TreeNode/Label.vueindex 5530a0caa7..85ab9b6697 100644--- a/frontend/src/views/sql-editor/AsidePanel/TreeNode/Label.vue+++ b/frontend/src/views/sql-editor/AsidePanel/TreeNode/Label.vue@@ -17,6 +17,9 @@<template v-if="type === 'table'"><TableNode :node="node" :factors="factors" :keyword="keyword" /></template>+ <template v-if="type === 'partition-table'">+ <PartitionTableNode :node="node" :factors="factors" :keyword="keyword" />+ </template><template v-if="type === 'view'"><ViewNode :node="node" :factors="factors" :keyword="keyword" /></template>@@ -42,6 +45,7 @@ import DummyNode from "./DummyNode.vue";import EnvironmentNode from "./EnvironmentNode.vue";import InstanceNode from "./InstanceNode.vue";import LabelNode from "./LabelNode.vue";+import PartitionTableNode from "./PartitionTableNode.vue";import ProjectNode from "./ProjectNode.vue";import SchemaNode from "./SchemaNode.vue";import TableNode from "./TableNode.vue";diff --git a/frontend/src/views/sql-editor/AsidePanel/TreeNode/PartitionTableNode.vue b/frontend/src/views/sql-editor/AsidePanel/TreeNode/PartitionTableNode.vuenew file mode 100644index 0000000000..e0c34981ce--- /dev/null+++ b/frontend/src/views/sql-editor/AsidePanel/TreeNode/PartitionTableNode.vue@@ -0,0 +1,30 @@+<template>+ <div class="flex items-center max-w-full overflow-hidden gap-x-1">+ <TableIcon class="w-4 h-4" />+ <HighlightLabelText+ :text="target.partition.name"+ :keyword="keyword"+ class="flex-1 truncate"+ />+ </div>+</template>++<script setup lang="ts">+import { computed } from "vue";+import { TableIcon } from "@/components/Icon";+import {+ SQLEditorTreeNode as TreeNode,+ SQLEditorTreeFactor as Factor,+} from "@/types";+import HighlightLabelText from "./HighlightLabelText.vue";++const props = defineProps<{+ node: TreeNode;+ factors: Factor[];+ keyword: string;+}>();++const target = computed(+ () => (props.node as TreeNode<"partition-table">).meta.target+);+</script>diff --git a/frontend/src/views/sql-editor/AsidePanel/common.ts b/frontend/src/views/sql-editor/AsidePanel/common.tsindex 40180e137b..a0b3ed72eb 100644--- a/frontend/src/views/sql-editor/AsidePanel/common.ts+++ b/frontend/src/views/sql-editor/AsidePanel/common.ts@@ -11,6 +11,8 @@ import {import {SchemaMetadata,DatabaseMetadataView,+ TableMetadata,+ TablePartitionMetadata,} from "@/types/proto/v1/database_service";const createDummyNode = (@@ -53,14 +55,85 @@ const mapTableNodes = (schema: SchemaMetadata,parent: SQLEditorTreeNode) => {- const children = schema.tables.map((table) =>- mapTreeNodeByType("table", { database, schema, table }, parent)- );+ const children = schema.tables.map((table) => {+ const node = mapTreeNodeByType(+ "table",+ { database, schema, table },+ parent+ );++ // Map table-level partitions.+ if (table.partitions.length > 0) {+ node.isLeaf = false;+ node.children = [];+ for (const partition of table.partitions) {+ const subnode = mapTreeNodeByType(+ "partition-table",+ { database, schema, table, partition },+ node+ );+ if (partition.subpartitions.length > 0) {+ subnode.isLeaf = false;+ subnode.children = mapPartitionTableNodes(+ database,+ schema,+ table,+ partition,+ subnode+ );+ } else {+ subnode.isLeaf = true;+ }+ node.children.push(subnode);+ }+ } else {+ node.isLeaf = true;+ }+ return node;+ });if (children.length === 0) {return [createDummyNode("table", parent)];}return children;};++// Map partition-table-level partitions.+const mapPartitionTableNodes = (+ database: ComposedDatabase,+ schema: SchemaMetadata,+ table: TableMetadata,+ parentPartition: TablePartitionMetadata,+ parent: SQLEditorTreeNode+) => {+ const children = parentPartition.subpartitions.map((partition) => {+ const node = mapTreeNodeByType(+ "partition-table",+ {+ database,+ schema,+ table,+ parentPartition,+ partition: partition,+ },+ parent+ );+ if (partition.subpartitions.length > 0) {+ node.isLeaf = false;+ node.children = mapPartitionTableNodes(+ database,+ schema,+ table,+ partition,+ node+ );+ } else {+ node.isLeaf = true;+ }+ return node;+ });+ return children;+};+const mapViewNodes = (database: ComposedDatabase,schema: SchemaMetadata,