[GitHub] flink pull request: [FLINK-2231] Create a Serializer for Scala Enu...
Github user StephanEwen commented on the pull request: https://github.com/apache/flink/pull/935#issuecomment-125890350 Other than the one comment, this looks good. +1 --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] flink pull request: [FLINK-2231] Create a Serializer for Scala Enu...
Github user StephanEwen commented on a diff in the pull request: https://github.com/apache/flink/pull/935#discussion_r35741171 --- Diff: flink-scala/src/main/scala/org/apache/flink/api/scala/typeutils/EnumValueSerializer.scala --- @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * License); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.flink.api.scala.typeutils + +import org.apache.flink.api.common.typeutils.TypeSerializer +import org.apache.flink.api.common.typeutils.base.IntSerializer +import org.apache.flink.core.memory.{DataInputView, DataOutputView} + +/** + * Serializer for [[Enumeration]] values. + */ +class EnumValueSerializer[E : Enumeration](val enum: E) extends TypeSerializer[E#Value] { + + type T = E#Value + + val intSerializer = new IntSerializer() + + override def duplicate: EnumValueSerializer[E] = this + + override def createInstance: T = enum(0) + + override def isImmutableType: Boolean = true + + override def getLength: Int = intSerializer.getLength + + override def copy(from: T): T = enum.apply(from.id) + + override def copy(from: T, reuse: T): T = copy(from) + + override def copy(src: DataInputView, tgt: DataOutputView): Unit = intSerializer.copy(src, tgt) + + override def serialize(v: T, tgt: DataOutputView): Unit = intSerializer.serialize(v.id, tgt) + + override def deserialize(source: DataInputView): T = enum(intSerializer.deserialize(source)) + + override def deserialize(reuse: T, source: DataInputView): T = deserialize(source) + + override def equals(obj: Any): Boolean = { --- End diff -- Can you also override `hashCode()` here? Keeps it consistent with overriding `equals()` --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] flink pull request: [FLINK-2231] Create a Serializer for Scala Enu...
Github user aljoscha commented on the pull request: https://github.com/apache/flink/pull/935#issuecomment-125936680 Merged, thanks for your work. :smile: --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] flink pull request: [FLINK-2231] Create a Serializer for Scala Enu...
Github user asfgit closed the pull request at: https://github.com/apache/flink/pull/935 --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] flink pull request: [FLINK-2231] Create a Serializer for Scala Enu...
Github user aljoscha commented on a diff in the pull request: https://github.com/apache/flink/pull/935#discussion_r35631275 --- Diff: flink-tests/src/test/scala/org/apache/flink/api/scala/runtime/ScalaSpecialTypesSerializerTest.scala --- @@ -93,8 +98,11 @@ class ScalaSpecialTypesSerializerTest { val typeInfo = implicitly[TypeInformation[T]] val serializer = typeInfo.createSerializer(new ExecutionConfig) val typeClass = typeInfo.getTypeClass - val test = + val test = if (typeInfo.isInstanceOf[EnumValueTypeInfo[_]]) { +new ScalaSpecialTypesSerializerTestInstance[T](serializer, typeClass, 4, instances) --- End diff -- We could use serializer.getLength here. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] flink pull request: [FLINK-2231] Create a Serializer for Scala Enu...
Github user aljoscha commented on the pull request: https://github.com/apache/flink/pull/935#issuecomment-125536383 Looks good, any objections to me merging this? I can fix the one comment I had about using serializer.getLength when I merge it. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] flink pull request: [FLINK-2231] Create a Serializer for Scala Enu...
GitHub user aalexandrov opened a pull request: https://github.com/apache/flink/pull/935 [FLINK-2231] Create a Serializer for Scala Enumerations. This closes FLINK-2231. The code should work for all objects which follow [the Enumeration idiom outlined in the ScalaDoc](http://www.scala-lang.org/api/2.11.5/index.html#scala.Enumeration). The second commit removes the boilerplate code from the `EnumValueComparator` by delegating to an `IntComparator`, you can either discard or squash it while merging depending on your preference. Bear in mind the FIXME at line 368 in `TypeAnalyzer.scala`. The commented code is better, but unfortunately doesn't work with Scala 2.10, so I used the FQN workaround. You can merge this pull request into a Git repository by running: $ git pull https://github.com/aalexandrov/flink FLINK-2231 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/flink/pull/935.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #935 commit fd69bda383f6771e87ded1b4b595a395519efd6e Author: Alexander Alexandrov alexander.s.alexand...@gmail.com Date: 2015-07-24T10:36:17Z [FLINK-2231] Create a Serializer for Scala Enumerations. commit dca03720d090c383f88a57af6808fdbfd2c4ec29 Author: Alexander Alexandrov alexander.s.alexand...@gmail.com Date: 2015-07-24T16:43:14Z Delegating EnumValueComparator. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] flink pull request: [FLINK-2231] Create a Serializer for Scala Enu...
Github user aalexandrov commented on the pull request: https://github.com/apache/flink/pull/935#issuecomment-124582468 PS. The third commit fixes a compilation error in IntelliJ when the 'scala_2.11' profile is active. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---