Class: ChDB::DataPath

Inherits:
Object
  • Object
show all
Defined in:
lib/chdb/data_path.rb

Overview

Represents the data path configuration for ChDB. This class is responsible for initializing and managing the data path including parsing URIs, handling query parameters, and ensuring directory existence.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, options) ⇒ DataPath

Returns a new instance of DataPath.



16
17
18
19
20
21
22
# File 'lib/chdb/data_path.rb', line 16

def initialize(uri, options)
  initialize_instance_variables
  path = parse_uri(uri)
  merge_options(options)
  check_params
  directory_path(path)
end

Instance Attribute Details

#dir_pathObject (readonly)

Returns the value of attribute dir_path.



14
15
16
# File 'lib/chdb/data_path.rb', line 14

def dir_path
  @dir_path
end

#is_tmpObject (readonly)

Returns the value of attribute is_tmp.



14
15
16
# File 'lib/chdb/data_path.rb', line 14

def is_tmp
  @is_tmp
end

#modeObject (readonly)

Returns the value of attribute mode.



14
15
16
# File 'lib/chdb/data_path.rb', line 14

def mode
  @mode
end

#query_paramsObject (readonly)

Returns the value of attribute query_params.



14
15
16
# File 'lib/chdb/data_path.rb', line 14

def query_params
  @query_params
end

Instance Method Details

#closeObject



55
56
57
# File 'lib/chdb/data_path.rb', line 55

def close
  FileUtils.remove_entry(@dir_path, true) if @is_tmp && Dir.exist?(@dir_path)
end

#generate_argumentsObject

rubocop:disable Metrics/MethodLength



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/chdb/data_path.rb', line 24

def generate_arguments # rubocop:disable Metrics/MethodLength
  args = ['clickhouse', "--path=#{@dir_path}"]
  excluded_keys = %w[results_as_hash readonly readwrite flags]

  @query_params.each do |key, value|
    next if excluded_keys.include?(key)

    case key.to_s
    when 'udf_path'
      udf_value = value.to_s
      args += ['--', "--user_scripts_path=#{udf_value}",
               "--user_defined_executable_functions_config=#{udf_value}/*.xml"]
      next
    when '--'
      args << '--'
      next
    end

    key_str = key.to_s
    args << if value.nil?
              "--#{key_str}"
            else
              "--#{key_str}=#{value}"
            end
  end

  args << '--readonly=1' if @mode.anybits?(Constants::Open::READONLY)

  args
end