-
Notifications
You must be signed in to change notification settings - Fork 237
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
Conversation
I've extended the length of In the event that a column type is still longer than the new limit, everything degrades gracefully and the partial type string will be short as before. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me overall, thanks for the update!
Also could you update the version in package.json?
if (!matches || matches.length < 3) { | ||
return { key, type }; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this to handle the truncated case?
- could you add a test case for it?
- what if the truncated type also matches the regex? like
struct<date:struct<hour:int>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a case for non-matching truncated, and the 2nd scenario where the truncated type matches the regex accidentally. I've addressed this by checking the depth
field to ensure we've closed all <>
pairs
} | ||
*/ | ||
export function parseType(key: string, type: string): ComplexType { | ||
const regex = /(struct|array|map|uniontype)<(.*)>/i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it need to handle spaces? like struct <...>
, struct<year : int, day : int>
?
also should it match the start and end /^ ... $/
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left spaces out intentionally as I haven't seen that in the wild. If needed it probably wouldn't be too hard, but didn't want to add unnecessary complexity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added start/end to the regex.
if (char === '<') { | ||
prettyString += '<\n'; | ||
depth += 1; | ||
prettyString += ' '.repeat(depth); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you use a variable for the 2 spaces ' '
?
querybook/webapp/components/DataTableViewColumn/DataTableColumnCard.tsx
Outdated
Show resolved
Hide resolved
{complexType.type} | ||
</StyledText> | ||
<AccentText weight="extra">{complexType.key}</AccentText> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of displaying it as type key
, I'd prefer to have it same as the ColumnRow
, which is key type
, which I think is more reasonable.
645b79f
to
a030692
Compare
@@ -24,6 +26,7 @@ export const DataTableColumnCard: React.FunctionComponent<IProps> = ({ | |||
updateDataColumnDescription, | |||
}) => { | |||
const [expanded, setExpanded] = React.useState(false); | |||
const parsedType = parseType('', column.type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memo this?
@@ -71,3 +81,57 @@ export const DataTableColumnCard: React.FunctionComponent<IProps> = ({ | |||
</div> | |||
); | |||
}; | |||
|
|||
interface IDataTableColumnCardNestedTypeProps { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you separate this into another file?
IDataTableColumnCardNestedTypeProps | ||
> = ({ complexType }) => { | ||
const hasChildren = complexType.children?.length > 0; | ||
const [expanded, setExpanded] = React.useState(false); |
There was a problem hiding this comment.
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 hasChildren = complexType.children?.length > 0; | ||
const [expanded, setExpanded] = React.useState(false); | ||
|
||
const rowProps = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const rowProps: React.HTMLAttributes = {}
</div> | ||
{hasChildren && | ||
expanded && | ||
complexType.children?.map((child) => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.map
is sufficient
'struct<ids:array<string>,data:uniontype<int,float,string>>' | ||
) | ||
).toEqual(`struct< | ||
ids:array< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add a space after :
to make it easier to read?
@@ -53,6 +56,7 @@ export const TablePanelView: React.FunctionComponent<ITablePanelViewProps> = ({ | |||
onClick={onColumnRowClick.bind(null, col.id)} | |||
name={col.name} | |||
type={col.type} | |||
typeChildren={parseType('', col.type).children} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memo this?
actually, the parsing can be down in ColumnRow since col.type is passed as a prop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ColumnRow takes typeChildren
because it only parses once, then recursively output nested rows. I've moved the parseType
call down and inside useMemo
, where it returns either the passed typeChildren
or calculates it.
e5e26b5
to
963482e
Compare
Rebased to resolve conflicts / squashed the commits. |
This is an alternate version of #1072, replacing the JSON viewer with a more natural-looking nested type drilldown. I've also addressed some issues with the original version.
Compared to #1072, the parser is more consistent and does a better job of handling certain types than before. To support the nesting, it always creates nodes with optional children. Now
array<>
anduniontype<>
types will create placeholder<element>
nodes underneath them, andmap<>
types create placeholder<key>
and<value>
nodes.Complex type parsing is case-insensitive (e.g. struct vs STRUCT) but otherwise case is preserved.
There are three main features: