Repository navigation
Encode string literals compared with DATE or TIMESTAMP columns - #1847
Draft
agusaldasoro wants to merge 1 commit into
Draft
agusaldasoro wants to merge 1 commit into
agusaldasoro wants to merge 1 commit into
Conversation
A plain string literal compared with a DATE or TIMESTAMP column, e.g. d > '2024-01-01', was written as an SMT string against an Int column, so Z3 rejected the formula and the query got no data. Such literals, in comparisons and IN lists, are now encoded as epoch seconds like typed DATE and TIMESTAMP literals.
agusaldasoro
added this pull request to stack #1848
October 7, 2026 12:56
agusaldasoro
removed this pull request from stack #1848
October 7, 2026 13:04
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.
Stacked on #1846.
Problem
DATEandTIMESTAMPcolumns are encoded as epoch seconds (an SMTInt). A typed literal such asTIMESTAMP '2024-01-01 10:00:00'or, with #1846,DATE '2024-01-01'is converted to epoch seconds by the condition parser. A plain string literal is not:WHERE d > '2024-01-01'was written as(> (D ev__1) "2024-01-01"). Z3 rejects the formula for comparing anIntwith aString, so the query gets no data. The same happened forTIMESTAMPcolumns (ts > '2024-01-01 10:00:00') and forINlists.Plain string literals are the common case: SQL written by hand, and the bound parameters of ORM queries, rarely use the typed form.
Fix
JSqlVisitor.toEpochSeconds(String)(dbconstraint) is now public. It is the existing conversion used for typedTIMESTAMPliterals, extracted unchanged. It accepts the same layouts (Tor space separator, optional seconds and fraction, offsets), and reads a bare date as midnight UTC.SMTConditionVisitor: when one side of a comparison is aDATEorTIMESTAMPcolumn of the schema and the other is a string literal, the literal is encoded withtoEpochSeconds, on either side. The same applies to the string literals of anINlist on such a column.(- n), since SMT-LIB has no negative numerals.DateTimeParseException. Only that conjunct is dropped and counted as a partial translation, like any other untranslatable condition.Tests
DateColumnSolvingTest(end to end against Z3 and H2) gets four more queries:d > '2024-01-01','2024-03-05' = d,d IN ('2024-03-05', '2024-03-06')andts > '2024-01-01 10:00:00'. Each checks that the generated row is inserted and returned by the query. All four fail on Encode DATE columns like TIMESTAMP ones #1846 (no actions).TemporalStringLiteralTranslationTest, on the generated SMT-LIB. It checks the epoch encoding, the negated numeral for a date before 1970, and that a non-date string drops only its own conjunct. All three fail on Encode DATE columns like TIMESTAMP ones #1846.All tests in
core-extra/dbconstraintand underorg.evomaster.core.database.sql.solverpass.