Search

Home

Release Notes

User Docs

🧬

Convert Code Override

💡
o·ver·ride: interrupt the action of (an automatic device), typically in order to take manual control.
  • Overview
  • setup
  • overrideCode
  • Convert vs. Convert Type
  • Convert Type (Order: 1)
  • Convert (Order: 2)
  • Convert Type - Final (Order: 3)
  • Class Documentation
  • Holder
  • Constructor
  • Members
  • ParsedName
  • Constructor
  • Members
  • ParsedPhone
  • Constructor
  • Members
  • RestService
  • Constructor
  • Members
  • References
  • Examples
  • Change a field
  • Modify an amount field
  • Bin a field for validation
  • Copy a field to another
  • Calculate a derived value
  • Drop Records
  • Regular Expression (RegEx) Match
  • Plug a date 1 year ago
  • Plug Dates
  • Parsing JSON
  • Get year, month, day from a date
  • Email Verification 1
  • Email Verification 2
  • Filename
  • Plug Record Id or Line Number
  • split DOB components
  • Get an original source field
  • Concatenate several fields together
  • Access Client or File Attributes
  • Get CreateDate from File
  • Caps Case a Set of Fields
  • Create a Banded Range Field
  • Reduce: Keep Latest Record Only

Overview

💡
Users are able to implement more complex logic using one or more code overrides. Code can be injected at the convert level, affecting on that specific convert or at the convert type level, which would apply the logic to all pipelines of that specific type.

setup

💡
Use setup to perform an operation one time, and pass the result of that operation to overrideCode. For instance, if you pull a lookup data table from an API, rather than doing it in overrideCode which would call an API many times, make the API call one time in setup, then use the resulting data in overrideCode.

overrideCode

💡
Code run in overrideCode is executed on each row, represented by a Holder. It must return an instance of a Holder object.

Convert vs. Convert Type

💡
Convert Type code is run before the code for the specific convert. Convert type code must be enabled by checking then Enabled checkbox and saving. Other than the ordering and enabled, both operate in a similar way.

Convert Type (Order: 1)

Administration → Convert Types → Click convert hyperlink → Code

image

Convert (Order: 2)

Files → Menu for specific file → Open in Builder → Code

image

Convert Type - Final (Order: 3)

image

Class Documentation

Holder

💡

Holder is the default container used to serialize data through the conversion process. It can be changed using code overrides. Use the copy method or upsertField to mutate an instance of a holder to return.

Constructor

Members

val client: Option[Client]
val convertConfiguration: Option[ConvertConfiguration]
val errorList: Option[List[String]]
val errors: List[TransformationError]
val fieldConfiguration: Option[FieldConfiguration]
val file: Option[File]
def getField(k: String): Option[Any]
def getFieldAs[T](k: String): Option[T]
def getFieldAsDateTime(k: String): Option[DateTime]
def getMatchcode(): Option[String]
val lineNumber: Long
def removeField(k: String): Holderf
def toString(): String
def upsertField(k: String, v: Option[Any]): Holder
def validField(str: String): Boolean

ParsedName

Constructor

Members

val first: Option[String]
val firstInitial: Option[String]
val firstNameValidation: Option[NameValidation]
def fullname(): Option[String]
val gender: Option[String]
val last: Option[String]
val middle: Option[String]
val nicknames: Option[String]
val postnomial: Option[String]
val prefix: Option[String]
val soundEx: Option[SoundEx]
val suffix: Option[String]
def toString(): String

ParsedPhone

Constructor

new io.phase3.transform.model.ParsedPhone(original: Option[String] = None, formatted: Option[String] = None, isValid: Option[Boolean] = None)

Members

val formatted: Option[String]
val isValid: Option[Boolean]
val original: Option[String]

RestService

Constructor

💡
The io.phase3.transform.service.RestService class is static.

Members

def delete(uri: String, headers: Option[Map[String, String]] = None): Option[Int] //Response Code

def get[T](uri: String, headers: Option[Map[String, String]] = None (implicit arg0: Manifest[T]): Option[T]
def post[T](uri: String, body: String, headers: Option[Map[String, String]] = None (implicit arg0: Manifest[T]): Option[T]

References

Scala Cheat Sheet

Scala REPL Online

Examples

Change a field


val state = if(holder.getFieldAs[String]("state").getOrElse("XX") == "AX"){
    Some("AZ")
}
else{
    holder.getFieldAs[String]("state")
}

holder.upsertField("state",state)

Modify an amount field

val amount = holder.getFieldAs[Double]("amount").getOrElse(0.0) * 1.64

holder.upsertField("amount", Some(amount))

Bin a field for validation

val dollar = holder.getFieldAs[String]("dollar").getOrElse("0").toInt

val myBin = dollar match {
  case 0 => Some("SM")
  case x if x < 10 => Some("MD")
  case _ => Some("LG")
}

holder.upsertField("myBin",myBin)

Copy a field to another

holder.upsertField("copy_of_field1",holder.getFieldAs[String]("field1"))

Calculate a derived value

val dollars = holder.getFieldAs[Double]("dollars")
val quantity = holder.getFieldAs[Int]("quantity")

holder.upsertField("net",Option(dollars * quantity))

Drop Records

//Ensure that drop and dropReason are added as fields of this convert type

val (drop,dropReason) = if (holder.getFieldAs[String]("item_id").isEmpty) 
  (Some(true),Some("Missing item_id")) 
else 
  (None,None)

holder.upsertField("drop",drop)
      .upsertField("dropReason",dropReason)

Regular Expression (RegEx) Match

val regex = "(^[A-Za-z\\-0-9]*)".r
  
val itemId = if(holder.getFieldAs[String]("item_desc").isDefined){
  regex.findFirstMatchIn(holder.getFieldAs[String]("item_desc").get) match {
    case Some(i) => Some(i.group(1))
    case None => None
  }
}
else{
  None
}

holder.upsertField("item_id",itemId)

Plug a date 1 year ago

holder.upsertField("transactionDate",Some(new org.joda.time.DateTime().minusYears( 1 )))

Plug Dates

import org.joda.time.DateTime

val now = new DateTime()

holder.upsertField("my_date_field", Some(now))
new org.joda.time.DateTime().withYear(1900).withDayOfYear(1).withMonthOfYear(1)

Parsing JSON

Get year, month, day from a date

Email Verification 1

Email Verification 2

Filename

val fileName = holder.file.get.alias.getOrElse(holder.file.get.fileName.getOrElse(""))

Plug Record Id or Line Number

val recordId = holder.file.get._id
val lineNumber = holder.lineNumber

//make sure record_id and line_number are fields in your convert type    
holder.upsertField("record_id",Some(recordId))
      .upsertField("line_number",Some(lineNumber))

split DOB components

Get an original source field

💡
Administration → Convert Types → Output Options → Options → Passthrough Raw Input Data must be checked
# Where: field.0, field.1, field.2, field.3
holder.upsertField("test01",holder.getSourceField(0))

Concatenate several fields together

Access Client or File Attributes

Get CreateDate from File

Caps Case a Set of Fields

Create a Banded Range Field

Reduce: Keep Latest Record Only

new ReduceOverride {
  override def reduceOverride(keyRecords: (String, Iterable[Holder]),dedupeType:String): Iterable[Holder] = {
    val (key, holders) = keyRecords

    val newestFirst = holders.toList.sortBy(_.getFieldAsDateTime("date").getOrElse(new org.joda.time.DateTime()).getMillis)(Ordering.Long.reverse)

    List(newestFirst.head)
  }
}