Repository navigation
Write temporal primary keys as canonical text and parse them in check (#107) - #116
Open
RodolfoMeloDev wants to merge 2 commits into
Open
RodolfoMeloDev wants to merge 2 commits into
RodolfoMeloDev wants to merge 2 commits into
Conversation
…CrunchyData#107) The pk JSON of a row is read back by check and bound to the key filter on both the source and the target, since the repository picks one pk per pk_hash from either side. For a date/datetime/timestamp/time key the JSON applied the platform's replace() to the raw column: - PostgreSQL rejects it (function replace(timestamp ...) does not exist): the compare query aborts, the run continues with an empty side and every row is reported missing. - SQL Server converts with style 0 ('Nov 5 2026 2:03PM'): seconds and fractions are lost and the text follows SET LANGUAGE. - Oracle converts with NLS_DATE_FORMAT ('05-NOV-26'): the time and century are lost. - MySQL and MariaDB keep the value, but in session time while the pk_hash uses UTC. The check filter then bound that text to col = ?, which PostgreSQL rejects for temporal columns and the other platforms resolve with session settings. A row whose key lost its seconds is not found on either side and, since CrunchyData#103, is cleared as converged: real drift reported as in sync. Add TemporalKeyUtils, used for primary-key columns of the types in TIMESTAMP_TYPES (except MySQL year and SQL Server rowversion): - keyText() renders YYYY-MM-DD HH24:MI:SS[.fraction] (HH24:MI:SS for time) with explicit formats only, keeping each platform's full precision and normalizing to UTC exactly where castTimestamp() does for the pk_hash. - keyParameter() parses the bind parameter back with explicit formats or ISO input, trimming the fraction to what the platform accepts, and converts to the column's own type where a wider comparison would miss the row (SQL Server datetime against datetime2). createColumnFilterClause() now reads data_type from dc_table_column_map (added to SQL_REPO_DCTABLECOLUMNMAP_BYORIGINALIAS) and the destination platform to build the filter. Non-temporal keys are unchanged, and the pk_hash is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…runchyData#107) Checked on Db2 12.1: - to_char(...,'FF9') cut a timestamp(12) key to 9 digits, and timestamp() parses to precision 6, so such a row was not found by its own key. Render FF12 and parse with cast(... as timestamp(12)). - Db2 TIME has no fraction and time() rejects '14:03:27.123456' (SQL0180N), which other platforms write for their time keys. Parse only the first 8 characters. - Snowflake parses at most 9 fractional digits; trim the parameter so a 12-digit Db2 key does not fail there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #107.
Problem
checkreads the pk JSON of a row back and binds it to the key filter on both the source and the target.SQL_REPO_SELECT_OUTOFSYNC_ROWSpicks one pk perpk_hashfrom either side. For adate/datetime/timestamp/timekey, the JSON applied the platform'sreplace()to the raw column, and the filter bound that text tocol = ?. The issue describes SQL Server and PostgreSQL; checking every platform found that the problem reaches all of them:mainfunction replace(timestamp ...) does not existNov 5 2026 2:03PM, ornov 5 2026underSET LANGUAGE PortugueseNLS_DATE_FORMAT,05-NOV-26, or05/11/26with a pt-BR JVM99)2026-11-05 14:03:27pk_hashuses UTCThe
checkfilter then fails on PostgreSQL (timestamp = varchar) and resolves through session settings elsewhere. A row whose key lost its seconds is found on neither side and, since #103, is cleared as converged. Real drift is reported as in sync.Change
New
TemporalKeyUtils, used for primary-key columns of the types inTIMESTAMP_TYPES, except MySQLyearand SQL Server rowversion (timestamp):keyText()rendersYYYY-MM-DD HH24:MI:SS[.fraction], orHH24:MI:SSfortime, with explicit formats only. It keeps each platform's full precision (up to 12 digits on Db2) and normalizes to UTC exactly wherecastTimestamp()does for thepk_hash.keyParameter()parses the bind parameter with explicit formats or ISO input. It trims the fraction to what the platform accepts (7 on SQL Server, 9 on Oracle and Snowflake, 12 on Db2). Where a wider comparison would miss the row, it converts to the column's own type: a SQL Serverdatetimecompared with an uncastdatetime2misses.003/.997.createColumnFilterClause()now receives the platform and readsdata_type, which is added toSQL_REPO_DCTABLECOLUMNMAP_BYORIGINALIAS.Non-temporal keys and the
pk_hashare unchanged.to_char(col,'YYYY-MM-DD HH24:MI:SS.US'); tz:at time zone 'UTC'cast(? as timestamp); tz:(cast(? as timestamp) at time zone 'UTC')convert(varchar(27), col, 121); datetimeoffset viaswitchoffset(col,'+00:00')cast(convert(datetime2(7), left(?, 27), 121) as <datetime|smalldatetime|date>)to_char(col,'YYYY-MM-DD HH24:MI:SS.FF9'); DATE without fractionto_timestamp(substr(?,1,29),'YYYY-MM-DD HH24:MI:SS.FF9'); DATE:to_date(substr(?,1,19),...)date_format(convert_tz(col,@@session.time_zone,'UTC'),'%Y-%m-%d %H:%i:%s.%f')convert_tz(cast(? as datetime(6)),'UTC',@@session.time_zone)date_format(col,'%Y-%m-%d %H:%i:%s.%f')cast(? as datetime(6))to_char(col,'YYYY-MM-DD HH24:MI:SS.FF12')cast(cast(? as varchar(40)) as timestamp(12))to_char(col,'YYYY-MM-DD HH24:MI:SS.FF9'); ltz/tz viaconvert_timezone('UTC', col)to_timestamp_ntz(substr(?,1,29))Tests
TemporalKeyUtilsTest, 78 cases: golden cases for every platform and type, plus the call sites (pk JSON and filter, temporal and non-temporal).mvn test: 111 tests, 0 failures.0001-01-01,1753-01-01,9999-12-31 23:59:59.997/.9999999/.999999999999),datetime2(7),datetimeoffsetwith offsets that change the UTC date, OracleTIMESTAMP(9)andWITH TIME ZONE, and Db2TIMESTAMP(12).DateStyle SQL, DMY,SET LANGUAGE PortugueseplusSET DATEFORMAT dmy, Oracle NLS for Brazil, and session time zoneAmerica/Sao_Paulo.conston MySQL.e2e_keysande2e_dkeysbelow. Onmainthey fail on all six platforms. With the fixes, every row is equal with identical data, and every change is reported bycompareand confirmed bycheck. That includes the row present only on the target, whose key comes from PostgreSQL and is bound on the source platform.Notes
checkRows(). Whichever is merged second needs a trivial rebase.SQLFixGenerationService(fix=true) still writes the pk JSON values as SQL literals. A temporal literal with 6 fractional digits is rejected by a SQL Serverdatetimetarget..5) in the pk JSON.End-to-end evidence
The same scenario ran with each platform below as the source and PostgreSQL 16 as
target and repository, once with
main(db72a0c) and once with the four fixbranches merged together (
739d1be: #106, #107, #111 and #112), from a fresh repositoryand target each time. pgCompare ran with default settings and a pt-BR JVM locale.
postgres:16mysql:8.4mariadb:11.4mcr.microsoft.com/mssql/server:2022-latestgvenzl/oracle-xe:21-slim-faststarticr.io/db2_community/db2:latestThree tables with identical rows on both sides:
e2e_keys(id bigint, dt timestamp(3));datetimeon SQL Server,TIMESTAMP(3)on Oracle and Db22147483648,123456789012...), #112 (a, b,11/11/2026, xml)e2e_dkeys(id int, d date);DATEon Oraclee2e_numid int;amount decimal(24,10)with 0.19, -0.5, 0.0165, 1e10, 12345678901, 1e-10...Steps:
comparewith identical data (all rows must be equal), then these changes on the target, thencompareandcheck(both must report exactly them):Result: with the fixes, all 18 table runs (6 platforms x 3 tables) match the expectation in the three steps, with no SEVERE line in the log. On
main:checkafter the changesfunction replace(timestamp ...) does not exist)e2e_num4 of 9 Not Equal (e+10, e-10 decades)e2e_keys: 4 rows reported equal, 3 real changes loste2e_num4 of 9 Not Equal (0 < abs(v) < 1)e2e_keys: 5 rows reported equal, 4 real changes loste2e_keys: 5 rows reported equal, 4 real changes loste2e_keys: 4 rows reported equal, 3 real changes lostFull result per platform, build and table (E = equal, NE = not equal, MS/MT = missing source/target)
Unit tests (
mvn test) per branchBefore the end-to-end runs, the expressions were also run directly on each engine,
including under non-default session settings (PostgreSQL
DateStyle SQL, DMY; SQL ServerSET LANGUAGE PortugueseandSET DATEFORMAT dmy; Oracle NLS for Brazil; MySQL and Oraclesession time zone
America/Sao_Paulo). The scripts, data and full pgCompare logs of every runare available on request.
🤖 Generated with Claude Code