Repository navigation
Description
Problem
The independent review of the 4.x backport #1652 (Codex, static) reported, and an offline check confirmed, statements and results that work on 4.4.0 (4.x da0590d) and fail or change after #1577 (GH-1569) and #1630 (GH-1616, commit 32fd6bb). The code is the same on master, so 5.0.0 would ship these as regressions against 4.4.0, and the 4.4.1 backport #1652 would carry them too.
- An ARRAY of an unhashable Float
TypeDecoratorfails to decode (Decode float ARRAY elements and import the compliance suite on SQLAlchemy 2.1 (GH-1569) #1577).AthenaArray(D()).result_processor(dialect, None)('["1.5"]')withclass D(TypeDecorator): impl = Float; __hash__ = Nonereturns[1.5]on 4.4.0 (SQLAlchemy 2.0.44) and raisesTypeError: unhashable type: 'D'after Decode float ARRAY elements and import the compliance suite on SQLAlchemy 2.1 (GH-1569) #1577. The processor cache is keyed byid(), but resolving the implementation callsdialect_impl(), which hashes the decorator. - NULL for a MAP or ROW with a precision-less
Numericraises (Render timedelta, MAP, and ROW values as Athena literals (GH-1616) #1630).insert(t).values(m=None)forColumn("m", AthenaMap(String, Numeric()))rendersINSERT INTO t (m) VALUES (null)on 4.4.0 and raisesCompileError: ARRAY, MAP, and ROW decimal values require explicit Numeric precisionafter Render timedelta, MAP, and ROW values as Athena literals (GH-1616) #1630, also when compiled without executing. A NULL value has no decimal to round. - ROW and MAP casts that differ only by a variant share a compiled-cache key (Render timedelta, MAP, and ROW values as Athena literals (GH-1616) #1630).
literal((1,), AthenaStruct(("x", String())))andliteral((1,), AthenaStruct(("x", String().with_variant(Integer(), "awsathena"))))have equal cache keys (the field key uses_static_cache_key, which omits the variant:pyathena/sqlalchemy/struct.py), but now render different SQL:CAST(ROW(1) AS ROW(x VARCHAR))andCAST(ROW(1) AS ROW(x INTEGER)). With one engine, the second statement can reuse the first's compiled SQL and bind processors. On 4.4.0 the keys were equal as well, but both rendered(1). Check MAP key and value types the same way. - A ROW comparison now rounds a bound
Decimalbefore comparing (Render timedelta, MAP, and ROW values as Athena literals (GH-1616) #1630; behavior change).r == (Decimal("1.234"), "x")forrofROW(n DECIMAL(5, 2), tag VARCHAR)rendersr = (DECIMAL '1.234', 'x')on 4.4.0 andr = CAST(ROW(DECIMAL '1.234', 'x') AS ROW(n DECIMAL(5, 2), tag VARCHAR))after Render timedelta, MAP, and ROW values as Athena literals (GH-1616) #1630, so a stored(1.23, 'x')now matches. Decide whether this follows the declared type as intended (as==casts other values) or should keep the value's precision.
Reproduction
Offline, on 4.x da0590d and on the backport head dcee17f (= master's code), SQLAlchemy 2.0.44 and 2.1.9, with the dialect AthenaDialect(). The outputs are in the review record on #1652.
Environment
master after #1577 (4c971ae) and #1630 (bb0a896); 4.x with #1652. SQLAlchemy 2.0.44 to 2.1.9.
Proposed fix (optional)
Fix 1 to 3 on master (resolve the implementation of an unhashable decorator without hashing it; skip the precision check for NULL; include the full declared types, variants included, in the cache key of MAP and ROW). Decide 4. Then add the fixes to the 4.x backport #1652 before it is marked Ready.
Activity