vertica / spark-connector

This component acts as a bridge between Spark and Vertica, allowing the user to either retrieve data from Vertica for processing in Spark, or store processed data from Spark into Vertica.
Apache License 2.0
20 stars 23 forks source link

Implement relational operators for Vertica Version comparisons #518

Closed ai-bq closed 1 year ago

ai-bq commented 1 year ago

Is your feature request related to a problem? Please describe.

All instances of version checks in the connector currently use our own string operators for making version comparisons.

Describe the solution you'd like

Our Version class already extends Ordered so we can use relational operators for these comparisons instead. We should switch all instances of our Version checks to using Ordered, then clean up the Version class as we won't need the current methods anymore.


case class Version(major: Int, minor: Int = 0, servicePack: Int = 0, hotfix: Int = 0) extends Ordered[Version] {

  def largerOrEqual(version: Version): Boolean = this.compare(version) >= 0

  def largerThan(version: Version): Boolean = this.compare(version) > 0

  def lesserOrEqual(version: Version): Boolean = this.compare(version) <= 0

  def lessThan(version: Version): Boolean = this.compare(version) < 0

  def isEquals(version: Version): Boolean =  this.compare(version) == 0

  override def toString: String = s"${major}.${minor}.${servicePack}-${hotfix}"

  override def compare(that: Version): Int =
    (this.major * 1000 + this.minor * 100 + this.servicePack * 10 + this.hotfix) -
      (that.major * 1000 + that.minor * 100 + that.servicePack * 10 + that.hotfix)
}
jeremyprime commented 1 year ago

I believe it is as simple as deleting the custom logical methods in the Version class (largerOrEqual, largerThan, etc) and updating all places in the code where we compared the version to use logical operators (>=, >, etc).