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

feat: Visualize complex Hive column types v2 #1091

Merged
merged 1 commit into from
Jan 10, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.15.7",
"version": "3.16.0",
"description": "A Big Data Webapp",
"private": true,
"scripts": {
Expand Down
258 changes: 258 additions & 0 deletions querybook/webapp/__tests__/lib/utils/complex-types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
import { parseType, prettyPrintType } from 'lib/utils/complex-types';

test('simple type', () => {
expect(parseType('column', 'string')).toEqual({
key: 'column',
type: 'string',
});
});

test('truncated type', () => {
expect(
parseType(
'column',
'struct<date:struct<year:int,month:int,day:int>,hour:int,minute:int,second:int,'
)
).toEqual({
key: 'column',
type: 'struct<date:struct<year:int,month:int,day:int>,hour:int,minute:int,second:int,',
});

// Truncated, but coincidentally matches the regex
expect(parseType('column', 'struct<date:struct<hour:int>')).toEqual({
key: 'column',
type: 'struct<date:struct<hour:int>',
});
});

test('malformed struct type', () => {
expect(parseType('column', 'STRUCT <id:string>')).toEqual({
key: 'column',
type: 'STRUCT <id:string>',
});
});

test('complex type', () => {
expect(parseType('column', 'STRUCT<id:string>')).toEqual({
key: 'column',
type: 'STRUCT<id:string>',
children: [
{
key: 'id',
type: 'string',
},
],
});

expect(
parseType(
'column',
'struct<date:struct<year:int,month:int,day:int>,hour:int,minute:int,second:int,timeZoneId:string>'
)
).toEqual({
key: 'column',
type: 'struct<date:struct<year:int,month:int,day:int>,hour:int,minute:int,second:int,timeZoneId:string>',
children: [
{
key: 'date',
type: 'struct<year:int,month:int,day:int>',
children: [
{ key: 'year', type: 'int' },
{ key: 'month', type: 'int' },
{ key: 'day', type: 'int' },
],
},
{ key: 'hour', type: 'int' },
{ key: 'minute', type: 'int' },
{ key: 'second', type: 'int' },
{ key: 'timeZoneId', type: 'string' },
],
});

expect(
parseType(
'column',
'array<struct<size:struct<width:int,height:int,isAspectRatio:boolean>>>'
)
).toEqual({
key: 'column',
type: 'array<struct<size:struct<width:int,height:int,isAspectRatio:boolean>>>',
children: [
{
key: '<element>',
type: 'struct<size:struct<width:int,height:int,isAspectRatio:boolean>>',
children: [
{
key: 'size',
type: 'struct<width:int,height:int,isAspectRatio:boolean>',
children: [
{ key: 'width', type: 'int' },
{ key: 'height', type: 'int' },
{ key: 'isAspectRatio', type: 'boolean' },
],
},
],
},
],
});

expect(
parseType(
'column',
'struct<purchasePath:string,resultToken:string,sessionId:string,site:struct<eapid:bigint,tpid:bigint>,tests:array<struct<bucketValue:string,experimentId:string,instanceId:string>>,user:struct<guid:string,tuid:string>>'
)
).toEqual({
key: 'column',
type: 'struct<purchasePath:string,resultToken:string,sessionId:string,site:struct<eapid:bigint,tpid:bigint>,tests:array<struct<bucketValue:string,experimentId:string,instanceId:string>>,user:struct<guid:string,tuid:string>>',
children: [
{ key: 'purchasePath', type: 'string' },
{ key: 'resultToken', type: 'string' },
{ key: 'sessionId', type: 'string' },
{
key: 'site',
type: 'struct<eapid:bigint,tpid:bigint>',
children: [
{ key: 'eapid', type: 'bigint' },
{ key: 'tpid', type: 'bigint' },
],
},
{
key: 'tests',
type: 'array<struct<bucketValue:string,experimentId:string,instanceId:string>>',
children: [
{
key: '<element>',
type: 'struct<bucketValue:string,experimentId:string,instanceId:string>',
children: [
{ key: 'bucketValue', type: 'string' },
{ key: 'experimentId', type: 'string' },
{ key: 'instanceId', type: 'string' },
],
},
],
},
{
key: 'user',
type: 'struct<guid:string,tuid:string>',
children: [
{ key: 'guid', type: 'string' },
{ key: 'tuid', type: 'string' },
],
},
],
});

expect(parseType('column', 'map<string,float>')).toEqual({
key: 'column',
type: 'map<string,float>',
children: [
{
key: '<key>',
type: 'string',
},
{
key: '<value>',
type: 'float',
},
],
});

expect(
parseType(
'column',
'map<string,uniontype<string,int,bigint,float,double,struct<year:int,month:int,day:int>>>'
)
).toEqual({
key: 'column',
type: 'map<string,uniontype<string,int,bigint,float,double,struct<year:int,month:int,day:int>>>',
children: [
{
key: '<key>',
type: 'string',
},
{
key: '<value>',
type: 'uniontype<string,int,bigint,float,double,struct<year:int,month:int,day:int>>',
children: [
{ key: '<element>', type: 'string' },
{ key: '<element>', type: 'int' },
{ key: '<element>', type: 'bigint' },
{ key: '<element>', type: 'float' },
{ key: '<element>', type: 'double' },
{
key: '<element>',
type: 'struct<year:int,month:int,day:int>',
children: [
{ key: 'year', type: 'int' },
{ key: 'month', type: 'int' },
{ key: 'day', type: 'int' },
],
},
],
},
],
});
});

test('prettyPrintType', () => {
expect(prettyPrintType('map<string,string>')).toEqual(`map<
string,
string
>`);

expect(
prettyPrintType(
'struct<ids:array<string>,data:uniontype<int,float,string>>'
)
).toEqual(`struct<
ids: array<
string
>,
data: uniontype<
int,
float,
string
>
>`);

expect(
prettyPrintType(
'struct<ids:array<string>,comment:string,data:map<int,int>>'
)
).toEqual(`struct<
ids: array<
string
>,
comment: string,
data: map<
int,
int
>
>`);

expect(
prettyPrintType(
'map<struct<ids:array<string>,comment:string,data:map<int,int>>,struct<data:array<string>,event:map<int,int>>>'
)
).toEqual(`map<
struct<
ids: array<
string
>,
comment: string,
data: map<
int,
int
>
>,
struct<
data: array<
string
>,
event: map<
int,
int
>
>
>`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,20 @@
}
}
}

.DataTableColumnCardNestedType {

.column-type {
min-width: 80px;
word-break: break-all;
}

.nested-indent {
margin-left: 32px;
}

.expand-icon {
margin-left: -32px;
padding: 0 8px;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { ContentState } from 'draft-js';
import * as React from 'react';
import React, { useMemo } from 'react';

import { DataTableColumnStats } from 'components/DataTableStats/DataTableColumnStats';
import { IDataColumn } from 'const/metastore';
import { useToggleState } from 'hooks/useToggleState';
import { parseType } from 'lib/utils/complex-types';
import { Card } from 'ui/Card/Card';
import { EditableTextField } from 'ui/EditableTextField/EditableTextField';
import { Icon } from 'ui/Icon/Icon';
import { KeyContentDisplay } from 'ui/KeyContentDisplay/KeyContentDisplay';
import { AccentText, StyledText } from 'ui/StyledText/StyledText';

import { DataTableColumnCardNestedType } from './DataTableColumnCardNestedType';

import './DataTableColumnCard.scss';

interface IProps {
Expand All @@ -23,7 +27,8 @@ export const DataTableColumnCard: React.FunctionComponent<IProps> = ({
column,
updateDataColumnDescription,
}) => {
const [expanded, setExpanded] = React.useState(false);
const [expanded, , toggleExpanded] = useToggleState(false);
const parsedType = useMemo(() => parseType('', column.type), [column.type]);

const userCommentsContent = (
<EditableTextField
Expand All @@ -37,7 +42,7 @@ export const DataTableColumnCard: React.FunctionComponent<IProps> = ({
<Card key={column.id} alignLeft>
<div
className="DataTableColumnCard-top horizontal-space-between"
onClick={() => setExpanded(!expanded)}
onClick={() => toggleExpanded()}
aria-label={
expanded ? 'click to collapse' : 'click to expand'
}
Expand All @@ -53,6 +58,13 @@ export const DataTableColumnCard: React.FunctionComponent<IProps> = ({
</div>
{expanded ? (
<div className="mt16">
{parsedType.children && (
<KeyContentDisplay keyString="Type Detail">
<DataTableColumnCardNestedType
complexType={parsedType}
/>
</KeyContentDisplay>
)}
{column.comment && (
<KeyContentDisplay keyString="Definition">
{column.comment}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as React from 'react';

import { ComplexType } from 'lib/utils/complex-types';
import { IconButton } from 'ui/Button/IconButton';
import { AccentText, StyledText } from 'ui/StyledText/StyledText';

interface IDataTableColumnCardNestedTypeProps {
complexType: ComplexType;
}
export const DataTableColumnCardNestedType: React.FunctionComponent<
IDataTableColumnCardNestedTypeProps
> = ({ complexType }) => {
const hasChildren = complexType.children?.length > 0;
const [expanded, setExpanded] = React.useState(false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can use useToggleState then you don't need () => setExpanded(!expanded)


const rowProps: React.HTMLAttributes<HTMLDivElement> = {
className: 'flex-row',
};

if (hasChildren) {
rowProps['onClick'] = () => setExpanded(!expanded);
rowProps['aria-label'] = expanded
? 'click to collapse'
: 'click to expand';
rowProps['data-balloon-pos'] = 'down-left';
}

return (
<div className="DataTableColumnCardNestedType">
<div {...rowProps}>
{hasChildren && (
<IconButton
icon={expanded ? 'Minus' : 'Plus'}
size="16"
noPadding={true}
className="expand-icon"
/>
)}
<AccentText weight="extra" className="mr12">
{complexType.key}
</AccentText>
<StyledText
color="light"
className={`column-type ${!hasChildren && 'nested-indent'}`}
>
{complexType.type}
</StyledText>
</div>
{hasChildren &&
expanded &&
complexType.children.map((child) => (
<div className="nested-indent m16" key={child.key}>
<DataTableColumnCardNestedType complexType={child} />
</div>
))}
</div>
);
};
Loading