Class: Mondrian::OLAP::Result
- Inherits:
-
Object
- Object
- Mondrian::OLAP::Result
- Defined in:
- lib/mondrian/olap/result.rb
Defined Under Namespace
Classes: DrillThrough
Constant Summary collapse
- AXIS_SYMBOLS =
[:column, :row, :page, :section, :chapter]
- QUERY_TIMING_CUMULATIVE_REGEXP =
/\AQuery Timing \(Cumulative\):\n/
Instance Attribute Summary collapse
-
#profiling_handler ⇒ Object
readonly
Returns the value of attribute profiling_handler.
-
#raw_cell_set ⇒ Object
readonly
Returns the value of attribute raw_cell_set.
-
#total_duration ⇒ Object
readonly
Returns the value of attribute total_duration.
Class Method Summary collapse
Instance Method Summary collapse
- #axes_count ⇒ Object
- #axis_full_names ⇒ Object
- #axis_members ⇒ Object
- #axis_names ⇒ Object
-
#drill_through(params = {}) ⇒ Object
Specify drill through cell position, for example, as :row => 0, :cell => 1 Specify max returned rows with :max_rows parameter Specify returned fields (as list of MDX levels and measures) with :return parameter Specify measures which at least one should not be empty (NULL) with :nonempty parameter.
- #formatted_values(*axes_sequence) ⇒ Object
-
#initialize(connection, raw_cell_set, options = {}) ⇒ Result
constructor
A new instance of Result.
- #profiling_mark_full(name, duration) ⇒ Object
- #profiling_plan ⇒ Object
- #profiling_timing ⇒ Object
- #profiling_timing_string ⇒ Object
-
#to_html(options = {}) ⇒ Object
format results in simple HTML table.
- #values(*axes_sequence) ⇒ Object
- #values_using(values_method, axes_sequence = []) ⇒ Object
Constructor Details
#initialize(connection, raw_cell_set, options = {}) ⇒ Result
Returns a new instance of Result.
6 7 8 9 10 11 |
# File 'lib/mondrian/olap/result.rb', line 6 def initialize(connection, raw_cell_set, = {}) @connection = connection @raw_cell_set = raw_cell_set @profiling_handler = [:profiling_handler] @total_duration = [:total_duration] end |
Instance Attribute Details
#profiling_handler ⇒ Object (readonly)
Returns the value of attribute profiling_handler.
13 14 15 |
# File 'lib/mondrian/olap/result.rb', line 13 def profiling_handler @profiling_handler end |
#raw_cell_set ⇒ Object (readonly)
Returns the value of attribute raw_cell_set.
13 14 15 |
# File 'lib/mondrian/olap/result.rb', line 13 def raw_cell_set @raw_cell_set end |
#total_duration ⇒ Object (readonly)
Returns the value of attribute total_duration.
13 14 15 |
# File 'lib/mondrian/olap/result.rb', line 13 def total_duration @total_duration end |
Class Method Details
.java_to_ruby_value(value, column_type = nil) ⇒ Object
555 556 557 558 559 560 561 562 563 564 565 566 |
# File 'lib/mondrian/olap/result.rb', line 555 def self.java_to_ruby_value(value, column_type = nil) case value when Numeric, String value when Java::JavaMath::BigDecimal BigDecimal(value.to_s) when Java::JavaSql::Clob clob_to_string(value) else value end end |
Instance Method Details
#axes_count ⇒ Object
15 16 17 |
# File 'lib/mondrian/olap/result.rb', line 15 def axes_count axes.length end |
#axis_full_names ⇒ Object
23 24 25 |
# File 'lib/mondrian/olap/result.rb', line 23 def axis_full_names @axis_full_names ||= axis_positions(:getUniqueName) end |
#axis_members ⇒ Object
27 28 29 |
# File 'lib/mondrian/olap/result.rb', line 27 def axis_members @axis_members ||= axis_positions(:to_member) end |
#axis_names ⇒ Object
19 20 21 |
# File 'lib/mondrian/olap/result.rb', line 19 def axis_names @axis_names ||= axis_positions(:getName) end |
#drill_through(params = {}) ⇒ Object
Specify drill through cell position, for example, as
:row => 0, :cell => 1
Specify max returned rows with :max_rows parameter Specify returned fields (as list of MDX levels and measures) with :return parameter Specify measures which at least one should not be empty (NULL) with :nonempty parameter
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/mondrian/olap/result.rb', line 143 def drill_through(params = {}) Error.wrap_native_exception do cell_params = [] axes_count.times do |i| axis_symbol = AXIS_SYMBOLS[i] raise ArgumentError, "missing position #{axis_symbol.inspect}" unless axis_position = params[axis_symbol] cell_params << Java::JavaLang::Integer.new(axis_position) end raw_cell = @raw_cell_set.getCell(cell_params) DrillThrough.from_raw_cell(raw_cell, params.merge(role_name: @connection.role_name)) end end |
#formatted_values(*axes_sequence) ⇒ Object
50 51 52 |
# File 'lib/mondrian/olap/result.rb', line 50 def formatted_values(*axes_sequence) values_using(:getFormattedValue, axes_sequence) end |
#profiling_mark_full(name, duration) ⇒ Object
126 127 128 |
# File 'lib/mondrian/olap/result.rb', line 126 def profiling_mark_full(name, duration) profiling_timing && profiling_timing.markFull(name, duration) end |
#profiling_plan ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/mondrian/olap/result.rb', line 110 def profiling_plan if profiling_handler @raw_cell_set.close if plan = profiling_handler.plan plan.gsub("\r\n", "\n") end end end |
#profiling_timing ⇒ Object
119 120 121 122 123 124 |
# File 'lib/mondrian/olap/result.rb', line 119 def profiling_timing if profiling_handler @raw_cell_set.close profiling_handler.timing end end |
#profiling_timing_string ⇒ Object
132 133 134 135 136 |
# File 'lib/mondrian/olap/result.rb', line 132 def profiling_timing_string if profiling_timing && (timing_string = profiling_timing.toString) timing_string.gsub("\r\n", "\n").sub(QUERY_TIMING_CUMULATIVE_REGEXP, '') end end |
#to_html(options = {}) ⇒ Object
format results in simple HTML table
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 104 105 106 107 108 |
# File 'lib/mondrian/olap/result.rb', line 64 def to_html( = {}) case axes_count when 1 builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |doc| doc.table do doc.tr do column_full_names.each do |column_full_name| column_full_name = column_full_name.join(',') if column_full_name.is_a?(Array) doc.th column_full_name, :align => 'right' end end doc.tr do ([:formatted] ? formatted_values : values).each do |value| doc.td value, :align => 'right' end end end end builder.doc.to_html when 2 builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |doc| doc.table do doc.tr do doc.th column_full_names.each do |column_full_name| column_full_name = column_full_name.join(',') if column_full_name.is_a?(Array) doc.th column_full_name, :align => 'right' end end ([:formatted] ? formatted_values : values).each_with_index do |row, i| doc.tr do row_full_name = row_full_names[i].is_a?(Array) ? row_full_names[i].join(',') : row_full_names[i] doc.th row_full_name, :align => 'left' row.each do |cell| doc.td cell, :align => 'right' end end end end end builder.doc.to_html else raise ArgumentError, "just columns and rows axes are supported" end end |
#values(*axes_sequence) ⇒ Object
46 47 48 |
# File 'lib/mondrian/olap/result.rb', line 46 def values(*axes_sequence) values_using(:getValue, axes_sequence) end |
#values_using(values_method, axes_sequence = []) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/mondrian/olap/result.rb', line 54 def values_using(values_method, axes_sequence = []) if axes_sequence.empty? axes_sequence = (0...axes_count).to_a.reverse elsif axes_sequence.size != axes_count raise ArgumentError, "axes sequence size is not equal to result axes count" end recursive_values(values_method, axes_sequence, 0) end |