Fix: ALL_TAB_COLUMNS view implementation#1336
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds an Oracle-compatible catalog view SYS.ALL_TAB_COLUMNS that exposes per-column metadata derived from PostgreSQL catalogs, plus a regression test and expected-output section that validates the view's projection and asserts an invalid-identifier error for COLLATION_NAME. ChangesSYS.ALL_TAB_COLUMNS View Implementation
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@contrib/ivorysql_ora/sql/ora_sysview.sql`:
- Around line 216-260: The current test mixes a negative "invalid identifier"
check for COLLATION_NAME into the positive assertion that queries
SYS.ALL_TAB_COLUMNS for TEST_ALL_TAB_COLUMNS, so the whole block fails to
validate real column data; remove COLLATION_NAME from the SELECT list in the
successful assertion (the SELECT that lists COLUMN_ID, DATA_TYPE, NULLABLE,
DATA_DEFAULT, etc. and ends with ORDER BY COLUMN_ID) so it returns a valid
result set, and add a separate negative test that intentionally selects
COLLATION_NAME from SYS.ALL_TAB_COLUMNS (targeting TABLE_NAME =
'TEST_ALL_TAB_COLUMNS') asserting it raises an invalid identifier error.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 26e7e03a-d42f-4085-bed8-f9c50ff2662c
📒 Files selected for processing (3)
contrib/ivorysql_ora/expected/ora_sysview.outcontrib/ivorysql_ora/sql/ora_sysview.sqlcontrib/ivorysql_ora/src/sysview/sysview--1.0.sql
There was a problem hiding this comment.
🧹 Nitpick comments (1)
contrib/ivorysql_ora/expected/ora_sysview.out (1)
345-403: 🏗️ Heavy liftAdd positive test case to validate ALL_TAB_COLUMNS view returns correct column metadata.
The current test intentionally demonstrates that
COLLATION(a PostgreSQL reserved word) causes a syntax error when used unquoted. However, this negative test alone does not verify that the view functions correctly. The test should include at least one successful query—either without theCOLLATIONcolumn or with it quoted—to validate that the view:
- Discovers the test table
- Returns correct column metadata (COLUMN_ID, DATA_TYPE, DATA_PRECISION, NULLABLE, etc.)
- Properly maps Oracle-compatible types (VARCHAR2, NUMERIC, DATE)
Without a positive test case, there is no evidence that the view implementation produces the expected results.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@contrib/ivorysql_ora/expected/ora_sysview.out` around lines 345 - 403, Add a positive test that queries SYS.ALL_TAB_COLUMNS for the created TEST_ALL_TAB_COLUMNS table to verify it returns expected metadata (e.g., COLUMN_ID, COLUMN_NAME, DATA_TYPE, DATA_PRECISION, NULLABLE, DATA_DEFAULT) and correct type mappings for VARCHAR2/NUMERIC/DATE; locate the current failing negative test that selects COLLATION from SYS.ALL_TAB_COLUMNS and either remove the unquoted COLLATION reference or replace it with a quoted "COLLATION" (or simply omit that column) in the SELECT so the query succeeds, then add assertions that the returned rows include the three columns NAME, AGE, CREATE_TIME with correct DATA_TYPE and precision values for TEST_ALL_TAB_COLUMNS.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@contrib/ivorysql_ora/expected/ora_sysview.out`:
- Around line 345-403: Add a positive test that queries SYS.ALL_TAB_COLUMNS for
the created TEST_ALL_TAB_COLUMNS table to verify it returns expected metadata
(e.g., COLUMN_ID, COLUMN_NAME, DATA_TYPE, DATA_PRECISION, NULLABLE,
DATA_DEFAULT) and correct type mappings for VARCHAR2/NUMERIC/DATE; locate the
current failing negative test that selects COLLATION from SYS.ALL_TAB_COLUMNS
and either remove the unquoted COLLATION reference or replace it with a quoted
"COLLATION" (or simply omit that column) in the SELECT so the query succeeds,
then add assertions that the returned rows include the three columns NAME, AGE,
CREATE_TIME with correct DATA_TYPE and precision values for
TEST_ALL_TAB_COLUMNS.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 36dd0f16-9c8d-4eec-88a6-5936b91bb3ec
📒 Files selected for processing (3)
contrib/ivorysql_ora/expected/ora_sysview.outcontrib/ivorysql_ora/sql/ora_sysview.sqlcontrib/ivorysql_ora/src/sysview/sysview--1.0.sql
🚧 Files skipped from review as they are similar to previous changes (2)
- contrib/ivorysql_ora/sql/ora_sysview.sql
- contrib/ivorysql_ora/src/sysview/sysview--1.0.sql
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@ora_sysview.sql`:
- Around line 24-26: The SELECT from ALL_PROCEDURES filtering OBJECT_NAME =
'PROC_DEL_TB' OR 'FUNC_AUTHID' returns multiple rows without a deterministic
order; update that query (and the other dictionary-view query referenced later)
to include an explicit ORDER BY (for example ORDER BY OBJECT_NAME, OBJECT_TYPE
or another stable key) so ora_sysview.out is deterministic; locate the SELECT
against ALL_PROCEDURES and the similar query around the later occurrence and
append a suitable ORDER BY clause to each.
- Around line 258-260: The query against SYS.ALL_TAB_COLUMNS is only filtering
TABLE_NAME and can return same-named tables from other schemas; update the WHERE
clause that queries SYS.ALL_TAB_COLUMNS for 'TEST_ALL_TAB_COLUMNS' to also
filter by OWNER (e.g., AND OWNER = '<EXPECTED_SCHEMA>' or AND OWNER = USER/
SYS_CONTEXT('USERENV','CURRENT_SCHEMA')) so the test only inspects the intended
schema; leave the ORDER BY COLUMN_ID as-is.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0a3afbb2-8716-4df1-8d19-24e853314ff7
📒 Files selected for processing (2)
ora_sysview.outora_sysview.sql
✅ Files skipped from review due to trivial changes (1)
- ora_sysview.out
2452af1 to
d662428
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@contrib/ivorysql_ora/expected/ora_sysview.out`:
- Around line 345-402: The ALL_TAB_COLUMNS test returns no rows because the
WHERE clause compares OWNER = CURRENT_USER while the view projects OWNER via
sys.ora_case_trans(...), causing a case-mismatch; update the test's WHERE clause
to use the same transformation as the view (i.e., WHERE OWNER =
SYS.ORA_CASE_TRANS(CURRENT_USER::VARCHAR2)) so the OWNER filter matches and the
SELECT from SYS.ALL_TAB_COLUMNS for TEST_ALL_TAB_COLUMNS returns the expected 4
rows to validate DATA_TYPE, DATA_LENGTH, COLUMN_ID ordering, etc.; change the
predicate in the test that references OWNER/CURRENT_USER to use
SYS.ORA_CASE_TRANS(CURRENT_USER::VARCHAR2) and regenerate the expected output.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 592fb916-9913-4f36-81df-9607b3ea3777
📒 Files selected for processing (2)
contrib/ivorysql_ora/expected/ora_sysview.outcontrib/ivorysql_ora/sql/ora_sysview.sql
🚧 Files skipped from review as they are similar to previous changes (1)
- contrib/ivorysql_ora/sql/ora_sysview.sql
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@contrib/ivorysql_ora/sql/ora_sysview.sql`:
- Line 236: The test/view is flaky because it selects the raw LAST_ANALYZED
timestamp; change the expectation to a deterministic assertion instead of
snapshotting the timestamp: update the code that emits or asserts LAST_ANALYZED
so it checks nullness (e.g., assert LAST_ANALYZED IS NULL or IS NOT NULL) or
returns a stable token (e.g., 'NULL'/'NOT NULL') rather than the real timestamp;
locate occurrences of LAST_ANALYZED in the SQL/view and replace the raw column
output with a deterministic null-check or token.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 01d03d4c-2bd1-48a8-8822-d8debf85b3cc
📒 Files selected for processing (2)
contrib/ivorysql_ora/expected/ora_sysview.outcontrib/ivorysql_ora/sql/ora_sysview.sql
There was a problem hiding this comment.
Actionable comments posted: 7
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@contrib/ivorysql_ora/src/sysview/sysview--1.0.sql`:
- Around line 1492-1496: The CASE that computes char_used is incorrect: remove
the PostgreSQL internal 'char' token from the first WHEN list and make varchar
and bpchar map consistently (either both to NULL or both to the same value);
specifically, update the CASE over pg_type.typname used to produce char_used so
that bpchar (Oracle CHAR) stays in the 'C' branch, the
oracharchar/oracharbyte/oravarcharchar/oravarcharbyte/orachar* variants remain
split into 'C'/'B' as appropriate, and either drop varchar from the 'B' branch
so both varchar and bpchar fall through to NULL, or place varchar with bpchar
into the same branch—edit the CASE that selects AS char_used accordingly.
- Around line 1479-1483: The scalar subquery that defines avg_col_len reads
pg_statistic directly and duplicates the already-joined pg_stats; replace that
correlated subquery with the avg_width column from the existing LEFT JOIN to
pg_stats (use pg_stats.avg_width cast/alias as needed for numeric and preserve
NULL behavior), remove the pg_statistic lookup in the avg_col_len expression,
and ensure the view continues to expose avg_col_len using the joined pg_stats
value (refer to avg_col_len, pg_stats, and avg_width to locate and update the
code).
- Around line 1425-1426: The DATA_LENGTH expression for plain varchar/bpchar
currently returns pg_attribute.atttypmod - 4 (a character count); change it to
return the byte length by multiplying (pg_attribute.atttypmod - 4) by
pg_encoding_max_length(pg_database.encoding) (the same approach used in the
oracharchar/oravarcharchar branch) so DATA_LENGTH represents bytes, not
characters, or alternatively document the semantic change if you intentionally
want characters; update the WHEN branch that checks pg_type.typname IN
('varchar','bpchar') to use the encoding-aware multiplication.
- Line 1394: The OWNER column is using pg_get_userbyid(pg_class.relowner) (the
role name) but should use the schema name from pg_namespace; replace the
expression
sys.ora_case_trans(pg_get_userbyid(pg_class.relowner)::varchar2)::varchar2(128)
AS owner with an expression that uses pg_namespace.nspname passed through
sys.ora_case_trans (e.g.,
sys.ora_case_trans(pg_namespace.nspname::varchar2)::varchar2(128) AS owner) so
OWNER reflects the schema name rather than the owning role.
- Line 1397: Replace the direct use of pg_attribute.attnum for COLUMN_ID with a
dense sequential ordinal computed per table: compute COLUMN_ID as a row-number
over the non-dropped attributes partitioned by the table (use
pg_attribute.attrelid) and ordered by pg_attribute.attnum so dropped columns
(attisdropped) do not create gaps; update the column expression that currently
references pg_attribute.attnum::numeric to use ROW_NUMBER() OVER (PARTITION BY
pg_attribute.attrelid ORDER BY pg_attribute.attnum) (or equivalent) and ensure
the existing attisdropped filter is applied.
- Line 1528: The ALL_TAB_COLUMNS view currently filters pg_class.relkind IN
('r','v','m','p','f') which lets partition child tables (relkind='r' and
relispartition=true) produce duplicate rows; modify the view's WHERE clause to
add AND NOT pg_class.relispartition to exclude partition children while keeping
partitioned parents, updating the definition of the ALL_TAB_COLUMNS view (search
for the SELECT that references pg_class.relkind) and then add a regression test
that creates a partitioned table fixture and asserts the view returns exactly
one row per logical column for the parent table.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 185ca33a-3c3e-4891-ae85-9586a7bdaf72
📒 Files selected for processing (1)
contrib/ivorysql_ora/src/sysview/sysview--1.0.sql
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@contrib/ivorysql_ora/src/sysview/sysview--1.0.sql`:
- Around line 1488-1495: The CASE that computes char_col_decl_length wrongly
multiplies pg_attribute.atttypmod-derived character counts by
pg_catalog.pg_encoding_max_length(), converting character counts to bytes;
update the logic in the char_col_decl_length expression (the CASE referencing
pg_type.typname, pg_attribute.atttypmod and
pg_catalog.pg_encoding_max_length(current_database())) to remove the
multiplication for CHAR-semantics types so it returns the declared length in
character units (native units), leaving any byte-size computation for
DATA_LENGTH instead; apply the same fix to the analogous expression earlier in
the file that uses the same pattern near the other CASE at lines ~1438–1439.
- Line 1486: Replace the current_setting('server_encoding')::varchar2(44) AS
character_set_name expression with a CASE that returns 'CHAR_CS' for character
types, 'NCHAR_CS' for national character types and NULL otherwise, reusing the
same type-checking logic already used elsewhere in this file (the expression
testing a.atttypid/a.atttypmod or t.typcategory/format_type). Concretely, locate
the existing type-checking expressions (used for COLLATION_NAME or similar
columns) and copy that pattern into a CASE WHEN ... THEN 'CHAR_CS' WHEN ... THEN
'NCHAR_CS' ELSE NULL END AS character_set_name, replacing the current_setting
call.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: de6e5ca6-3499-4103-9b97-5212a8ac5287
📒 Files selected for processing (2)
contrib/ivorysql_ora/expected/ora_sysview.outcontrib/ivorysql_ora/src/sysview/sysview--1.0.sql
🚧 Files skipped from review as they are similar to previous changes (1)
- contrib/ivorysql_ora/expected/ora_sysview.out
| NULL::numeric AS num_buckets, | ||
| pg_stat_get_last_analyze_time(pg_class.oid) AS last_analyzed, | ||
| NULL::numeric AS sample_size, | ||
| pg_catalog.current_setting('server_encoding')::varchar2(44) AS character_set_name, |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Oracle ALL_TAB_COLUMNS CHARACTER_SET_NAME semantics for CHAR, VARCHAR2, CLOB, NCHAR, NVARCHAR2, NCLOB, and non-character columns
💡 Result:
In Oracle Database, the ALL_TAB_COLUMNS view (and related views like ALL_TAB_COLS) includes the CHARACTER_SET_NAME column, which indicates the character set semantics for character-type columns [1][2][3][4]. It is populated only for columns of character data types: CHAR, VARCHAR2, NCHAR, NVARCHAR2. For these, it shows 'CHAR_CS' for database character set columns (CHAR, VARCHAR2) or 'NCHAR_CS' for national character set columns (NCHAR, NVARCHAR2) [1][2][3][4]. For LOB types: - CLOB uses the database character set (CHAR_CS) [5][6][7][8]. - NCLOB uses the national character set (NCHAR_CS) [5][6][7]. For non-character columns (e.g., NUMBER, DATE, BLOB), CHARACTER_SET_NAME is NULL, as it does not apply (analogous to CHAR_USED being NULL for non-character types) [9][4][1]. Note: While CLOB/NCLOB have character storage, official data dictionary docs describe CHARACTER_SET_NAME in the context of CHAR/VARCHAR2/NCHAR/NVARCHAR2, with no explicit mention for LOBs, but semantics follow their respective character sets [1][3][4]. In practice, queries on ALL_TAB_COLUMNS show CHAR_CS for CLOB and NCHAR_CS for NCLOB where populated [10].
Citations:
- 1: https://docs.oracle.com/en/database/oracle/oracle-database/26/refrn/ALL_TAB_COLS.html
- 2: http://docs.oracle.com/cd/B12037_01/server.101/b10755/statviews_1179.htm
- 3: https://docs.oracle.com/en/database/oracle/oracle-database/18/refrn/ALL_TAB_COLUMNS.html
- 4: https://docs.oracle.com/en/database/oracle/oracle-database/23/refrn/ALL_TAB_COLS.html
- 5: https://docs.oracle.com/en/database/oracle/oracle-database/26/lnpls/character-sets.html
- 6: http://docs.oracle.com/database/121/SUTIL/GUID-A0836AD3-5897-419E-AE40-33B40DB19660.htm
- 7: https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Data-Types.html
- 8: https://docs.oracle.com/database/121/ADMQS/GUID-7EDE63C6-5317-46A2-A9A3-6C019702B50D.htm
- 9: https://docs.oracle.com/cd/B19306_01/server.102/b14237/statviews_2094.htm
- 10: https://asktom.oracle.com/ords/asktom.search?tag=character-set-of-a-clob
🏁 Script executed:
sed -n '1480,1495p' contrib/ivorysql_ora/src/sysview/sysview--1.0.sqlRepository: IvorySQL/IvorySQL
Length of output: 795
🏁 Script executed:
# Search for existing type-checking patterns in the file to understand how types are compared
rg -n "typname IN|CASE.*typname|pg_type.typname" contrib/ivorysql_ora/src/sysview/sysview--1.0.sql -A 3Repository: IvorySQL/IvorySQL
Length of output: 4582
🏁 Script executed:
# Check if the type names mentioned in the suggested fix exist in the codebase
rg -n "oracharchar|oravarcharchar" contrib/ivorysql_ora/src/sysview/sysview--1.0.sqlRepository: IvorySQL/IvorySQL
Length of output: 493
🏁 Script executed:
rg -n "nchar|nvarchar2|nclob" contrib/ivorysql_ora/src/sysview/sysview--1.0.sqlRepository: IvorySQL/IvorySQL
Length of output: 523
🏁 Script executed:
# Also check what character types are actually supported
rg -n "typname IN.*char|typname IN.*varchar" contrib/ivorysql_ora/src/sysview/sysview--1.0.sql | head -20Repository: IvorySQL/IvorySQL
Length of output: 948
CHARACTER_SET_NAME returns database encoding for all columns instead of character-set semantics.
Line 1486 uses current_setting('server_encoding') which returns the same value (e.g., UTF8) for every column, including NUMBER and DATE. Oracle requires this field to be CHAR_CS for character types, NCHAR_CS for national character types, and NULL otherwise. Reuse the type-checking pattern already established in this file:
Suggested fix
- pg_catalog.current_setting('server_encoding')::varchar2(44) AS character_set_name,
+ CASE
+ WHEN pg_type.typname IN ('bpchar', 'varchar', 'oracharchar', 'oravarcharchar', 'text', 'clob')
+ THEN 'CHAR_CS'
+ WHEN pg_type.typname IN ('nchar', 'nvarchar2', 'nclob')
+ THEN 'NCHAR_CS'
+ ELSE NULL
+ END::varchar2(44) AS character_set_name,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@contrib/ivorysql_ora/src/sysview/sysview--1.0.sql` at line 1486, Replace the
current_setting('server_encoding')::varchar2(44) AS character_set_name
expression with a CASE that returns 'CHAR_CS' for character types, 'NCHAR_CS'
for national character types and NULL otherwise, reusing the same type-checking
logic already used elsewhere in this file (the expression testing
a.atttypid/a.atttypmod or t.typcategory/format_type). Concretely, locate the
existing type-checking expressions (used for COLLATION_NAME or similar columns)
and copy that pattern into a CASE WHEN ... THEN 'CHAR_CS' WHEN ... THEN
'NCHAR_CS' ELSE NULL END AS character_set_name, replacing the current_setting
call.
fix #1009
This PR completes the implementation of the
ALL_TAB_COLUMNSview in the Oracle compatibility layer, addressing key issues identified in the review process.Changes
DATA_TYPE,COLUMN_ID), and fixed boundary cases forNULLvalues and partition tables.ora_sysview.out) to match the corrected view behavior, ensuring test suite compatibility.Verification
contrib/ivorysql_oraOracle compatibility module.masterbranch.Related
Closes the remaining implementation requirements for the
ALL_TAB_COLUMNSview as part of the Oracle compatibility project.Summary by CodeRabbit
New Features
Tests