@@ -24,7 +24,7 @@ import javax.annotation.concurrent.GuardedBy
24
24
import scala .collection .mutable .ListBuffer
25
25
26
26
import org .apache .spark .internal .Logging
27
- import org .apache .spark .sql .{Encoder , SparkSession }
27
+ import org .apache .spark .sql .{Encoder , SparkSession , SQLContext }
28
28
import org .apache .spark .sql .catalyst .InternalRow
29
29
import org .apache .spark .sql .catalyst .encoders .{encoderFor , ExpressionEncoder }
30
30
import org .apache .spark .sql .catalyst .expressions .UnsafeRow
@@ -43,7 +43,7 @@ import org.apache.spark.sql.internal.connector.SimpleTableProvider
43
43
import org .apache .spark .sql .types .StructType
44
44
import org .apache .spark .sql .util .CaseInsensitiveStringMap
45
45
46
- object MemoryStream {
46
+ object MemoryStream extends LowPriorityMemoryStreamImplicits {
47
47
protected val currentBlockId = new AtomicInteger (0 )
48
48
protected val memoryStreamId = new AtomicInteger (0 )
49
49
@@ -54,6 +54,27 @@ object MemoryStream {
54
54
new MemoryStream [A ](memoryStreamId.getAndIncrement(), sparkSession, Some (numPartitions))
55
55
}
56
56
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
+
57
78
/**
58
79
* A base class for memory stream implementations. Supports adding data and resetting.
59
80
*/
0 commit comments