-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvement: FlinkBaseTypeInfoRegister mechanism
- Loading branch information
Showing
5 changed files
with
51 additions
and
23 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...cala/pl/touk/nussknacker/engine/flink/api/typeinformation/FlinkBaseTypeInfoRegister.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package pl.touk.nussknacker.engine.flink.api.typeinformation | ||
|
||
import org.apache.flink.api.common.functions.InvalidTypesException | ||
import org.apache.flink.api.common.typeinfo.{TypeInfoFactory, TypeInformation, Types} | ||
import org.apache.flink.api.java.typeutils.TypeExtractor | ||
|
||
import java.lang.reflect.Type | ||
import java.util | ||
import scala.reflect.{ClassTag, classTag} | ||
|
||
object FlinkBaseTypeInfoRegister { | ||
|
||
private val BaseTypes = List( | ||
Types.LOCAL_DATE, | ||
Types.LOCAL_TIME, | ||
Types.LOCAL_DATE_TIME, | ||
Types.INSTANT, | ||
Types.SQL_DATE, | ||
Types.SQL_TIME, | ||
Types.SQL_TIMESTAMP, | ||
) | ||
|
||
def makeSureBaseTypesAreRegistered(): Unit = | ||
BaseTypes.foreach(register(_)) | ||
|
||
private def register[T: ClassTag](typeInformation: TypeInformation[T]): Unit = { | ||
val klass = classTag[T].runtimeClass.asInstanceOf[Class[T]] | ||
val factory = new TypeInfoFactory[T] { | ||
override def createTypeInfo( | ||
t: Type, | ||
genericParameters: util.Map[String, TypeInformation[_]] | ||
): TypeInformation[T] = | ||
typeInformation | ||
} | ||
|
||
try { | ||
TypeExtractor.registerFactory(klass, factory.getClass) | ||
} catch { | ||
case exc: InvalidTypesException | ||
if exc.getMessage == s"A TypeInfoFactory for type '$klass' is already registered." => | ||
// Factory has been already registered | ||
} | ||
} | ||
|
||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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