Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 7127E200CBA for ; Mon, 3 Jul 2017 23:44:54 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 6FD62160BEC; Mon, 3 Jul 2017 21:44:54 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id DC5F8160BD2 for ; Mon, 3 Jul 2017 23:44:53 +0200 (CEST) Received: (qmail 38757 invoked by uid 500); 3 Jul 2017 21:44:53 -0000 Mailing-List: contact reviews-help@spark.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list reviews@spark.apache.org Received: (qmail 38746 invoked by uid 99); 3 Jul 2017 21:44:52 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jul 2017 21:44:52 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3AB04DFB30; Mon, 3 Jul 2017 21:44:51 +0000 (UTC) From: mike0sv To: reviews@spark.apache.org Reply-To: reviews@spark.apache.org References: In-Reply-To: Subject: [GitHub] spark pull request #18488: [SPARK-21255][SQL][WIP] Fixed NPE when creating e... Content-Type: text/plain Message-Id: <20170703214452.3AB04DFB30@git1-us-west.apache.org> Date: Mon, 3 Jul 2017 21:44:51 +0000 (UTC) archived-at: Mon, 03 Jul 2017 21:44:54 -0000 Github user mike0sv commented on a diff in the pull request: https://github.com/apache/spark/pull/18488#discussion_r125360539 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/JavaTypeInference.scala --- @@ -344,6 +352,28 @@ object JavaTypeInference { } } + /** Returns a mapping from enum value to int for given enum type */ + def enumSerializer[T](enum: Class[T]): T => Int = { + assert(enum.isEnum) + enum.getEnumConstants.toList.zipWithIndex.toMap + } + + /** Returns value index for given enum type and value */ + def serializeEnumName[T](enum: UTF8String, inputObject: T): Int = { + enumSerializer(Utils.classForName(enum.toString).asInstanceOf[Class[T]])(inputObject) + } + + /** Returns a mapping from int to enum value for given enum type */ + def enumDeserializer[T](enum: Class[T]): Int => T = { --- End diff -- Good point. But if we use string values, there is already a hashmap inside enum implementation, accessible via valueOf. --- 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 infrastructure@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org For additional commands, e-mail: reviews-help@spark.apache.org