@@ -56,8 +56,9 @@ func (s *sparkConnectClientImpl) newExecutePlanRequest(plan *proto.Plan) *proto.
5656SessionId : s .sessionId ,
5757Plan : plan ,
5858UserContext : & proto.UserContext {
59- UserId : "na" ,
59+ UserId : s . opts . UserId ,
6060},
61+ ClientType : & s .opts .UserAgent ,
6162// Operation ID is needed for being able to reattach.
6263OperationId : & operationId ,
6364RequestOptions : []* proto.ExecutePlanRequest_RequestOption {
@@ -109,16 +110,22 @@ func (s *sparkConnectClientImpl) ExecutePlan(ctx context.Context, plan *proto.Pl
109110return NewExecuteResponseStream (c , s .sessionId , * request .OperationId , s .opts ), nil
110111}
111112
112- func (s * sparkConnectClientImpl ) AnalyzePlan (ctx context.Context , plan * proto.Plan ) (* proto.AnalyzePlanResponse , error ) {
113- request := proto.AnalyzePlanRequest {
113+ // Creates a new AnalyzePlanRequest with the necessary metadata.
114+ func (s * sparkConnectClientImpl ) newAnalyzePlanStub () proto.AnalyzePlanRequest {
115+ return proto.AnalyzePlanRequest {
114116SessionId : s .sessionId ,
115- Analyze : & proto.AnalyzePlanRequest_Schema_ {
116- Schema : & proto.AnalyzePlanRequest_Schema {
117- Plan : plan ,
118- },
119- },
120117UserContext : & proto.UserContext {
121- UserId : "na" ,
118+ UserId : s .opts .UserId ,
119+ },
120+ ClientType : & s .opts .UserAgent ,
121+ }
122+ }
123+
124+ func (s * sparkConnectClientImpl ) AnalyzePlan (ctx context.Context , plan * proto.Plan ) (* proto.AnalyzePlanResponse , error ) {
125+ request := s .newAnalyzePlanStub ()
126+ request .Analyze = & proto.AnalyzePlanRequest_Schema_ {
127+ Schema : & proto.AnalyzePlanRequest_Schema {
128+ Plan : plan ,
122129},
123130}
124131// Append the other items to the request.
@@ -149,17 +156,11 @@ func (s *sparkConnectClientImpl) Explain(ctx context.Context, plan *proto.Plan,
149156return nil , sparkerrors .WithType (fmt .Errorf ("unsupported explain mode %v" ,
150157explainMode ), sparkerrors .InvalidArgumentError )
151158}
152-
153- request := proto.AnalyzePlanRequest {
154- SessionId : s .sessionId ,
155- Analyze : & proto.AnalyzePlanRequest_Explain_ {
156- Explain : & proto.AnalyzePlanRequest_Explain {
157- Plan : plan ,
158- ExplainMode : mode ,
159- },
160- },
161- UserContext : & proto.UserContext {
162- UserId : "na" ,
159+ request := s .newAnalyzePlanStub ()
160+ request .Analyze = & proto.AnalyzePlanRequest_Explain_ {
161+ Explain : & proto.AnalyzePlanRequest_Explain {
162+ Plan : plan ,
163+ ExplainMode : mode ,
163164},
164165}
165166// Append the other items to the request.
@@ -174,17 +175,11 @@ func (s *sparkConnectClientImpl) Explain(ctx context.Context, plan *proto.Plan,
174175
175176func (s * sparkConnectClientImpl ) Persist (ctx context.Context , plan * proto.Plan , storageLevel utils.StorageLevel ) error {
176177protoLevel := utils .ToProtoStorageLevel (storageLevel )
177-
178- request := proto.AnalyzePlanRequest {
179- SessionId : s .sessionId ,
180- Analyze : & proto.AnalyzePlanRequest_Persist_ {
181- Persist : & proto.AnalyzePlanRequest_Persist {
182- Relation : plan .GetRoot (),
183- StorageLevel : protoLevel ,
184- },
185- },
186- UserContext : & proto.UserContext {
187- UserId : "na" ,
178+ request := s .newAnalyzePlanStub ()
179+ request .Analyze = & proto.AnalyzePlanRequest_Persist_ {
180+ Persist : & proto.AnalyzePlanRequest_Persist {
181+ Relation : plan .GetRoot (),
182+ StorageLevel : protoLevel ,
188183},
189184}
190185// Append the other items to the request.
@@ -198,15 +193,10 @@ func (s *sparkConnectClientImpl) Persist(ctx context.Context, plan *proto.Plan,
198193}
199194
200195func (s * sparkConnectClientImpl ) Unpersist (ctx context.Context , plan * proto.Plan ) error {
201- request := proto.AnalyzePlanRequest {
202- SessionId : s .sessionId ,
203- Analyze : & proto.AnalyzePlanRequest_Unpersist_ {
204- Unpersist : & proto.AnalyzePlanRequest_Unpersist {
205- Relation : plan .GetRoot (),
206- },
207- },
208- UserContext : & proto.UserContext {
209- UserId : "na" ,
196+ request := s .newAnalyzePlanStub ()
197+ request .Analyze = & proto.AnalyzePlanRequest_Unpersist_ {
198+ Unpersist : & proto.AnalyzePlanRequest_Unpersist {
199+ Relation : plan .GetRoot (),
210200},
211201}
212202// Append the other items to the request.
@@ -220,15 +210,10 @@ func (s *sparkConnectClientImpl) Unpersist(ctx context.Context, plan *proto.Plan
220210}
221211
222212func (s * sparkConnectClientImpl ) GetStorageLevel (ctx context.Context , plan * proto.Plan ) (* utils.StorageLevel , error ) {
223- request := proto.AnalyzePlanRequest {
224- SessionId : s .sessionId ,
225- Analyze : & proto.AnalyzePlanRequest_GetStorageLevel_ {
226- GetStorageLevel : & proto.AnalyzePlanRequest_GetStorageLevel {
227- Relation : plan .GetRoot (),
228- },
229- },
230- UserContext : & proto.UserContext {
231- UserId : "na" ,
213+ request := s .newAnalyzePlanStub ()
214+ request .Analyze = & proto.AnalyzePlanRequest_GetStorageLevel_ {
215+ GetStorageLevel : & proto.AnalyzePlanRequest_GetStorageLevel {
216+ Relation : plan .GetRoot (),
232217},
233218}
234219// Append the other items to the request.
@@ -245,14 +230,9 @@ func (s *sparkConnectClientImpl) GetStorageLevel(ctx context.Context, plan *prot
245230}
246231
247232func (s * sparkConnectClientImpl ) SparkVersion (ctx context.Context ) (string , error ) {
248- request := proto.AnalyzePlanRequest {
249- SessionId : s .sessionId ,
250- Analyze : & proto.AnalyzePlanRequest_SparkVersion_ {
251- SparkVersion : & proto.AnalyzePlanRequest_SparkVersion {},
252- },
253- UserContext : & proto.UserContext {
254- UserId : "na" ,
255- },
233+ request := s .newAnalyzePlanStub ()
234+ request .Analyze = & proto.AnalyzePlanRequest_SparkVersion_ {
235+ SparkVersion : & proto.AnalyzePlanRequest_SparkVersion {},
256236}
257237// Append the other items to the request.
258238ctx = metadata .NewOutgoingContext (ctx , s .metadata )
@@ -265,15 +245,10 @@ func (s *sparkConnectClientImpl) SparkVersion(ctx context.Context) (string, erro
265245}
266246
267247func (s * sparkConnectClientImpl ) DDLParse (ctx context.Context , sql string ) (* types.StructType , error ) {
268- request := proto.AnalyzePlanRequest {
269- SessionId : s .sessionId ,
270- Analyze : & proto.AnalyzePlanRequest_DdlParse {
271- DdlParse : & proto.AnalyzePlanRequest_DDLParse {
272- DdlString : sql ,
273- },
274- },
275- UserContext : & proto.UserContext {
276- UserId : "na" ,
248+ request := s .newAnalyzePlanStub ()
249+ request .Analyze = & proto.AnalyzePlanRequest_DdlParse {
250+ DdlParse : & proto.AnalyzePlanRequest_DDLParse {
251+ DdlString : sql ,
277252},
278253}
279254// Append the other items to the request.
@@ -287,16 +262,11 @@ func (s *sparkConnectClientImpl) DDLParse(ctx context.Context, sql string) (*typ
287262}
288263
289264func (s * sparkConnectClientImpl ) SameSemantics (ctx context.Context , plan1 * proto.Plan , plan2 * proto.Plan ) (bool , error ) {
290- request := proto.AnalyzePlanRequest {
291- SessionId : s .sessionId ,
292- Analyze : & proto.AnalyzePlanRequest_SameSemantics_ {
293- SameSemantics : & proto.AnalyzePlanRequest_SameSemantics {
294- TargetPlan : plan1 ,
295- OtherPlan : plan2 ,
296- },
297- },
298- UserContext : & proto.UserContext {
299- UserId : "na" ,
265+ request := s .newAnalyzePlanStub ()
266+ request .Analyze = & proto.AnalyzePlanRequest_SameSemantics_ {
267+ SameSemantics : & proto.AnalyzePlanRequest_SameSemantics {
268+ TargetPlan : plan1 ,
269+ OtherPlan : plan2 ,
300270},
301271}
302272// Append the other items to the request.
@@ -310,15 +280,10 @@ func (s *sparkConnectClientImpl) SameSemantics(ctx context.Context, plan1 *proto
310280}
311281
312282func (s * sparkConnectClientImpl ) SemanticHash (ctx context.Context , plan * proto.Plan ) (int32 , error ) {
313- request := proto.AnalyzePlanRequest {
314- SessionId : s .sessionId ,
315- Analyze : & proto.AnalyzePlanRequest_SemanticHash_ {
316- SemanticHash : & proto.AnalyzePlanRequest_SemanticHash {
317- Plan : plan ,
318- },
319- },
320- UserContext : & proto.UserContext {
321- UserId : "na" ,
283+ request := s .newAnalyzePlanStub ()
284+ request .Analyze = & proto.AnalyzePlanRequest_SemanticHash_ {
285+ SemanticHash : & proto.AnalyzePlanRequest_SemanticHash {
286+ Plan : plan ,
322287},
323288}
324289// Append the other items to the request.
@@ -337,8 +302,9 @@ func (s *sparkConnectClientImpl) Config(ctx context.Context,
337302request := & proto.ConfigRequest {
338303Operation : operation ,
339304UserContext : & proto.UserContext {
340- UserId : "na" ,
305+ UserId : s . opts . UserId ,
341306},
307+ ClientType : & s .opts .UserAgent ,
342308}
343309request .SessionId = s .sessionId
344310resp , err := s .client .Config (ctx , request )
0 commit comments