Re: enum-like types in Spark

2015-07-02 Thread Imran Rashid
Hi Stephen, I'm not sure which link you are referring to for the example code -- but yes, the recommendation is that you create the enum in Java, eg. see https://github.com/apache/spark/blob/v1.4.0/core/src/main/java/org/apache/spark/status/api/v1/StageStatus.java Then nothing special is require

Re: enum-like types in Spark

2015-07-01 Thread Stephen Boesch
I am reviving an old thread here. The link for the example code for the java enum based solution is now dead: would someone please post an updated link showing the proper interop? Specifically: it is my understanding that java enum's may not be created within Scala. So is the proposed solution re

Re: enum-like types in Spark

2015-04-09 Thread Imran Rashid
any update here? This is relevant for a currently open PR of mine -- I've got a bunch of new public constants defined w/ format #4, but I'd gladly switch to java enums. (Even if we are just going to postpone this decision, I'm still inclined to switch to java enums ...) just to be clear about th

Re: enum-like types in Spark

2015-03-23 Thread Imran Rashid
well, perhaps I overstated things a little, I wouldn't call it the "official" solution, just a recommendation in the never-ending debate (and the recommendation from folks with their hands on scala itself). Even if we do get this fixed in scaladoc eventually -- as its not in the current versions,

Re: enum-like types in Spark

2015-03-23 Thread Reynold Xin
If scaladoc can show the Java enum types, I do think the best way is then just Java enum types. On Mon, Mar 23, 2015 at 2:11 PM, Patrick Wendell wrote: > If the official solution from the Scala community is to use Java > enums, then it seems strange they aren't generated in scaldoc? Maybe > we

Re: enum-like types in Spark

2015-03-23 Thread Patrick Wendell
If the official solution from the Scala community is to use Java enums, then it seems strange they aren't generated in scaldoc? Maybe we can just fix that w/ Typesafe's help and then we can use them. On Mon, Mar 23, 2015 at 1:46 PM, Sean Owen wrote: > Yeah the fully realized #4, which gets back t

Re: enum-like types in Spark

2015-03-23 Thread Aaron Davidson
The only issue I knew of with Java enums was that it does not appear in the Scala documentation. On Mon, Mar 23, 2015 at 1:46 PM, Sean Owen wrote: > Yeah the fully realized #4, which gets back the ability to use it in > switch statements (? in Scala but not Java?) does end up being kind of > hug

Re: enum-like types in Spark

2015-03-23 Thread Sean Owen
Yeah the fully realized #4, which gets back the ability to use it in switch statements (? in Scala but not Java?) does end up being kind of huge. I confess I'm swayed a bit back to Java enums, seeing what it involves. The hashCode() issue can be 'solved' with the hash of the String representation.

Re: enum-like types in Spark

2015-03-23 Thread Imran Rashid
I've just switched some of my code over to the new format, and I just want to make sure everyone realizes what we are getting into. I went from 10 lines as java enums https://github.com/squito/spark/blob/fef66058612ebf225e58dd5f5fea6bae1afd5b31/core/src/main/java/org/apache/spark/status/api/Stage

Re: enum-like types in Spark

2015-03-17 Thread Xiangrui Meng
Let me put a quick summary. #4 got majority vote with CamelCase but not UPPERCASE. The following is a minimal implementation that works for both Scala and Java. In Python, we use string for enums. This proposal is only for new public APIs. We are not going to change existing ones. -Xiangrui ~~~ se

Re: enum-like types in Spark

2015-03-16 Thread Aaron Davidson
It's unrelated to the proposal, but Enum#ordinal() should be much faster, assuming it's not serialized to JVMs with different versions of the enum :) On Mon, Mar 16, 2015 at 12:12 PM, Kevin Markey wrote: > In some applications, I have rather heavy use of Java enums which are > needed for related

Re: enum-like types in Spark

2015-03-16 Thread Patrick Wendell
Hey Xiangrui, Do you want to write up a straw man proposal based on this line of discussion? - Patrick On Mon, Mar 16, 2015 at 12:12 PM, Kevin Markey wrote: > In some applications, I have rather heavy use of Java enums which are needed > for related Java APIs that the application uses. And unf

Re: enum-like types in Spark

2015-03-16 Thread Kevin Markey
In some applications, I have rather heavy use of Java enums which are needed for related Java APIs that the application uses. And unfortunately, they are also used as keys. As such, using the native hashcodes makes any function over keys unstable and unpredictable, so we now use Enum.name() a

Re: enum-like types in Spark

2015-03-16 Thread Xiangrui Meng
In MLlib, we use strings for emu-like types in Python APIs, which is quite common in Python and easy for py4j. On the JVM side, we implement `fromString` to convert them back to enums. -Xiangrui On Wed, Mar 11, 2015 at 12:56 PM, RJ Nowling wrote: > How do these proposals affect PySpark? I think

Re: enum-like types in Spark

2015-03-11 Thread RJ Nowling
How do these proposals affect PySpark? I think compatibility with PySpark through Py4J should be considered. On Mon, Mar 9, 2015 at 8:39 PM, Patrick Wendell wrote: > Does this matter for our own internal types in Spark? I don't think > any of these types are designed to be used in RDD records,

Re: enum-like types in Spark

2015-03-09 Thread Patrick Wendell
Does this matter for our own internal types in Spark? I don't think any of these types are designed to be used in RDD records, for instance. On Mon, Mar 9, 2015 at 6:25 PM, Aaron Davidson wrote: > Perhaps the problem with Java enums that was brought up was actually that > their hashCode is not st

