From ee19d7d63fcb2132c809c9b9106dedbe47284bd3 Mon Sep 17 00:00:00 2001 From: Honnix Date: Thu, 19 Oct 2023 11:58:27 +0200 Subject: [PATCH] Case class for BindingCollection/Map (#263) * Make BindingCollection and BindingMap case class Signed-off-by: Hongxin Liang --- .../main/scala/org/flyte/flytekit/BindingCollection.scala | 3 +-- .../src/main/scala/org/flyte/flytekit/BindingMap.scala | 3 +-- .../src/main/scala/org/flyte/flytekit/package.scala | 7 +++---- .../org/flyte/flytekitscala/SdkBindingDataFactory.scala | 4 ++-- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/flytekit-scala_2.13/src/main/scala/org/flyte/flytekit/BindingCollection.scala b/flytekit-scala_2.13/src/main/scala/org/flyte/flytekit/BindingCollection.scala index 22f3f5a01..f52b2f990 100644 --- a/flytekit-scala_2.13/src/main/scala/org/flyte/flytekit/BindingCollection.scala +++ b/flytekit-scala_2.13/src/main/scala/org/flyte/flytekit/BindingCollection.scala @@ -17,13 +17,12 @@ package org.flyte.flytekit import org.flyte.api.v1.BindingData -import org.flyte.flytekit.SdkBindingData.Literal import org.flyte.flytekitscala.SdkLiteralTypes.collections import java.util.function import scala.collection.JavaConverters._ -private[flyte] class BindingCollection[T]( +private[flyte] case class BindingCollection[T]( elementType: SdkLiteralType[T], bindingCollection: List[SdkBindingData[T]] ) extends SdkBindingData[List[T]] { diff --git a/flytekit-scala_2.13/src/main/scala/org/flyte/flytekit/BindingMap.scala b/flytekit-scala_2.13/src/main/scala/org/flyte/flytekit/BindingMap.scala index b9fe1c1fc..7da1bf856 100644 --- a/flytekit-scala_2.13/src/main/scala/org/flyte/flytekit/BindingMap.scala +++ b/flytekit-scala_2.13/src/main/scala/org/flyte/flytekit/BindingMap.scala @@ -17,13 +17,12 @@ package org.flyte.flytekit import org.flyte.api.v1.BindingData -import org.flyte.flytekit.SdkBindingData.Literal import org.flyte.flytekitscala.SdkLiteralTypes.maps import java.util.function import scala.collection.JavaConverters._ -private[flyte] class BindingMap[T]( +private[flyte] case class BindingMap[T]( valuesType: SdkLiteralType[T], bindingMap: Map[String, SdkBindingData[T]] ) extends SdkBindingData[Map[String, T]] { diff --git a/flytekit-scala_2.13/src/main/scala/org/flyte/flytekit/package.scala b/flytekit-scala_2.13/src/main/scala/org/flyte/flytekit/package.scala index b35ecde46..a4771091e 100644 --- a/flytekit-scala_2.13/src/main/scala/org/flyte/flytekit/package.scala +++ b/flytekit-scala_2.13/src/main/scala/org/flyte/flytekit/package.scala @@ -18,10 +18,9 @@ package org.flyte /** Contains subclasses for [[SdkBindingData]]. We are forced to define this * package here because [[SdkBindingData#idl()]] is package private (we donĀ“t - * want to expose it to users). We cannot make it protected either as it would - * be good for the own object but both implementations deal with list or maps - * of [[SdkBindingData]] and therefore cannot call this method because it is in - * a different class. + * want to expose it to users). Making it protected doesn't help either because + * list or map needs to call this method of elements so that requires it to be + * public. * * This is not ideal because we are splitting the flytekit package in two maven * modules. This would create problems when we decide to add java 9 style diff --git a/flytekit-scala_2.13/src/main/scala/org/flyte/flytekitscala/SdkBindingDataFactory.scala b/flytekit-scala_2.13/src/main/scala/org/flyte/flytekitscala/SdkBindingDataFactory.scala index 857238ee4..c75ef8c65 100644 --- a/flytekit-scala_2.13/src/main/scala/org/flyte/flytekitscala/SdkBindingDataFactory.scala +++ b/flytekit-scala_2.13/src/main/scala/org/flyte/flytekitscala/SdkBindingDataFactory.scala @@ -353,7 +353,7 @@ object SdkBindingDataFactory { elementType: SdkLiteralType[T], elements: List[SdkBindingData[T]] ): SdkBindingData[List[T]] = { - new BindingCollection(elementType, elements) + BindingCollection(elementType, elements) } /** Creates a [[SdkBindingData]] for a flyte map given a java @@ -372,7 +372,7 @@ object SdkBindingDataFactory { valuesType: SdkLiteralType[T], valueMap: Map[String, SdkBindingData[T]] ): SdkBindingData[Map[String, T]] = - new BindingMap(valuesType, valueMap) + BindingMap(valuesType, valueMap) private def toSdkLiteralType( value: Any,