Skip to content

Commit

Permalink
fix: Do not evaluate isClassArityUsageDisabled on every serialize/des… (
Browse files Browse the repository at this point in the history
#157)

* fix: Do not evaluate isClassArityUsageDisabled on every serialize/deserialize function call

* chore: Move isClassArityUsageDisabled to object
  • Loading branch information
s-gelazevicius authored Oct 11, 2024
1 parent 7721dd4 commit bd076b2
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.apache.flink.api.common.typeutils.TypeSerializer
import org.apache.flink.api.java.typeutils.runtime.TupleSerializerBase
import org.apache.flink.core.memory.{DataInputView, DataOutputView}
import org.apache.flink.types.NullFieldException
import org.apache.flinkx.api.serializer.CaseClassSerializer.isClassArityUsageDisabled
import org.slf4j.{Logger, LoggerFactory}

import scala.util.{Failure, Success, Try}
Expand Down Expand Up @@ -77,14 +78,6 @@ abstract class CaseClassSerializer[T <: Product](
createInstance(fields.toArray)
}

private def isClassArityUsageDisabled =
sys.env
.get("DISABLE_CASE_CLASS_ARITY_USAGE")
.exists(v =>
Try(v.toBoolean)
.getOrElse(false)
)

def serialize(value: T, target: DataOutputView): Unit = {
if (arity > 0 && !isClassArityUsageDisabled)
target.writeInt(value.productArity)
Expand Down Expand Up @@ -124,3 +117,13 @@ abstract class CaseClassSerializer[T <: Product](
createInstance(fields.filter(_ != null))
}
}

object CaseClassSerializer {
private val isClassArityUsageDisabled =
sys.env
.get("DISABLE_CASE_CLASS_ARITY_USAGE")
.exists(v =>
Try(v.toBoolean)
.getOrElse(false)
)
}

0 comments on commit bd076b2

Please sign in to comment.