adbc_scan_table: fix COUNT(*) on tables whose first column is not numeric - #14
Merged
rustyconover merged 3 commits intoAug 27, 2026
Conversation
…NT(*) on string-first tables) DuckDB asks for COLUMN_IDENTIFIER_ROW_ID alone for COUNT(*); the scan fell back to SELECT * and mapped Arrow column 0 onto the BIGINT row-id output, failing with e.g. "Could not convert string 'SYSTEM' to INT64" whenever the table's first column is not numeric (Db2 SYSCAT.TABLES, SYSCAT.SCHEMATA). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> (cherry picked from commit a844055)
Covers the fix for Query-farm#14 through the ATTACH scan path (the path DuckDB actually uses for COUNT(*) on a catalog-qualified table -- unlike a direct adbc_scan_table(...) call, which the optimizer projects a real column for even when the query only needs a row count, so it never hits the buggy fallback). Verified this reproduces the original failure (Conversion Error: Could not convert string 'alpha' to INT64) against the pre-fix code, and passes once the fix in this PR is applied. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B5cXMpuhzmAxLF41Nt2T4L
Contributor
Author
|
🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
SELECT COUNT(*) FROM attached_db.schema.tablefails with e.g.whenever the table's first column is not numeric (every Db2
SYSCAT.*table starts withTENANTNAME, for example). ForCOUNT(*)DuckDB asks the table function for onlyCOLUMN_IDENTIFIER_ROW_ID;AdbcScanTableInitGlobalsees no valid column ids and falls back toSELECT *, whileAdbcScanTableInitLocalmaps Arrow column 0 onto the (BIGINT) row-id output slot. When column 0 happens to be numeric the count is right by accident; otherwise the cast fails.Fix
When no real columns are requested but a table name is known, scan
SELECT 1 FROM <qualified table>instead ofSELECT *. That is cheap for the remote database (no wide rows shipped), always yields an INT column for the row-id slot, and produces exactly the row count. Filter pushdown is applied afterwards as before, soCOUNT(*) ... WHERE ...still pushes the predicate down. The original fallback is kept for the no-table-name (raw query) case.Repro
Any ADBC source with a string-first table, e.g. with
adbc-driver-db2:Not built locally — please run the extension test build.
🤖 Generated with Claude Code