@@ -24,7 +24,7 @@ import javax.annotation.concurrent.GuardedBy
2424import scala .collection .mutable .ListBuffer
2525
2626import org .apache .spark .internal .Logging
27- import org .apache .spark .sql .{Encoder , SparkSession }
27+ import org .apache .spark .sql .{Encoder , SparkSession , SQLContext }
2828import org .apache .spark .sql .catalyst .InternalRow
2929import org .apache .spark .sql .catalyst .encoders .{encoderFor , ExpressionEncoder }
3030import org .apache .spark .sql .catalyst .expressions .UnsafeRow
@@ -43,7 +43,7 @@ import org.apache.spark.sql.internal.connector.SimpleTableProvider
4343import org .apache .spark .sql .types .StructType
4444import org .apache .spark .sql .util .CaseInsensitiveStringMap
4545
46- object MemoryStream {
46+ object MemoryStream extends LowPriorityMemoryStreamImplicits {
4747 protected val currentBlockId = new AtomicInteger (0 )
4848 protected val memoryStreamId = new AtomicInteger (0 )
4949
@@ -54,6 +54,27 @@ object MemoryStream {
5454 new MemoryStream [A ](memoryStreamId.getAndIncrement(), sparkSession, Some (numPartitions))
5555}
5656
57+ /**
58+ * Provides lower-priority implicits for MemoryStream to prevent ambiguity when both
59+ * SparkSession and SQLContext are in scope. The implicits in the companion object,
60+ * which use SparkSession, take higher precedence.
61+ */
62+ trait LowPriorityMemoryStreamImplicits {
63+ this : MemoryStream .type =>
64+
65+ // Deprecated: Used when an implicit SQLContext is in scope
66+ @ deprecated(" Use MemoryStream.apply with an implicit SparkSession instead of SQLContext" , " 4.1.0" )
67+ def apply [A : Encoder ]()(implicit sqlContext : SQLContext ): MemoryStream [A ] =
68+ new MemoryStream [A ](memoryStreamId.getAndIncrement(), sqlContext.sparkSession)
69+
70+ @ deprecated(" Use MemoryStream.apply with an implicit SparkSession instead of SQLContext" , " 4.1.0" )
71+ def apply [A : Encoder ](numPartitions : Int )(implicit sqlContext : SQLContext ): MemoryStream [A ] =
72+ new MemoryStream [A ](
73+ memoryStreamId.getAndIncrement(),
74+ sqlContext.sparkSession,
75+ Some (numPartitions))
76+ }
77+
5778/**
5879 * A base class for memory stream implementations. Supports adding data and resetting.
5980 */
0 commit comments