Class: SparkConnect::RuntimeConfig
- Inherits:
-
Object
- Object
- SparkConnect::RuntimeConfig
- Defined in:
- lib/spark_connect/conf.rb
Overview
Runtime configuration interface, returned by SparkSession#conf. Mirrors PySpark’s ‘spark.conf`.
Constant Summary collapse
- Proto =
SparkConnect::Proto
- Op =
Proto::ConfigRequest::Operation
- CR =
Proto::ConfigRequest
Instance Method Summary collapse
-
#get(key, default = :__unset__) ⇒ String?
Get the value of a configuration property.
-
#get_all(prefix = nil) ⇒ Hash{String=>String}
All configuration properties (optionally filtered by ‘prefix`).
-
#initialize(client) ⇒ RuntimeConfig
constructor
A new instance of RuntimeConfig.
-
#modifiable?(key) ⇒ Boolean
Whether a configuration property is modifiable in the current session.
-
#set(key, value) ⇒ void
Set a configuration property.
-
#unset(key) ⇒ void
Unset a configuration property.
Constructor Details
#initialize(client) ⇒ RuntimeConfig
Returns a new instance of RuntimeConfig.
16 17 18 |
# File 'lib/spark_connect/conf.rb', line 16 def initialize(client) @client = client end |
Instance Method Details
#get(key, default = :__unset__) ⇒ String?
Get the value of a configuration property.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/spark_connect/conf.rb', line 36 def get(key, default = :__unset__) op = if default == :__unset__ Op.new(get: CR::Get.new(keys: [key.to_s])) else Op.new(get_with_default: CR::GetWithDefault.new( pairs: [Proto::KeyValue.new(key: key.to_s, value: default)] )) end resp = @client.config(op) pair = resp.pairs.first pair&.value end |
#get_all(prefix = nil) ⇒ Hash{String=>String}
All configuration properties (optionally filtered by ‘prefix`).
63 64 65 66 67 68 |
# File 'lib/spark_connect/conf.rb', line 63 def get_all(prefix = nil) ga = CR::GetAll.new ga.prefix = prefix if prefix resp = @client.config(Op.new(get_all: ga)) resp.pairs.to_h { |p| [p.key, p.value] } end |
#modifiable?(key) ⇒ Boolean
Whether a configuration property is modifiable in the current session.
74 75 76 77 |
# File 'lib/spark_connect/conf.rb', line 74 def modifiable?(key) resp = @client.config(Op.new(is_modifiable: CR::IsModifiable.new(keys: [key.to_s]))) resp.pairs.first&.value == "true" end |