@@ -23,7 +23,6 @@ import java.util.{List => JList}
23
23
import scala .annotation .varargs
24
24
import scala .collection .mutable
25
25
import scala .jdk .CollectionConverters ._
26
- import scala .reflect .ClassTag
27
26
28
27
import org .json4s ._
29
28
import org .json4s .jackson .JsonMethods ._
@@ -46,20 +45,23 @@ import org.apache.spark.util.SizeEstimator
46
45
* See [[ParamValidators ]] for factory methods for common validation functions.
47
46
* @tparam T param value type
48
47
*/
49
- class Param [T : ClassTag ](
50
- val parent : String , val name : String , val doc : String , val isValid : T => Boolean )
51
- extends Serializable {
48
+ class Param [T ](
49
+ val parent : String , val name : String , val doc : String , val isValid : T => Boolean ,
50
+ val dataClass : Class [T ]
51
+ ) extends Serializable {
52
52
53
- // Spark Connect ML needs T type information which has been erased when compiling,
54
- // Use classTag to preserve the T type.
55
- val paramValueClassTag = implicitly[ClassTag [T ]]
53
+ def this (parent : String , name : String , doc : String , isValid : T => Boolean ) =
54
+ this (parent, name, doc, isValid, null )
56
55
57
56
def this (parent : Identifiable , name : String , doc : String , isValid : T => Boolean ) =
58
57
this (parent.uid, name, doc, isValid)
59
58
60
59
def this (parent : String , name : String , doc : String ) =
61
60
this (parent, name, doc, ParamValidators .alwaysTrue[T ])
62
61
62
+ def this (parent : String , name : String , doc : String , dataClass : Class [T ]) =
63
+ this (parent, name, doc, ParamValidators .alwaysTrue[T ], dataClass)
64
+
63
65
def this (parent : Identifiable , name : String , doc : String ) = this (parent.uid, name, doc)
64
66
65
67
/**
@@ -329,7 +331,7 @@ object ParamValidators {
329
331
* Specialized version of `Param[Double]` for Java.
330
332
*/
331
333
class DoubleParam (parent : String , name : String , doc : String , isValid : Double => Boolean )
332
- extends Param [Double ](parent, name, doc, isValid) {
334
+ extends Param [Double ](parent, name, doc, isValid, classOf [ Double ] ) {
333
335
334
336
def this (parent : String , name : String , doc : String ) =
335
337
this (parent, name, doc, ParamValidators .alwaysTrue)
@@ -387,7 +389,7 @@ private[param] object DoubleParam {
387
389
* Specialized version of `Param[Int]` for Java.
388
390
*/
389
391
class IntParam (parent : String , name : String , doc : String , isValid : Int => Boolean )
390
- extends Param [Int ](parent, name, doc, isValid) {
392
+ extends Param [Int ](parent, name, doc, isValid, classOf [ Int ] ) {
391
393
392
394
def this (parent : String , name : String , doc : String ) =
393
395
this (parent, name, doc, ParamValidators .alwaysTrue)
@@ -414,7 +416,7 @@ class IntParam(parent: String, name: String, doc: String, isValid: Int => Boolea
414
416
* Specialized version of `Param[Float]` for Java.
415
417
*/
416
418
class FloatParam (parent : String , name : String , doc : String , isValid : Float => Boolean )
417
- extends Param [Float ](parent, name, doc, isValid) {
419
+ extends Param [Float ](parent, name, doc, isValid, classOf [ Float ] ) {
418
420
419
421
def this (parent : String , name : String , doc : String ) =
420
422
this (parent, name, doc, ParamValidators .alwaysTrue)
@@ -473,7 +475,7 @@ private object FloatParam {
473
475
* Specialized version of `Param[Long]` for Java.
474
476
*/
475
477
class LongParam (parent : String , name : String , doc : String , isValid : Long => Boolean )
476
- extends Param [Long ](parent, name, doc, isValid) {
478
+ extends Param [Long ](parent, name, doc, isValid, classOf [ Long ] ) {
477
479
478
480
def this (parent : String , name : String , doc : String ) =
479
481
this (parent, name, doc, ParamValidators .alwaysTrue)
@@ -500,7 +502,8 @@ class LongParam(parent: String, name: String, doc: String, isValid: Long => Bool
500
502
* Specialized version of `Param[Boolean]` for Java.
501
503
*/
502
504
class BooleanParam (parent : String , name : String , doc : String ) // No need for isValid
503
- extends Param [Boolean ](parent, name, doc) {
505
+ extends Param [Boolean ](parent, name, doc, ParamValidators .alwaysTrue[Boolean ], classOf [Boolean ])
506
+ {
504
507
505
508
def this (parent : Identifiable , name : String , doc : String ) = this (parent.uid, name, doc)
506
509
@@ -521,7 +524,7 @@ class BooleanParam(parent: String, name: String, doc: String) // No need for isV
521
524
* Specialized version of `Param[Array[String]]` for Java.
522
525
*/
523
526
class StringArrayParam (parent : Params , name : String , doc : String , isValid : Array [String ] => Boolean )
524
- extends Param [Array [String ]](parent, name, doc, isValid) {
527
+ extends Param [Array [String ]](parent.uid , name, doc, isValid, classOf [ Array [ String ]] ) {
525
528
526
529
def this (parent : Params , name : String , doc : String ) =
527
530
this (parent, name, doc, ParamValidators .alwaysTrue)
@@ -544,7 +547,7 @@ class StringArrayParam(parent: Params, name: String, doc: String, isValid: Array
544
547
* Specialized version of `Param[Array[Double]]` for Java.
545
548
*/
546
549
class DoubleArrayParam (parent : Params , name : String , doc : String , isValid : Array [Double ] => Boolean )
547
- extends Param [Array [Double ]](parent, name, doc, isValid) {
550
+ extends Param [Array [Double ]](parent.uid , name, doc, isValid, classOf [ Array [ Double ]] ) {
548
551
549
552
def this (parent : Params , name : String , doc : String ) =
550
553
this (parent, name, doc, ParamValidators .alwaysTrue)
@@ -576,7 +579,9 @@ class DoubleArrayArrayParam(
576
579
name : String ,
577
580
doc : String ,
578
581
isValid : Array [Array [Double ]] => Boolean )
579
- extends Param [Array [Array [Double ]]](parent, name, doc, isValid) {
582
+ extends Param [Array [Array [Double ]]](
583
+ parent.uid, name, doc, isValid, classOf [Array [Array [Double ]]]
584
+ ) {
580
585
581
586
def this (parent : Params , name : String , doc : String ) =
582
587
this (parent, name, doc, ParamValidators .alwaysTrue)
@@ -610,7 +615,7 @@ class DoubleArrayArrayParam(
610
615
* Specialized version of `Param[Array[Int]]` for Java.
611
616
*/
612
617
class IntArrayParam (parent : Params , name : String , doc : String , isValid : Array [Int ] => Boolean )
613
- extends Param [Array [Int ]](parent, name, doc, isValid) {
618
+ extends Param [Array [Int ]](parent.uid , name, doc, isValid, classOf [ Array [ Int ]] ) {
614
619
615
620
def this (parent : Params , name : String , doc : String ) =
616
621
this (parent, name, doc, ParamValidators .alwaysTrue)
0 commit comments