Class: Mortar::Command::Describe

Inherits:
Base
  • Object
show all
Includes:
Git
Defined in:
lib/mortar/command/describe.rb

Overview

show data schema for pigscript

Instance Attribute Summary

Attributes inherited from Base

#args, #options

Instance Method Summary collapse

Methods inherited from Base

#api, #ask_public, #config_parameters, #get_error_message_context, #git, #initialize, #initialize_embedded_project, #luigi_parameters, namespace, #pig_parameters, #project, #register_api_call, #register_do, #register_project, #spark_script_arguments, #validate_project_name, #validate_project_structure

Methods included from Helpers

#action, #ask, #confirm, #copy_if_not_present_at_dest, #default_host, #deprecate, #display, #display_header, #display_object, #display_row, #display_table, #display_with_indent, #download_to_file, #ensure_dir_exists, #error, error_with_failure, error_with_failure=, extended, extended_into, #format_bytes, #format_date, #format_with_bang, #full_host, #get_terminal_environment, #home_directory, #host, #hprint, #hputs, included, included_into, #installed_with_omnibus?, #json_decode, #json_encode, #line_formatter, #longest, #output_with_bang, #pending_github_team_state_message, #quantify, #redisplay, #retry_on_exception, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #spinner, #status, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #test_name, #ticking, #time_ago, #truncate, #warning, #with_tty, #write_to_file

Constructor Details

This class inherits a constructor from Mortar::Command::Base

Instance Method Details

#indexObject

describe PIGSCRIPT ALIAS

Describe the schema of an alias and all of its ancestors.

-p, –parameter NAME=VALUE # Set a pig parameter value in your script. -f, –param-file PARAMFILE # Load pig parameter values from a file. -g, –pigversion PIG_VERSION # Set pig version. Options are <PIG_VERSION_OPTIONS>.

Examples:

Describe the songs_sample relation in the generate_regression_model_coefficients.pig pigscript.
     $ mortar describe pigscripts/generate_regression_model_coefficients.pig songs_sample


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/mortar/command/describe.rb', line 37

def index
  pigscript_name = shift_argument
  alias_name = shift_argument
  unless pigscript_name && alias_name
    error("Usage: mortar describe PIGSCRIPT ALIAS\nMust specify PIGSCRIPT and ALIAS.")
  end
  
  validate_arguments!
  pigscript = validate_script!(pigscript_name)
  
  if pigscript.is_a? Mortar::Project::ControlScript
    error "Currently Mortar does not support describing control scripts"
  end
  
  git_ref = sync_code_with_cloud()
  
  describe_id = nil
  action("Starting describe") do
    describe_id = api.post_describe(project.name, pigscript.name, alias_name, git_ref, 
      :pig_version => pig_version.version, 
      :project_script_path => pigscript.rel_path,
      :parameters => pig_parameters).body["describe_id"]
  end
      
  describe_result = nil
  display
  ticking(polling_interval) do |ticks|
    describe_result = api.get_describe(describe_id, :exclude_result => true).body
    is_finished =
      Mortar::API::Describe::STATUSES_COMPLETE.include?(describe_result["status_code"])
      
    redisplay("[#{spinner(ticks)}] Calculating schema for #{alias_name} and ancestors...",
      is_finished) # only display newline on last message
    if is_finished
      display
      break
    end
  end
  
  case describe_result['status_code']
  when Mortar::API::Describe::STATUS_FAILURE
    error_message = "Describe failed with #{describe_result['error_type'] || 'error'}"
    if line_number = describe_result["line_number"]
      error_message += " at Line #{line_number}"
      if column_number = describe_result["column_number"]
        error_message += ", Column #{column_number}"
      end
    end
    error_context = get_error_message_context(describe_result['error_message'])
    error_message += ":\n\n#{describe_result['error_message']}\n\n#{error_context}"
    error(error_message)
  when Mortar::API::Describe::STATUS_KILLED
    error("Describe killed by user.")
  when Mortar::API::Describe::STATUS_SUCCESS
    web_result_url = describe_result['web_result_url']
    display("Results available at #{web_result_url}")

    unless no_browser?
      action("Opening web browser to show results") do
        require "launchy"
        Launchy.open(web_result_url).join
      end
    end
  else
    raise RuntimeError, "Unknown describe status: #{describe_result['status']} for describe_id: #{describe_id}"
  end
end