Re: enum-like types in Spark

2015-03-09 Thread Aaron Davidson
Perhaps the problem with Java enums that was brought up was actually that their hashCode is not stable across JVMs, as it depends on the memory location of the enum itself. On Mon, Mar 9, 2015 at 6:15 PM, Imran Rashid wrote: > Can you expand on the serde issues w/ java enum's at all? I haven't

Re: enum-like types in Spark

2015-03-09 Thread Imran Rashid
Can you expand on the serde issues w/ java enum's at all? I haven't heard of any problems specific to enums. The java object serialization rules seem very clear and it doesn't seem like different jvms should have a choice on what they do: http://docs.oracle.com/javase/6/docs/platform/serializati

Re: enum-like types in Spark

2015-03-06 Thread Sean Owen
This has some disadvantage for Java, I think. You can't switch on an object defined like this, but you can with an enum. And although the scala compiler understands that the set of values is fixed because of 'sealed' and so can warn about missing cases, the JVM won't know this, and can't do the sam

Re: enum-like types in Spark

2015-03-05 Thread Mridul Muralidharan
I have a strong dislike for java enum's due to the fact that they are not stable across JVM's - if it undergoes serde, you end up with unpredictable results at times [1]. One of the reasons why we prevent enum's from being key : though it is highly possible users might depend on it internally and

Re: enum-like types in Spark

2015-03-05 Thread Xiangrui Meng
For #4, my previous proposal may confuse the IDEs with additional types generated by the case objects, and their toString contain the underscore. The following works better: sealed abstract class StorageLevel object StorageLevel { final val MemoryOnly: StorageLevel = { case object MemoryOnl

Re: enum-like types in Spark

2015-03-05 Thread Imran Rashid
I have a very strong dislike for #1 (scala enumerations). I'm ok with #4 (with Xiangrui's final suggestion, especially making it sealed & available in Java), but I really think #2, java enums, are the best option. Java enums actually have some very real advantages over the other approaches -- yo

Re: enum-like types in Spark

2015-03-05 Thread Patrick Wendell
Yes - only new or internal API's. I doubt we'd break any exposed APIs for the purpose of clean up. Patrick On Mar 5, 2015 12:16 AM, "Mridul Muralidharan" wrote: > While I dont have any strong opinions about how we handle enum's > either way in spark, I assume the discussion is targetted at (new)

Re: enum-like types in Spark

2015-03-05 Thread Mridul Muralidharan
While I dont have any strong opinions about how we handle enum's either way in spark, I assume the discussion is targetted at (new) api being designed in spark. Rewiring what we already have exposed will lead to incompatible api change (StorageLevel for example, is in 1.0). Regards, Mridul On Wed

Re: enum-like types in Spark

2015-03-04 Thread Aaron Davidson
That's kinda annoying, but it's just a little extra boilerplate. Can you call it as StorageLevel.DiskOnly() from Java? Would it also work if they were case classes with empty constructors, without the field? On Wed, Mar 4, 2015 at 11:35 PM, Xiangrui Meng wrote: > `case object` inside an `object`

Re: enum-like types in Spark

2015-03-04 Thread Xiangrui Meng
`case object` inside an `object` doesn't show up in Java. This is the minimal code I found to make everything show up correctly in both Scala and Java: sealed abstract class StorageLevel // cannot be a trait object StorageLevel { private[this] case object _MemoryOnly extends StorageLevel fina

Re: enum-like types in Spark

2015-03-04 Thread Patrick Wendell
I like #4 as well and agree with Aaron's suggestion. - Patrick On Wed, Mar 4, 2015 at 6:07 PM, Aaron Davidson wrote: > I'm cool with #4 as well, but make sure we dictate that the values should > be defined within an object with the same name as the enumeration (like we > do for StorageLevel). Ot

Re: enum-like types in Spark

2015-03-04 Thread Aaron Davidson
I'm cool with #4 as well, but make sure we dictate that the values should be defined within an object with the same name as the enumeration (like we do for StorageLevel). Otherwise we may pollute a higher namespace. e.g. we SHOULD do: trait StorageLevel object StorageLevel { case object MemoryO

Re: enum-like types in Spark

2015-03-04 Thread Michael Armbrust
#4 with a preference for CamelCaseEnums On Wed, Mar 4, 2015 at 5:29 PM, Joseph Bradley wrote: > another vote for #4 > People are already used to adding "()" in Java. > > > On Wed, Mar 4, 2015 at 5:14 PM, Stephen Boesch wrote: > > > #4 but with MemoryOnly (more scala-like) > > > > http://docs.sc

Re: enum-like types in Spark

2015-03-04 Thread Joseph Bradley
another vote for #4 People are already used to adding "()" in Java. On Wed, Mar 4, 2015 at 5:14 PM, Stephen Boesch wrote: > #4 but with MemoryOnly (more scala-like) > > http://docs.scala-lang.org/style/naming-conventions.html > > Constants, Values, Variable and Methods > > Constant names should

Re: enum-like types in Spark

2015-03-04 Thread Stephen Boesch
#4 but with MemoryOnly (more scala-like) http://docs.scala-lang.org/style/naming-conventions.html Constants, Values, Variable and Methods Constant names should be in upper camel case. That is, if the member is final, immutable and it belongs to a package object or an object, it may be considered