Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparable version representation #109

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ebikt
Copy link
Contributor

@ebikt ebikt commented May 29, 2019

Ascii representations of debian versions can be comparend using simple ASCII dictionary ordering to get result of comparison of original version. Intended usage is to store ASCII representation in separate column in SQL table of packages and then use ORDER BY to obtain the package with the highest version.

ebikt added 2 commits May 29, 2019 22:28
Comparable strings adds support for external databases, where we want
compare versions by native comparsion of the database.
@paultag
Copy link
Owner

paultag commented May 29, 2019

@stapelberg mind doing a review? This is changing quite a bit, and you wrote this code originally.

@paultag paultag requested a review from stapelberg May 29, 2019 23:52
@@ -199,6 +397,9 @@ func parseInto(result *Version, input string) error {
}

colon := strings.Index(trimmed, ":")
if (colon >= 9) {
return fmt.Errorf("epoch too big or not an integer")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The epoch can be any unsigned integer; a valid version can be 10000000000:1.0-1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such epoch is valid, but not supported. It does not fit into 32bit integer, so most parsers would have problems (comparing it) anyways.

@paultag
Copy link
Owner

paultag commented May 30, 2019

This also may not help you, but there's a postgresql-11-debversion field for PostgreSQL that we use throughout Debian.

Description: Debian version number type for PostgreSQL
 Debian version numbers, used to version Debian binary and source
 packages, have a defined format, including specifications for how
 versions should be compared in order to sort them.  This package
 implements a "debversion" type to represent Debian version numbers
 within the PostgreSQL database.  This also includes operators for
 version comparison and index operator classes for creating indexes on
 the debversion type.
 .
 Version comparison uses the algorithm used by the Debian package
 manager, dpkg, using the implementation from libapt-pkg.  This means
 that columns in tables using the debversion type may be sorted and
 compared correctly using the same logic as "dpkg --compare-versions".
 It is also possible to create indexes on these columns.
 .
 postgresql-debversion implements the following features:
 .
  * The "debversion" type (internally derived from the "text" type)
  * A full set of operators for version comparison (< <= = <> >= >)
    including commutator and negator optimisation hints
  * Operator classes for btree and hash indexes
  * The aggregate functions min() and max()

@ebikt
Copy link
Contributor Author

ebikt commented May 30, 2019

This also may not help you, but there's a postgresql-11-debversion field for PostgreSQL that we use throughout Debian.

Indeed, I was using this with some old version MySQL server. Having precomputed value for comparisons can be beneficial also for other uses (e.g., when sorting large number of versions, because byte-string comparison is much faster than interpreting debian version for every comparison.).

@paultag
Copy link
Owner

paultag commented May 30, 2019

Indeed, I was using this with some old version MySQL server. Having precomputed value for comparisons can be beneficial also for other uses (e.g., when sorting large number of versions, because byte-string comparison is much faster than interpreting debian version for every comparison.).

The PostgreSQL version here is index-able and is quite fast - we use it in production for the entire Debian archive 👍

@paultag
Copy link
Owner

paultag commented May 30, 2019

The more I think about this changeset, the more that I think this could be a separate package that takes a debian/version.Version and produces a string for SQL use. I don't know if I'm quite sold on this change to the version code, but let me read through the changes and think critically about it a bit more.

@ebikt
Copy link
Contributor Author

ebikt commented Jun 6, 2019

I'm OK with the decision that it should be separate package. I wrote this code so maybe I should take responsibility for it in my own repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants