Class: GoodData::Command::Datasets

Inherits:
Object
  • Object
show all
Defined in:
lib/gooddata/commands/datasets.rb

Instance Method Summary collapse

Instance Method Details

#applyObject

Creates a server-side model based on local model description. The model description is read from a JSON file that can be generated using the +datasets:describe+ command

Usage

gooddata datasets:apply --project <projectid> <data set config>
  • --project- GoodData project identifier
  • data set config - JSON file with the model description (possibly generated by the datasets:describe command)


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/gooddata/commands/datasets.rb', line 68

def apply
  # TODO: Review following connect replacement/reimplementation
  # connect
  with_project do |project_id|
    begin
      cfg_file = args.shift
    rescue
      raise(CommandFailed, 'Invalid arguments')
    end

    fail(CommandFailed, "Usage: #{$PROGRAM_NAME} <dataset config>") unless cfg_file
    config = begin
      JSON.parse open(cfg_file)
    rescue
      raise(CommandFailed, "Error reading dataset config file '#{cfg_file}'")
    end
    objects = Project[project_id].add_dataset config['title'], config['columns']
    puts "Dataset #{config['title']} added to the project, #{objects['uris'].length} metadata objects affected"
  end
end

#describeObject

Describe a data set. Currently, only a CSV data set is supported.

The command prescans the data set, picks possible LDM types for it's fields and asks user for confirmation.

Usage

gooddata datasets:describe --file-csv <path> --name <name> --output <output path>
  • --file-csv - path to the CSV file (required)
  • --name - name of the data set (user will be prompted unless provided)
  • --output - name of the output JSON file with the model description (user will be prompted unless provided)


48
49
50
51
52
53
54
55
56
# File 'lib/gooddata/commands/datasets.rb', line 48

def describe
  columns = ask_for_fields
  name = extract_option('--name') || ask('Enter the dataset name')
  output = extract_option('--output') || ask('Enter path to the file where to save the model description', :default => "#{name}.json")
  open output, 'w' do |f|
    f << JSON.pretty_generate(:title => name, :columns => columns) + "\n"
    f.flush
  end
end

#indexObject

List all data sets present in the project specified by the --project option

Usage

gooddata datasets --project <projectid>
gooddata datasets:list --project <projectid>
  • --project - GoodData project identifier


25
26
27
28
29
30
31
32
33
# File 'lib/gooddata/commands/datasets.rb', line 25

def index
  # TODO: Review following connect replacement/reimplementation
  # connect
  with_project do |project_id|
    Project[project_id].datasets.each do |ds|
      puts "#{ds.uri}\t#{ds.identifier}\t#{ds.title}"
    end
  end
end

#loadObject

Loads a CSV file into an existing server-side data set

Usage

gooddata datasets:load --project <projectid> <file> <dataset config><
  • --project - GoodData project identifier
  • file - CSV file to load
  • data set config - JSON file with the model description (possibly generated by the datasets:describe command)


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/gooddata/commands/datasets.rb', line 99

def load
  # TODO: Review following connect replacement/reimplementation
  # connect
  with_project do |project_id|
    file, cfg_file = args
    fail(CommandFailed, "Usage: #{$PROGRAM_NAME} datasets:load <file> <dataset config>") unless cfg_file
    begin
      config = JSON.parse open(cfg_file)
    rescue
      raise(CommandFailed, "Error reading dataset config file '#{cfg_file}'")
    end
    schema = Model::Schema.new config
    Project[project_id].upload file, schema
  end
end