Created
November 16, 2017 11:31
-
-
Save djtfmartin/3a98a0f4339adea3444cf1ff761b18a1 to your computer and use it in GitHub Desktop.
FixDatePrecision.scala
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
package au.org.ala.biocache.tool | |
import au.org.ala.biocache.Config | |
import org.slf4j.LoggerFactory | |
object FixDatePrecision extends au.org.ala.biocache.cmd.Tool { | |
def cmd = "fix-date-precision" | |
def desc = "Cleanup old date precision values." | |
protected val logger = LoggerFactory.getLogger("SyncLocTable") | |
def main(args: Array[String]) { | |
new FixDatePrecision().fix | |
Config.persistenceManager.shutdown | |
} | |
} | |
class FixDatePrecision { | |
val monthPrecision = List("Year", "Month Range", "Year Range") | |
var counter = 0 | |
var updates = 0 | |
def fix { | |
Config.persistenceManager.pageOverLocal("occ", (key, map, tokenRangeIdx) => { | |
counter += 1 | |
val datePrecision = map.getOrElse("dateprecision_p", "") | |
val eventDate = map.getOrElse("eventdate_p", "") | |
val eventDateEnd = map.getOrElse("eventdateend_p", "") | |
if(monthPrecision.contains(datePrecision)){ | |
Config.persistenceManager.putAsync( | |
key, | |
"occ", | |
Map("month_p" -> "", "day_p" -> ""), | |
false, | |
false | |
) | |
updates += 1 | |
} else if(datePrecision == "Day Range") { | |
if (eventDate == eventDateEnd && eventDate.length == 7) { | |
Config.persistenceManager.putAsync( | |
key, | |
"occ", | |
Map("day_p" -> ""), | |
false, | |
false | |
) | |
updates += 1 | |
} else if (eventDate != eventDateEnd && eventDate.length == 7) { | |
Config.persistenceManager.putAsync( | |
key, | |
"occ", | |
Map("month_p" -> "", "day_p" -> ""), | |
false, | |
false | |
) | |
updates += 1 | |
} | |
} | |
true | |
}, 6, Array[String]("rowkey", "dateprecision_p", "eventdate_p", "eventdateend_p")) | |
println(s"Rows read: $counter updates: $updates") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment