@@ -83,6 +83,8 @@ class SparkContext(config: SparkConf) extends Logging {
83
83
// contains a map from hostname to a list of input format splits on the host.
84
84
private [spark] var preferredNodeLocationData : Map [String , Set [SplitInfo ]] = Map ()
85
85
86
+ val startTime = System .currentTimeMillis()
87
+
86
88
/**
87
89
* Create a SparkContext that loads settings from system properties (for instance, when
88
90
* launching with ./bin/spark-submit).
@@ -269,8 +271,6 @@ class SparkContext(config: SparkConf) extends Logging {
269
271
/** A default Hadoop Configuration for the Hadoop code (e.g. file systems) that we reuse. */
270
272
val hadoopConfiguration = SparkHadoopUtil .get.newConfiguration(conf)
271
273
272
- val startTime = System .currentTimeMillis()
273
-
274
274
// Add each JAR given through the constructor
275
275
if (jars != null ) {
276
276
jars.foreach(addJar)
@@ -1624,47 +1624,74 @@ object SparkContext extends Logging {
1624
1624
1625
1625
private [spark] val DRIVER_IDENTIFIER = " <driver>"
1626
1626
1627
- implicit object DoubleAccumulatorParam extends AccumulatorParam [Double ] {
1627
+ // The following deprecated objects have already been copied to `object AccumulatorParam` to
1628
+ // make the compiler find them automatically. They are duplicate codes only for backward
1629
+ // compatibility, please update `object AccumulatorParam` accordingly if you plan to modify the
1630
+ // following ones.
1631
+
1632
+ @ deprecated(" Replaced by implicit objects in AccumulatorParam. This is kept here only for " +
1633
+ " backward compatibility." , " 1.2.0" )
1634
+ object DoubleAccumulatorParam extends AccumulatorParam [Double ] {
1628
1635
def addInPlace (t1 : Double , t2 : Double ): Double = t1 + t2
1629
1636
def zero (initialValue : Double ) = 0.0
1630
1637
}
1631
1638
1632
- implicit object IntAccumulatorParam extends AccumulatorParam [Int ] {
1639
+ @ deprecated(" Replaced by implicit objects in AccumulatorParam. This is kept here only for " +
1640
+ " backward compatibility." , " 1.2.0" )
1641
+ object IntAccumulatorParam extends AccumulatorParam [Int ] {
1633
1642
def addInPlace (t1 : Int , t2 : Int ): Int = t1 + t2
1634
1643
def zero (initialValue : Int ) = 0
1635
1644
}
1636
1645
1637
- implicit object LongAccumulatorParam extends AccumulatorParam [Long ] {
1646
+ @ deprecated(" Replaced by implicit objects in AccumulatorParam. This is kept here only for " +
1647
+ " backward compatibility." , " 1.2.0" )
1648
+ object LongAccumulatorParam extends AccumulatorParam [Long ] {
1638
1649
def addInPlace (t1 : Long , t2 : Long ) = t1 + t2
1639
1650
def zero (initialValue : Long ) = 0L
1640
1651
}
1641
1652
1642
- implicit object FloatAccumulatorParam extends AccumulatorParam [Float ] {
1653
+ @ deprecated(" Replaced by implicit objects in AccumulatorParam. This is kept here only for " +
1654
+ " backward compatibility." , " 1.2.0" )
1655
+ object FloatAccumulatorParam extends AccumulatorParam [Float ] {
1643
1656
def addInPlace (t1 : Float , t2 : Float ) = t1 + t2
1644
1657
def zero (initialValue : Float ) = 0f
1645
1658
}
1646
1659
1647
- // TODO: Add AccumulatorParams for other types, e.g. lists and strings
1660
+ // The following deprecated functions have already been moved to `object RDD` to
1661
+ // make the compiler find them automatically. They are still kept here for backward compatibility
1662
+ // and just call the corresponding functions in `object RDD`.
1648
1663
1649
- implicit def rddToPairRDDFunctions [K , V ](rdd : RDD [(K , V )])
1664
+ @ deprecated(" Replaced by implicit functions in the RDD companion object. This is " +
1665
+ " kept here only for backward compatibility." , " 1.2.0" )
1666
+ def rddToPairRDDFunctions [K , V ](rdd : RDD [(K , V )])
1650
1667
(implicit kt : ClassTag [K ], vt : ClassTag [V ], ord : Ordering [K ] = null ) = {
1651
- new PairRDDFunctions (rdd)
1668
+ RDD .rddToPairRDDFunctions (rdd)
1652
1669
}
1653
1670
1654
- implicit def rddToAsyncRDDActions [T : ClassTag ](rdd : RDD [T ]) = new AsyncRDDActions (rdd)
1671
+ @ deprecated(" Replaced by implicit functions in the RDD companion object. This is " +
1672
+ " kept here only for backward compatibility." , " 1.2.0" )
1673
+ def rddToAsyncRDDActions [T : ClassTag ](rdd : RDD [T ]) = RDD .rddToAsyncRDDActions(rdd)
1655
1674
1656
- implicit def rddToSequenceFileRDDFunctions [K <% Writable : ClassTag , V <% Writable : ClassTag ](
1675
+ @ deprecated(" Replaced by implicit functions in the RDD companion object. This is " +
1676
+ " kept here only for backward compatibility." , " 1.2.0" )
1677
+ def rddToSequenceFileRDDFunctions [K <% Writable : ClassTag , V <% Writable : ClassTag ](
1657
1678
rdd : RDD [(K , V )]) =
1658
- new SequenceFileRDDFunctions (rdd)
1679
+ RDD .rddToSequenceFileRDDFunctions (rdd)
1659
1680
1660
- implicit def rddToOrderedRDDFunctions [K : Ordering : ClassTag , V : ClassTag ](
1681
+ @ deprecated(" Replaced by implicit functions in the RDD companion object. This is " +
1682
+ " kept here only for backward compatibility." , " 1.2.0" )
1683
+ def rddToOrderedRDDFunctions [K : Ordering : ClassTag , V : ClassTag ](
1661
1684
rdd : RDD [(K , V )]) =
1662
- new OrderedRDDFunctions [ K , V , ( K , V )] (rdd)
1685
+ RDD .rddToOrderedRDDFunctions (rdd)
1663
1686
1664
- implicit def doubleRDDToDoubleRDDFunctions (rdd : RDD [Double ]) = new DoubleRDDFunctions (rdd)
1687
+ @ deprecated(" Replaced by implicit functions in the RDD companion object. This is " +
1688
+ " kept here only for backward compatibility." , " 1.2.0" )
1689
+ def doubleRDDToDoubleRDDFunctions (rdd : RDD [Double ]) = RDD .doubleRDDToDoubleRDDFunctions(rdd)
1665
1690
1666
- implicit def numericRDDToDoubleRDDFunctions [T ](rdd : RDD [T ])(implicit num : Numeric [T ]) =
1667
- new DoubleRDDFunctions (rdd.map(x => num.toDouble(x)))
1691
+ @ deprecated(" Replaced by implicit functions in the RDD companion object. This is " +
1692
+ " kept here only for backward compatibility." , " 1.2.0" )
1693
+ def numericRDDToDoubleRDDFunctions [T ](rdd : RDD [T ])(implicit num : Numeric [T ]) =
1694
+ RDD .numericRDDToDoubleRDDFunctions(rdd)
1668
1695
1669
1696
// Implicit conversions to common Writable types, for saveAsSequenceFile
1670
1697
@@ -1690,40 +1717,49 @@ object SparkContext extends Logging {
1690
1717
arr.map(x => anyToWritable(x)).toArray)
1691
1718
}
1692
1719
1693
- // Helper objects for converting common types to Writable
1694
- private def simpleWritableConverter [T , W <: Writable : ClassTag ](convert : W => T )
1695
- : WritableConverter [T ] = {
1696
- val wClass = classTag[W ].runtimeClass.asInstanceOf [Class [W ]]
1697
- new WritableConverter [T ](_ => wClass, x => convert(x.asInstanceOf [W ]))
1698
- }
1720
+ // The following deprecated functions have already been moved to `object WritableConverter` to
1721
+ // make the compiler find them automatically. They are still kept here for backward compatibility
1722
+ // and just call the corresponding functions in `object WritableConverter`.
1699
1723
1700
- implicit def intWritableConverter (): WritableConverter [Int ] =
1701
- simpleWritableConverter[Int , IntWritable ](_.get)
1724
+ @ deprecated(" Replaced by implicit functions in WritableConverter. This is kept here only for " +
1725
+ " backward compatibility." , " 1.2.0" )
1726
+ def intWritableConverter (): WritableConverter [Int ] =
1727
+ WritableConverter .intWritableConverter()
1702
1728
1703
- implicit def longWritableConverter (): WritableConverter [Long ] =
1704
- simpleWritableConverter[Long , LongWritable ](_.get)
1729
+ @ deprecated(" Replaced by implicit functions in WritableConverter. This is kept here only for " +
1730
+ " backward compatibility." , " 1.2.0" )
1731
+ def longWritableConverter (): WritableConverter [Long ] =
1732
+ WritableConverter .longWritableConverter()
1705
1733
1706
- implicit def doubleWritableConverter (): WritableConverter [Double ] =
1707
- simpleWritableConverter[Double , DoubleWritable ](_.get)
1734
+ @ deprecated(" Replaced by implicit functions in WritableConverter. This is kept here only for " +
1735
+ " backward compatibility." , " 1.2.0" )
1736
+ def doubleWritableConverter (): WritableConverter [Double ] =
1737
+ WritableConverter .doubleWritableConverter()
1708
1738
1709
- implicit def floatWritableConverter (): WritableConverter [Float ] =
1710
- simpleWritableConverter[Float , FloatWritable ](_.get)
1739
+ @ deprecated(" Replaced by implicit functions in WritableConverter. This is kept here only for " +
1740
+ " backward compatibility." , " 1.2.0" )
1741
+ def floatWritableConverter (): WritableConverter [Float ] =
1742
+ WritableConverter .floatWritableConverter()
1711
1743
1712
- implicit def booleanWritableConverter (): WritableConverter [Boolean ] =
1713
- simpleWritableConverter[Boolean , BooleanWritable ](_.get)
1744
+ @ deprecated(" Replaced by implicit functions in WritableConverter. This is kept here only for " +
1745
+ " backward compatibility." , " 1.2.0" )
1746
+ def booleanWritableConverter (): WritableConverter [Boolean ] =
1747
+ WritableConverter .booleanWritableConverter()
1714
1748
1715
- implicit def bytesWritableConverter (): WritableConverter [Array [Byte ]] = {
1716
- simpleWritableConverter[Array [Byte ], BytesWritable ](bw =>
1717
- // getBytes method returns array which is longer then data to be returned
1718
- Arrays .copyOfRange(bw.getBytes, 0 , bw.getLength)
1719
- )
1720
- }
1749
+ @ deprecated(" Replaced by implicit functions in WritableConverter. This is kept here only for " +
1750
+ " backward compatibility." , " 1.2.0" )
1751
+ def bytesWritableConverter (): WritableConverter [Array [Byte ]] =
1752
+ WritableConverter .bytesWritableConverter()
1721
1753
1722
- implicit def stringWritableConverter (): WritableConverter [String ] =
1723
- simpleWritableConverter[String , Text ](_.toString)
1754
+ @ deprecated(" Replaced by implicit functions in WritableConverter. This is kept here only for " +
1755
+ " backward compatibility." , " 1.2.0" )
1756
+ def stringWritableConverter (): WritableConverter [String ] =
1757
+ WritableConverter .stringWritableConverter()
1724
1758
1725
- implicit def writableWritableConverter [T <: Writable ]() =
1726
- new WritableConverter [T ](_.runtimeClass.asInstanceOf [Class [T ]], _.asInstanceOf [T ])
1759
+ @ deprecated(" Replaced by implicit functions in WritableConverter. This is kept here only for " +
1760
+ " backward compatibility." , " 1.2.0" )
1761
+ def writableWritableConverter [T <: Writable ]() =
1762
+ WritableConverter .writableWritableConverter()
1727
1763
1728
1764
/**
1729
1765
* Find the JAR from which a given class was loaded, to make it easy for users to pass
@@ -1950,3 +1986,46 @@ private[spark] class WritableConverter[T](
1950
1986
val writableClass : ClassTag [T ] => Class [_ <: Writable ],
1951
1987
val convert : Writable => T )
1952
1988
extends Serializable
1989
+
1990
+ object WritableConverter {
1991
+
1992
+ // Helper objects for converting common types to Writable
1993
+ private [spark] def simpleWritableConverter [T , W <: Writable : ClassTag ](convert : W => T )
1994
+ : WritableConverter [T ] = {
1995
+ val wClass = classTag[W ].runtimeClass.asInstanceOf [Class [W ]]
1996
+ new WritableConverter [T ](_ => wClass, x => convert(x.asInstanceOf [W ]))
1997
+ }
1998
+
1999
+ // The following implicit functions were in SparkContext before 1.2 and users had to
2000
+ // `import SparkContext._` to enable them. Now we move them here to make the compiler find
2001
+ // them automatically. However, we still keep the old functions in SparkContext for backward
2002
+ // compatibility and forward to the following functions directly.
2003
+
2004
+ implicit def intWritableConverter (): WritableConverter [Int ] =
2005
+ simpleWritableConverter[Int , IntWritable ](_.get)
2006
+
2007
+ implicit def longWritableConverter (): WritableConverter [Long ] =
2008
+ simpleWritableConverter[Long , LongWritable ](_.get)
2009
+
2010
+ implicit def doubleWritableConverter (): WritableConverter [Double ] =
2011
+ simpleWritableConverter[Double , DoubleWritable ](_.get)
2012
+
2013
+ implicit def floatWritableConverter (): WritableConverter [Float ] =
2014
+ simpleWritableConverter[Float , FloatWritable ](_.get)
2015
+
2016
+ implicit def booleanWritableConverter (): WritableConverter [Boolean ] =
2017
+ simpleWritableConverter[Boolean , BooleanWritable ](_.get)
2018
+
2019
+ implicit def bytesWritableConverter (): WritableConverter [Array [Byte ]] = {
2020
+ simpleWritableConverter[Array [Byte ], BytesWritable ](bw =>
2021
+ // getBytes method returns array which is longer then data to be returned
2022
+ Arrays .copyOfRange(bw.getBytes, 0 , bw.getLength)
2023
+ )
2024
+ }
2025
+
2026
+ implicit def stringWritableConverter (): WritableConverter [String ] =
2027
+ simpleWritableConverter[String , Text ](_.toString)
2028
+
2029
+ implicit def writableWritableConverter [T <: Writable ]() =
2030
+ new WritableConverter [T ](_.runtimeClass.asInstanceOf [Class [T ]], _.asInstanceOf [T ])
2031
+ }
0 commit comments