grundprinzip commented on code in PR #82:
URL: https://github.com/apache/spark-connect-go/pull/82#discussion_r1815589181


##########
spark/client/conf.go:
##########
@@ -0,0 +1,122 @@
+package client
+
+import (
+       "context"
+
+       proto "github.com/apache/spark-connect-go/v35/internal/generated"
+       "github.com/apache/spark-connect-go/v35/spark/client/base"
+)
+
+// Public interface RuntimeConfig
+type RuntimeConfig interface {
+       GetAll(ctx context.Context) (map[string]string, error)
+       Set(ctx context.Context, key string, value string) error
+       Get(ctx context.Context, key string) (map[string]string, error)
+       Unset(ctx context.Context, key string) error
+       IsModifiable(ctx context.Context, key string) (map[string]string, error)
+       GetWithDefault(ctx context.Context, key string, default_value string) 
(map[string]string, error)
+}
+
+// private type with private member client
+type runtimeConfig struct {
+       client *base.SparkConnectClient
+}
+
+// GetAll returns all configured keys in a map of strings
+func (r runtimeConfig) GetAll(ctx context.Context) (map[string]string, error) {
+       req := &proto.ConfigRequest_GetAll{}
+       operation := &proto.ConfigRequest_Operation_GetAll{GetAll: req}
+       op := &proto.ConfigRequest_Operation{OpType: operation}
+       resp, err := (*r.client).Config(ctx, op)
+       if err != nil {
+               return nil, err
+       }
+       m := make(map[string]string, 0)
+       for _, k := range resp.GetPairs() {
+               if k.Value != nil {
+                       m[k.Key] = *k.Value
+               }
+       }
+       return m, nil
+}
+
+// Set takes a key and a value and sets it in the config
+func (r runtimeConfig) Set(ctx context.Context, key string, value string) 
error {
+       reqArr := []*proto.KeyValue{{Key: key, Value: &value}}
+       req := &proto.ConfigRequest_Set{
+               Pairs: reqArr,
+       }
+       op := &proto.ConfigRequest_Operation{OpType: 
&proto.ConfigRequest_Operation_Set{Set: req}}
+       _, err := (*r.client).Config(ctx, op)
+       if err != nil {
+               return err
+       }
+       return nil
+}
+
+func (r runtimeConfig) Get(ctx context.Context, key string) 
(map[string]string, error) {
+       req := &proto.ConfigRequest_Get{Keys: []string{key}}
+       operation := &proto.ConfigRequest_Operation_Get{Get: req}
+       op := &proto.ConfigRequest_Operation{OpType: operation}
+       resp, err := (*r.client).Config(ctx, op)
+       if err != nil {
+               return nil, err
+       }
+       m := make(map[string]string, 0)
+       for _, k := range resp.GetPairs() {
+               if k.Value != nil {
+                       m[k.Key] = *k.Value
+               }
+       }
+       return m, nil
+}

Review Comment:
   since get only returns a single value this will make this code easier as 
well.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to