Skip to content

Commit

Permalink
feat: Add any links associated with a table to querybook descriptions (
Browse files Browse the repository at this point in the history
…#1450)

* feat: add table links field

* 3.34.0

* 3.34.0

* address comments

* fix lint

* fix lint
  • Loading branch information
zhangvi7 committed May 15, 2024
1 parent a49eb9b commit d81d582
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "querybook",
"version": "3.33.4",
"version": "3.34.0",
"description": "A Big Data Webapp",
"private": true,
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""add table links to datatable
Revision ID: 767cf0f573bd
Revises: 299e24dcfd29
Create Date: 2024-05-09 18:17:17.799678
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = '767cf0f573bd'
down_revision = '299e24dcfd29'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('data_table_information', sa.Column('table_links', sa.JSON(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('data_table_information', 'table_links')
# ### end Alembic commands ###
11 changes: 10 additions & 1 deletion querybook/server/const/metastore.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from enum import Enum
from typing import NamedTuple
from typing import NamedTuple, TypedDict

from .data_element import DataElementAssociationTuple


class DataSchema(NamedTuple):
name: str


class DataTableLink(TypedDict):
url: str
label: str


class DataTag(NamedTuple):
name: str
# below properties will be stored in tag.meta
Expand Down Expand Up @@ -75,6 +81,9 @@ class DataTable(NamedTuple):
# Custom properties
custom_properties: dict[str, str] = None

# Links associated to table
table_links: list[DataTableLink] = None

golden: bool = False
boost_score: float = 1

Expand Down
1 change: 1 addition & 0 deletions querybook/server/lib/metastore/base_metastore_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ def _create_table_table(
hive_metastore_description=table.raw_description,
partition_keys=table.partition_keys,
custom_properties=table.custom_properties,
table_links=table.table_links,
session=session,
)
if table.warnings is not None:
Expand Down
2 changes: 2 additions & 0 deletions querybook/server/logic/metastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ def create_table_information(
hive_metastore_description=None,
partition_keys=[],
custom_properties=None,
table_links=None,
commit=False,
session=None,
):
Expand All @@ -301,6 +302,7 @@ def create_table_information(
hive_metastore_description=hive_metastore_description,
column_info=column_infomation,
custom_properties=custom_properties,
table_links=table_links,
)

# The reason that we dont add description direclty in
Expand Down
2 changes: 2 additions & 0 deletions querybook/server/models/metastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class DataTableInformation(
hive_metastore_description = sql.Column(sql.Text(length=mediumtext_length))
column_info = sql.Column(sql.JSON)
custom_properties = sql.Column(sql.JSON)
table_links = sql.Column(sql.JSON)

def to_dict(self):
table_information = {
Expand All @@ -273,6 +274,7 @@ def to_dict(self):
"hive_metastore_description": self.hive_metastore_description,
"column_info": self.column_info,
"custom_properties": self.custom_properties,
"table_links": self.table_links,
}
return table_information

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ export const DataTableViewOverview: React.FC<
/>
) : null;

const tableLinksDOM = (table.table_links ?? []).map((link, index) => (
<div key={index}>
<Link to={link.url} newTab>
{link.label ?? link.url}
</Link>
<br />
</div>
));

const detailsDOM = dataTableDetailsRows
.filter((row) => table[row] != null)
.map((row) => {
Expand Down Expand Up @@ -198,6 +207,7 @@ export const DataTableViewOverview: React.FC<
const descriptionSection = (
<DataTableViewOverviewSection title="Description">
{description}
{tableLinksDOM}
</DataTableViewOverviewSection>
);

Expand Down
7 changes: 6 additions & 1 deletion querybook/webapp/const/metastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export interface IDataSchema {
metastore_id: number;
}

export interface IDataTableLink {
url: string;
label?: string;
}

export interface IDataTable {
id: number;
created_at: number;
Expand Down Expand Up @@ -74,7 +79,7 @@ export interface IDataTable {
partition_keys?: string[];
};
custom_properties?: Record<string, string | number>;

table_links?: IDataTableLink[];
schema: number;
schema_id: number;
warnings: number[];
Expand Down

0 comments on commit d81d582

Please sign in to comment.