Skip to content

Commit

Permalink
Fix Drill through results values for MS SQL database
Browse files Browse the repository at this point in the history
CLOB columns should be converted to string
  • Loading branch information
jjustaments committed Oct 6, 2016
1 parent 6018897 commit c6f0325
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
19 changes: 19 additions & 0 deletions lib/mondrian/olap/result.rb
Expand Up @@ -449,13 +449,32 @@ def self.java_to_ruby_value(value, column_type = nil)
value
when Java::JavaMath::BigDecimal
BigDecimal(value.to_s)
when Java::JavaSql::Clob
clob_to_string(value)
else
value
end
end

private

def self.clob_to_string(value)
if reader = value.getCharacterStream
buffered_reader = Java::JavaIo::BufferedReader.new(reader)
result = []
while str = buffered_reader.readLine
result << str
end
result.join("\n")
end
ensure
if buffered_reader
buffered_reader.close
elsif reader
reader.close
end
end

def axes
@axes ||= @raw_cell_set.getAxes
end
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/MondrianTest.xml
Expand Up @@ -87,6 +87,7 @@ fullname
</SQL>
</OrdinalExpression>
<Property name="Gender" column="gender"/>
<Property name="Description" column="description"/>
</Level>
</Hierarchy>
</Dimension>
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/MondrianTestOracle.xml
Expand Up @@ -87,6 +87,7 @@ FULLNAME
</SQL>
</OrdinalExpression>
<Property name="Gender" column="GENDER"/>
<Property name="Description" column="DESCRIPTION"/>
</Level>
</Hierarchy>
</Dimension>
Expand Down
11 changes: 7 additions & 4 deletions spec/query_spec.rb
Expand Up @@ -895,14 +895,16 @@ def sql_select_numbers(select_string)
@drill_through = @result.drill_through(row: 0, column: 0,
return: [
"Name([Customers].[Name])",
"Property([Customers].[Name], 'Gender')"
"Property([Customers].[Name], 'Gender')",
"Property([Customers].[Name], 'Description')"
]
)
@drill_through.column_labels.should == [ "Name", "Gender" ]
@drill_through.column_labels.should == [ "Name", "Gender", "Description" ]
@drill_through.rows.should == @sql.select_rows(<<-SQL
SELECT
customers.fullname,
customers.gender
customers.gender,
customers.description
FROM
sales,
customers,
Expand All @@ -919,7 +921,8 @@ def sql_select_numbers(select_string)
customers.id = sales.customer_id
ORDER BY
customers.fullname,
customers.gender
customers.gender,
customers.description
SQL
)
end
Expand Down
11 changes: 10 additions & 1 deletion spec/rake_tasks.rb
Expand Up @@ -40,6 +40,14 @@
t.string :lname, :limit => 30
t.string :fullname, :limit => 60
t.string :gender, :limit => 30
# Mondrian does not support properties with Oracle CLOB type
# as it tries to GROUP BY all columns when loading a dimension table
if MONDRIAN_DRIVER == 'oracle'
t.string :description, :limit => 4000
else
t.text :description
end

end

create_table :sales, :force => true, :id => false do |t|
Expand Down Expand Up @@ -207,7 +215,8 @@ class Sales < ActiveRecord::Base
:fname => "First#{i}",
:lname => "Last#{i}",
:fullname => "First#{i} Last#{i}",
:gender => i % 2 == 0 ? "M" : "F"
:gender => i % 2 == 0 ? "M" : "F",
:description => 100.times.map{"1234567890"}.join("\n")
)
end
end
Expand Down

0 comments on commit c6f0325

Please sign in to comment.