Skip to content

Commit

Permalink
fix: display list types and map types (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
tconbeer authored Nov 10, 2023
1 parent 10ae72e commit 2fbe863
Show file tree
Hide file tree
Showing 5 changed files with 481 additions and 689 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ All notable changes to this project will be documented in this file.
### Bug Fixes

- When running multiple queries, Harlequin now activates the results tab for the last query, instead of the first one.
- Queries that return duplicate column names are now displayed correctly in the Results Viewer ([textual-fastdatatable/#26](https://github.com/tconbeer/textual-fastdatatable/issues/26)).
- Queries that return duplicate column names are now displayed correctly in the Results Viewer ([tconbeer/textual-fastdatatable#26](https://github.com/tconbeer/textual-fastdatatable/issues/26)).
- List types returned by DuckDB no longer display as `?`, but instead as `[#]`, `[s]`, etc. ([#315](https://github.com/tconbeer/harlequin/issues/315)).
- Map types returned by DuckDB now display as `{m}`, to differentiate them from structs (`{}`).

## [1.3.0] - 2023-11-06

Expand All @@ -17,7 +19,7 @@ All notable changes to this project will be documented in this file.

### Bug Fixes

- Fixes a crash that could happen when a query returned no records ([textual-fastdatatable/#19](https://github.com/tconbeer/textual-fastdatatable/issues/19)).
- Fixes a crash that could happen when a query returned no records ([tconbeer/textual-fastdatatable#19](https://github.com/tconbeer/textual-fastdatatable/issues/19)).

### Adapter API Changes

Expand Down
12 changes: 7 additions & 5 deletions plugins/harlequin_duckdb/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ class DuckDbConnection(HarlequinConnection):
# these types don't have python classes
"DECIMAL": "#.#",
"REAL": "#.#",
"LIST": "[]",
"STRUCT": "{}",
"MAP": "{}",
"MAP": "{m}",
}

UNKNOWN_TYPE = "?"
Expand Down Expand Up @@ -304,9 +303,12 @@ def _short_column_type(cls, native_type: DuckDBPyType | str) -> str:
to check class members. So we just convert to a string and split
complex types on their first paren to match our dictionary.
"""
return cls.COLUMN_TYPE_MAPPING.get(
str(native_type).split("(")[0], cls.UNKNOWN_TYPE
)
base_type = str(native_type).split("(")[0].split("[")[0]
short_base_type = cls.COLUMN_TYPE_MAPPING.get(base_type, cls.UNKNOWN_TYPE)
if str(native_type).endswith("[]"):
return f"[{short_base_type}]"
else:
return short_base_type


class DuckDbAdapter(HarlequinAdapter):
Expand Down
3 changes: 2 additions & 1 deletion src/harlequin/components/results_viewer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Dict, List, Tuple, Union

import pyarrow as pa
from rich.markup import escape
from textual.app import ComposeResult
from textual.binding import Binding
from textual.css.query import NoMatches
Expand Down Expand Up @@ -193,4 +194,4 @@ def _human_row_count(self, data: pa.Table) -> str:
return f"({total_rows:,} Records)"

def _format_column_label(self, col_name: str, col_type: str) -> str:
return f"{col_name} [{self.type_color}]{col_type}[/]"
return f"{escape(col_name)} [{self.type_color}]{escape(col_type)}[/]"
1,146 changes: 466 additions & 680 deletions tests/functional_tests/__snapshots__/test_app.ambr

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion tests/functional_tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ async def test_multiple_buffers(
assert app.editor_collection.tab_count == 2
assert app.editor_collection.active == "tab-3"
assert app.editor.text == "tab 3"
snap_results.append(await app_snapshot(app, "Tab 3 after deleting 2"))
# TODO: bring back this flaky test.
# snap_results.append(await app_snapshot(app, "Tab 3 after deleting 2"))

await pilot.press("ctrl+k")
await pilot.pause()
Expand Down

0 comments on commit 2fbe863

Please sign in to comment.