This repository was archived by the owner on May 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 198
fix(ibis): add support for ClickHouse wrapper types (Nullable, Array, LowCardinality) #1359
Open
rishabh1815769
wants to merge
1
commit into
Canner:main
Choose a base branch
from
rishabh1815769:chore/fix-clickhouse-typecasting
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |
| # Date/Time Types | ||
| "date": RustWrenEngineColumnType.DATE, | ||
| "datetime": RustWrenEngineColumnType.TIMESTAMP, | ||
| "datetime64": RustWrenEngineColumnType.TIMESTAMP, | ||
| # String Types | ||
| "string": RustWrenEngineColumnType.VARCHAR, | ||
| "fixedstring": RustWrenEngineColumnType.CHAR, | ||
|
|
@@ -89,11 +90,12 @@ def get_table_list(self) -> list[Table]: | |
| ) | ||
|
|
||
| # table exists, and add column to the table | ||
| is_nullable = 'nullable(' in row["data_type"].lower() | ||
| unique_tables[schema_table].columns.append( | ||
| Column( | ||
| name=row["column_name"], | ||
| type=self._transform_column_type(row["data_type"]), | ||
| notNull=False, | ||
| notNull=not is_nullable, | ||
| description=row["column_comment"], | ||
| properties=None, | ||
| ) | ||
|
|
@@ -119,7 +121,9 @@ def _transform_column_type(self, data_type: str) -> RustWrenEngineColumnType: | |
| The corresponding RustWrenEngineColumnType | ||
| """ | ||
| # Convert to lowercase for comparison | ||
| normalized_type = data_type.lower() | ||
| # Extract inner type from wrappers like Nullable(...), Array(...), etc. | ||
| inner_type = self._extract_inner_type(data_type) | ||
| normalized_type = inner_type.lower() | ||
|
|
||
| # Use the module-level mapping table | ||
| mapped_type = CLICKHOUSE_TYPE_MAPPING.get( | ||
|
|
@@ -130,3 +134,25 @@ def _transform_column_type(self, data_type: str) -> RustWrenEngineColumnType: | |
| logger.warning(f"Unknown ClickHouse data type: {data_type}") | ||
|
|
||
| return mapped_type | ||
|
|
||
| def _extract_inner_type(self, data_type: str) -> str: | ||
| """Extract the inner type from ClickHouse type definitions. | ||
|
|
||
| This handles types wrapped in Nullable(...), Array(...), etc. | ||
|
|
||
| Args: | ||
| data_type: The ClickHouse data type string | ||
|
|
||
| Returns: | ||
| The extracted inner type string | ||
| """ | ||
|
|
||
| if '(' in data_type and data_type.endswith(')'): | ||
| paren_start = data_type.find('(') | ||
| type_name = data_type[:paren_start].lower() | ||
| inner = data_type[paren_start + 1:-1] | ||
|
|
||
| if type_name in ['nullable', 'array', 'lowcardinality']: | ||
| return self._extract_inner_type(inner) | ||
| else: | ||
| return type_name | ||
|
Comment on lines
+138
to
+158
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: _extract_inner_type is defined at module scope and can return None → runtime crash.
Replace this block with a method inside ClickHouseMetadata and guarantee a string return: - def _extract_inner_type(self, data_type: str) -> str:
- """Extract the inner type from ClickHouse type definitions.
-
- This handles types wrapped in Nullable(...), Array(...), etc.
-
- Args:
- data_type: The ClickHouse data type string
-
- Returns:
- The extracted inner type string
- """
-
- if '(' in data_type and data_type.endswith(')'):
- paren_start = data_type.find('(')
- type_name = data_type[:paren_start].lower()
- inner = data_type[paren_start + 1:-1]
-
- if type_name in ['nullable', 'array', 'lowcardinality']:
- return self._extract_inner_type(inner)
- else:
- return type_name
+ def _extract_inner_type(self, data_type: str) -> str:
+ """Extract base type from ClickHouse wrappers like Nullable(...), Array(...), LowCardinality(...)."""
+ s = (data_type or "").strip()
+ while True:
+ if "(" in s and s.endswith(")"):
+ paren_start = s.find("(")
+ type_name = s[:paren_start].strip().lower()
+ inner = s[paren_start + 1 : -1].strip()
+ if type_name in ("nullable", "array", "lowcardinality"):
+ s = inner
+ continue
+ # Non-wrapper with params, e.g., Decimal(10,2) or FixedString(16)
+ return type_name
+ # No params/wrappers; return as-is (caller lowercases)
+ return sAdditionally, add this helper inside the same class to correctly compute column nullability: def _is_column_nullable(self, data_type: str) -> bool:
s = (data_type or "").strip()
while True:
s_l = s.lower()
if s_l.startswith("nullable(") and s.endswith(")"):
return True
if s_l.startswith("lowcardinality(") and s.endswith(")"):
# unwrap and continue; LowCardinality(Nullable(T)) => nullable
s = s[s.find("(") + 1 : -1].strip()
continue
if s_l.startswith("array(") and s.endswith(")"):
# Array(Nullable(T)) does not make the column nullable
return False
return False🤖 Prompt for AI Agents |
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nullability detection is incorrect for Array(Nullable(...)); only top-level Nullable should count.
Sub-string check flags arrays-of-nullable elements as nullable columns. Handle wrapper chain: Nullable(...), LowCardinality(Nullable(...)) → nullable; Array(Nullable(...)) → not nullable at column level.
Apply this minimal change here:
Add this helper inside ClickHouseMetadata (see additional snippet below).
🤖 Prompt for AI Agents