Skip to content

Types: Resolve reflected geo and array types, and name unresolvable ones - #301

Open
florinutz wants to merge 1 commit into
flo/292-numeric-typefrom
flo/295-type-map
Open

florinutz wants to merge 1 commit into
flo/292-numeric-typefrom
flo/295-type-map

Conversation

@florinutz

@florinutz florinutz commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Reflecting a column whose CrateDB type the dialect doesn't know gave it the abstract UserDefinedType. Reading worked, but compiling DDL from the reflected table crashed without naming the column or the type:

AttributeError: 'UserDefinedType' object has no attribute 'get_col_spec'

sys.summits reproduces it: coordinates is a geo_point, and Geopoint was never registered in the type map.

Closes #295.

Stacked on #300 (flo/292-numeric-type), since both touch TYPES_MAP and the type compiler, and the numeric_array derivation here needs the numeric entry #300 adds.

Fix

  • Unknown types reflect as UnresolvedType, which carries the CrateDB type name. The column still reads, and compiling it fails with that name:

    CompileError: (in table 'pg_am', column 'amhandler'):
    Unable to represent CrateDB type 'regproc' in SQLAlchemy
    

    The type is exported, so callers can check isinstance(column.type, UnresolvedType) and skip the column. NullType, which the issue suggests, would report "did you forget to specify a type" and name nothing.

  • geo_point and geo_shape map to the existing Geopoint and Geoshape.

  • Array types are derived from their element (<element>_array) instead of a fixed list of sixteen, so e.g. timestamp without time zone_array resolves too. object_array keeps its entry for ObjectArray. Arrays of arrays and arrays of unresolved types stay unresolved.

Out of scope: reflection still drops type parameters, so a reflected VARCHAR(10) comes back unbounded.

Tests

tests/reflection_test.py, new: the array form of every mapped type, the refusal for unresolvable scalars, elements and nested arrays, and a live reflection of sys.summits.

@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 355fc83a-4e97-430d-b4c7-fb61963847e3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Unknown types reflect as `UnresolvedType` rather than `NullType`, which the
issue proposed, so the error carries the CrateDB type name.
@florinutz florinutz changed the title Report the CrateDB type reflection could not resolve Types: Resolve reflected geo and array types, and name unresolvable ones Sep 11, 2026
@florinutz
florinutz marked this pull request as ready for review September 11, 2026 13:33
@florinutz
florinutz added this pull request to stack #306 September 11, 2026 13:59

@bgunebakan bgunebakan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you! I've reviewed that with NUMERIC PR because there is some places that touches both implementation. I've added some comments.

resolved = self._lookup_type(type_)
if resolved is None:
# Debug level: reflecting `pg_catalog` alone leaves twenty-odd columns unresolved.
log.debug("Unable to resolve CrateDB type: %s", type_)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need debug log?

"numeric": sqltypes.NUMERIC,
"float_vector": FloatVector,
"geo_point": Geopoint,
"geo_shape": Geoshape,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Issue ticket also mentions ip and character, they are also unmapped with geo fields. Could you add them to map for covering all types mentioned on ticket?

if not type_.endswith(ARRAY_SUFFIX):
return None
element_name = type_[: -len(ARRAY_SUFFIX)]
# SQLAlchemy's `ARRAY` cannot hold an array.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The comment says "SQLAlchemy's ARRAY cannot hold an array", but it can. What is the reason of the comment?

Comment thread tests/reflection_test.py
Comment on lines +11 to +12
# `pg_catalog` reports `regproc` for function references, which no table can declare.
UNRESOLVABLE = "regproc"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

regproc drives five parametrised cases, so if it's ever mapped they quietly stop testing what they say. A name the server can never report would be better

Suggested change
# `pg_catalog` reports `regproc` for function references, which no table can declare.
UNRESOLVABLE = "regproc"
UNRESOLVABLE = "unresolvable_cratedb_type"

Comment thread tests/reflection_test.py
for record in caplog.records
if record.name == "sqlalchemy_cratedb.dialect"
]
assert messages == ["Unable to resolve CrateDB type: {0}".format(data_type)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any future debug line on this logger would breaks the test.

Suggested change
assert messages == ["Unable to resolve CrateDB type: {0}".format(data_type)]
assert "Unable to resolve CrateDB type: {0}".format(data_type) in messages

Comment thread CHANGES.md
serializes them as strings, storing every digit instead of rounding to float
- Types: Added `numeric` and `numeric_array` to the reflected type map, where
they previously resolved to an abstract type that could not be compiled
- Reflection: Fixed columns of a CrateDB type the dialect cannot represent

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reflection: is a new label, the file has used Types:, Compiler: and Dialect:. I'd keep same labels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unknown column types fall back to abstract UserDefinedType

2 participants