mondrian-olap 0.5.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +5 -5
  2. data/Changelog.md +86 -0
  3. data/LICENSE-Mondrian.txt +87 -0
  4. data/LICENSE.txt +1 -1
  5. data/README.md +43 -40
  6. data/VERSION +1 -1
  7. data/lib/mondrian/jars/commons-collections-3.2.2.jar +0 -0
  8. data/lib/mondrian/jars/commons-dbcp-1.4.jar +0 -0
  9. data/lib/mondrian/jars/commons-io-2.2.jar +0 -0
  10. data/lib/mondrian/jars/commons-lang-2.6.jar +0 -0
  11. data/lib/mondrian/jars/commons-logging-1.2.jar +0 -0
  12. data/lib/mondrian/jars/commons-pool-1.5.7.jar +0 -0
  13. data/lib/mondrian/jars/commons-vfs2-2.2.jar +0 -0
  14. data/lib/mondrian/jars/eigenbase-xom-1.3.5.jar +0 -0
  15. data/lib/mondrian/jars/guava-17.0.jar +0 -0
  16. data/lib/mondrian/jars/log4j-1.2.17.jar +0 -0
  17. data/lib/mondrian/jars/log4j.properties +2 -4
  18. data/lib/mondrian/jars/mondrian-9.1.0.0.jar +0 -0
  19. data/lib/mondrian/jars/olap4j-1.2.0.jar +0 -0
  20. data/lib/mondrian/olap/connection.rb +252 -67
  21. data/lib/mondrian/olap/cube.rb +63 -2
  22. data/lib/mondrian/olap/error.rb +37 -8
  23. data/lib/mondrian/olap/query.rb +41 -21
  24. data/lib/mondrian/olap/result.rb +163 -44
  25. data/lib/mondrian/olap/schema.rb +42 -3
  26. data/lib/mondrian/olap/schema_element.rb +25 -6
  27. data/lib/mondrian/olap/schema_udf.rb +21 -16
  28. data/spec/connection_role_spec.rb +69 -13
  29. data/spec/connection_spec.rb +3 -2
  30. data/spec/cube_cache_control_spec.rb +261 -0
  31. data/spec/cube_spec.rb +32 -4
  32. data/spec/fixtures/MondrianTest.xml +1 -6
  33. data/spec/fixtures/MondrianTestOracle.xml +1 -6
  34. data/spec/mondrian_spec.rb +71 -1
  35. data/spec/query_spec.rb +323 -25
  36. data/spec/rake_tasks.rb +253 -159
  37. data/spec/schema_definition_spec.rb +314 -61
  38. data/spec/spec_helper.rb +115 -45
  39. data/spec/support/data/customers.csv +10902 -0
  40. data/spec/support/data/product_classes.csv +101 -0
  41. data/spec/support/data/products.csv +101 -0
  42. data/spec/support/data/sales.csv +101 -0
  43. data/spec/support/data/time.csv +731 -0
  44. metadata +126 -124
  45. data/LICENSE-Mondrian.html +0 -259
  46. data/lib/mondrian/jars/commons-collections-3.2.jar +0 -0
  47. data/lib/mondrian/jars/commons-dbcp-1.2.1.jar +0 -0
  48. data/lib/mondrian/jars/commons-logging-1.1.1.jar +0 -0
  49. data/lib/mondrian/jars/commons-pool-1.2.jar +0 -0
  50. data/lib/mondrian/jars/commons-vfs-1.0.jar +0 -0
  51. data/lib/mondrian/jars/eigenbase-xom-1.3.1.jar +0 -0
  52. data/lib/mondrian/jars/log4j-1.2.14.jar +0 -0
  53. data/lib/mondrian/jars/mondrian.jar +0 -0
  54. data/lib/mondrian/jars/olap4j-1.0.1.539.jar +0 -0
@@ -85,13 +85,13 @@ describe "Schema definition" do
85
85
  XML
86
86
  end
87
87
 
88
- it "should render table name in uppercase when using Oracle or LucidDB driver" do
88
+ it "should render table name in uppercase when using Oracle or Snowflake driver" do
89
89
  @schema.define do
90
90
  cube 'Sales' do
91
91
  table 'sales_fact', :alias => 'sales', :schema => 'facts'
92
92
  end
93
93
  end
94
- %w(oracle luciddb).each do |driver|
94
+ %w(oracle snowflake).each do |driver|
95
95
  @schema.to_xml(:driver => driver).should be_like <<-XML
96
96
  <?xml version="1.0" encoding="UTF-8"?>
97
97
  <Schema name="default">
@@ -119,13 +119,13 @@ describe "Schema definition" do
119
119
  XML
120
120
  end
121
121
 
122
- it "should render table name in lowercase when using Oracle or LucidDB driver but with :upcase_data_dictionary set to false" do
122
+ it "should render table name in lowercase when using Oracle or Snowflake driver but with :upcase_data_dictionary set to false" do
123
123
  @schema.define :upcase_data_dictionary => false do
124
124
  cube 'Sales' do
125
125
  table 'sales_fact', :alias => 'sales', :schema => 'facts'
126
126
  end
127
127
  end
128
- %w(oracle luciddb).each do |driver|
128
+ %w(oracle snowflake).each do |driver|
129
129
  @schema.to_xml(:driver => driver).should be_like <<-XML
130
130
  <?xml version="1.0" encoding="UTF-8"?>
131
131
  <Schema name="default">
@@ -191,7 +191,9 @@ describe "Schema definition" do
191
191
  all_member_name 'All Genders'
192
192
  primary_key 'customer_id'
193
193
  table 'customer'
194
- level 'Gender', :column => 'gender', :unique_members => true
194
+ level 'Gender', :column => 'gender', :unique_members => true,
195
+ # Test attribute with a future value
196
+ :approx_row_count => Thread.new { sleep 0.1; 2 }
195
197
  end
196
198
  end
197
199
  end
@@ -203,7 +205,7 @@ describe "Schema definition" do
203
205
  <Dimension foreignKey="customer_id" name="Gender">
204
206
  <Hierarchy allMemberName="All Genders" hasAll="true" primaryKey="customer_id">
205
207
  <Table name="customer"/>
206
- <Level column="gender" name="Gender" uniqueMembers="true"/>
208
+ <Level approxRowCount="2" column="gender" name="Gender" uniqueMembers="true"/>
207
209
  </Hierarchy>
208
210
  </Dimension>
209
211
  </Cube>
@@ -549,6 +551,27 @@ describe "Schema definition" do
549
551
  XML
550
552
  end
551
553
 
554
+ it "should render XML with dimension and hierarchy" do
555
+ @schema.define do
556
+ cube 'Sales' do
557
+ calculated_member 'Current week' do
558
+ hierarchy '[Time.Weekly]'
559
+ formula '[Time.Weekly].[Week].CurrentDateMember'
560
+ end
561
+ end
562
+ end
563
+ @schema.to_xml.should be_like <<-XML
564
+ <?xml version="1.0" encoding="UTF-8"?>
565
+ <Schema name="default">
566
+ <Cube name="Sales">
567
+ <CalculatedMember hierarchy="[Time.Weekly]" name="Current week">
568
+ <Formula>[Time.Weekly].[Week].CurrentDateMember</Formula>
569
+ </CalculatedMember>
570
+ </Cube>
571
+ </Schema>
572
+ XML
573
+ end
574
+
552
575
  it "should render embedded cube XML defintion before additional calculated member to XML" do
553
576
  @schema.define do
554
577
  cube 'Sales' do
@@ -765,65 +788,86 @@ describe "Schema definition" do
765
788
  end
766
789
 
767
790
  describe "Element annotations" do
768
- it "should render XML from block of elements" do
769
- @schema.define do
770
- cube 'Sales' do
771
- annotations do
772
- annotation 'key1', 'value1'
773
- annotation 'key2', 'value2'
774
- end
775
- measure 'Unit Sales', :column => 'unit_sales' do
791
+ describe "block of elements" do
792
+ before do
793
+ @schema.define do
794
+ cube 'Sales' do
776
795
  annotations do
777
- annotation 'key3', 'value3'
796
+ annotation 'key1', 'value1'
797
+ annotation 'key2', 'value2'
798
+ end
799
+ measure 'Unit Sales', :column => 'unit_sales' do
800
+ annotations do
801
+ annotation 'key3', 'value3'
802
+ end
778
803
  end
779
804
  end
780
805
  end
781
806
  end
782
- @schema.to_xml.should be_like <<-XML
783
- <?xml version="1.0" encoding="UTF-8"?>
784
- <Schema name="default">
785
- <Cube name="Sales">
786
- <Annotations>
787
- <Annotation name="key1">value1</Annotation>
788
- <Annotation name="key2">value2</Annotation>
789
- </Annotations>
790
- <Measure aggregator="sum" column="unit_sales" name="Unit Sales">
807
+
808
+ it "should render XML" do
809
+ @schema.to_xml.should be_like <<-XML
810
+ <?xml version="1.0" encoding="UTF-8"?>
811
+ <Schema name="default">
812
+ <Cube name="Sales">
791
813
  <Annotations>
792
- <Annotation name="key3">value3</Annotation>
814
+ <Annotation name="key1">value1</Annotation>
815
+ <Annotation name="key2">value2</Annotation>
793
816
  </Annotations>
794
- </Measure>
795
- </Cube>
796
- </Schema>
797
- XML
817
+ <Measure aggregator="sum" column="unit_sales" name="Unit Sales">
818
+ <Annotations>
819
+ <Annotation name="key3">value3</Annotation>
820
+ </Annotations>
821
+ </Measure>
822
+ </Cube>
823
+ </Schema>
824
+ XML
825
+ end
826
+
827
+ it "should access annotations from schema definition" do
828
+ @schema.cubes.first.annotations_hash.should == {'key1' => 'value1', 'key2' => 'value2'}
829
+ end
798
830
  end
799
831
 
800
- it "should render XML from hash options" do
801
- @schema.define do
802
- cube 'Sales' do
803
- annotations :key1 => 'value1', :key2 => 'value2'
804
- measure 'Unit Sales', :column => 'unit_sales', :annotations => {:key3 => 'value3'}
832
+ describe "from hash options" do
833
+ before do
834
+ @schema.define do
835
+ cube 'Sales' do
836
+ annotations :key1 => 'value1', :key2 => 'value2'
837
+ measure 'Unit Sales', :column => 'unit_sales', :annotations => {:key3 => 'value3'}
838
+ end
805
839
  end
806
840
  end
807
- @schema.to_xml.should be_like <<-XML
808
- <?xml version="1.0" encoding="UTF-8"?>
809
- <Schema name="default">
810
- <Cube name="Sales">
811
- <Annotations>
812
- <Annotation name="key1">value1</Annotation>
813
- <Annotation name="key2">value2</Annotation>
814
- </Annotations>
815
- <Measure aggregator="sum" column="unit_sales" name="Unit Sales">
841
+
842
+ it "should render XML " do
843
+ @schema.to_xml.should be_like <<-XML
844
+ <?xml version="1.0" encoding="UTF-8"?>
845
+ <Schema name="default">
846
+ <Cube name="Sales">
816
847
  <Annotations>
817
- <Annotation name="key3">value3</Annotation>
848
+ <Annotation name="key1">value1</Annotation>
849
+ <Annotation name="key2">value2</Annotation>
818
850
  </Annotations>
819
- </Measure>
820
- </Cube>
821
- </Schema>
822
- XML
851
+ <Measure aggregator="sum" column="unit_sales" name="Unit Sales">
852
+ <Annotations>
853
+ <Annotation name="key3">value3</Annotation>
854
+ </Annotations>
855
+ </Measure>
856
+ </Cube>
857
+ </Schema>
858
+ XML
859
+ end
860
+
861
+ it "should access annotations from schema definition" do
862
+ @schema.cubes.first.annotations_hash.should == {'key1' => 'value1', 'key2' => 'value2'}
863
+ @schema.cubes.first.measures.first.annotations_hash.should == {'key3' => 'value3'}
864
+ end
823
865
  end
824
866
  end
825
867
 
826
868
  describe "User defined functions and formatters in JavaScript" do
869
+ next pending "not supported by Mondrian in Java 8" if ENV_JAVA["java.version"] >= "1.8"
870
+
827
871
  before(:each) do
828
872
  @schema.define do
829
873
  cube 'Sales' do
@@ -957,6 +1001,8 @@ describe "Schema definition" do
957
1001
  end
958
1002
 
959
1003
  describe "User defined functions and formatters in CoffeeScript" do
1004
+ next pending "not supported by Mondrian in Java 8" if ENV_JAVA["java.version"] >= "1.8"
1005
+
960
1006
  before(:each) do
961
1007
  @schema.define do
962
1008
  cube 'Sales' do
@@ -976,11 +1022,11 @@ describe "Schema definition" do
976
1022
  dimension 'Measures'
977
1023
  formula 'Factorial(6)'
978
1024
  cell_formatter do
979
- coffeescript <<-JS
1025
+ coffeescript <<-CS
980
1026
  s = value.toString()
981
1027
  s = "0" + s while s.length < 20
982
1028
  s
983
- JS
1029
+ CS
984
1030
  end
985
1031
  end
986
1032
  calculated_member 'City' do
@@ -989,30 +1035,30 @@ describe "Schema definition" do
989
1035
  end
990
1036
  end
991
1037
  user_defined_function 'Factorial' do
992
- coffeescript <<-JS
1038
+ coffeescript <<-CS
993
1039
  parameters: ["Numeric"]
994
1040
  returns: "Numeric"
995
1041
  execute: (n) ->
996
1042
  if n <= 1 then 1 else n * @execute(n - 1)
997
- JS
1043
+ CS
998
1044
  end
999
1045
  user_defined_function 'UpperName' do
1000
- coffeescript <<-JS
1046
+ coffeescript <<-CS
1001
1047
  parameters: ["Member"]
1002
1048
  returns: "String"
1003
1049
  syntax: "Property"
1004
1050
  execute: (member) ->
1005
1051
  member.getName().toUpperCase()
1006
- JS
1052
+ CS
1007
1053
  end
1008
1054
  user_defined_function 'toUpperName' do
1009
- coffeescript <<-JS
1055
+ coffeescript <<-CS
1010
1056
  parameters: ["Member", "String"]
1011
1057
  returns: "String"
1012
1058
  syntax: "Method"
1013
1059
  execute: (member, dummy) ->
1014
1060
  member.getName().toUpperCase()
1015
- JS
1061
+ CS
1016
1062
  end
1017
1063
  end
1018
1064
  @olap = Mondrian::OLAP::Connection.create(CONNECTION_PARAMS.merge :schema => @schema)
@@ -1059,12 +1105,21 @@ describe "Schema definition" do
1059
1105
  @schema.define do
1060
1106
  cube 'Sales' do
1061
1107
  table 'sales'
1062
- dimension 'Customers', :foreign_key => 'customer_id' do
1063
- hierarchy :has_all => true, :all_member_name => 'All Customers', :primary_key => 'id' do
1108
+ dimension 'Time', foreign_key: 'time_id' do
1109
+ hierarchy all_member_name: 'All Time', primary_key: 'time_id' do
1110
+ table 'time_by_day'
1111
+ level 'Year', column: 'the_year', type: 'Numeric'
1112
+ level 'Quarter', column: 'quarter'
1113
+ level 'Month', column: 'month_of_year', type: 'Numeric'
1114
+ level 'Day', column: 'day_of_month', type: 'Numeric'
1115
+ end
1116
+ end
1117
+ dimension 'Customers', foreign_key: 'customer_id' do
1118
+ hierarchy all_member_name: 'All Customers', primary_key: 'id' do
1064
1119
  table 'customers'
1065
- level 'Name', :column => 'fullname' do
1120
+ level 'Name', column: 'fullname' do
1066
1121
  member_formatter { ruby {|member| member.getName().upcase } }
1067
- property 'City', :column => 'city' do
1122
+ property 'City', column: 'city' do
1068
1123
  property_formatter { ruby {|member, property_name, property_value| property_value.upcase} }
1069
1124
  end
1070
1125
  end
@@ -1149,8 +1204,38 @@ describe "Schema definition" do
1149
1204
  end
1150
1205
  end
1151
1206
  end
1207
+ user_defined_function 'ChildrenSet' do
1208
+ ruby do
1209
+ parameters :member
1210
+ returns :member_set
1211
+ syntax :function
1212
+ def call_with_evaluator(evaluator, member)
1213
+ evaluator.getSchemaReader.getMemberChildren(member)
1214
+ end
1215
+ end
1216
+ end
1217
+ user_defined_function 'SetFirstTuple' do
1218
+ ruby do
1219
+ parameters :set
1220
+ returns :tuple
1221
+ syntax :function
1222
+ def call_with_evaluator(evaluator, set)
1223
+ set.first
1224
+ end
1225
+ end
1226
+ end
1227
+ user_defined_function 'SetFirstTuples' do
1228
+ ruby do
1229
+ parameters :tuple_set, :numeric
1230
+ returns :tuple_set
1231
+ syntax :function
1232
+ def call_with_evaluator(evaluator, set, count)
1233
+ set.to_a[0, count]
1234
+ end
1235
+ end
1236
+ end
1152
1237
  end
1153
- @olap = Mondrian::OLAP::Connection.create(CONNECTION_PARAMS.merge :schema => @schema)
1238
+ @olap = Mondrian::OLAP::Connection.create(CONNECTION_PARAMS.merge schema: @schema)
1154
1239
  end
1155
1240
 
1156
1241
  it "should execute user defined function" do
@@ -1225,6 +1310,35 @@ describe "Schema definition" do
1225
1310
  result.values[i].should == [first_member.name.upcase]
1226
1311
  end
1227
1312
  end
1313
+
1314
+ it "should execute user defined functions with a member set result" do
1315
+ result = @olap.from('Sales').
1316
+ with_member('[Measures].[Children Set]').as("SetToStr(ChildrenSet([Customers].CurrentMember))").
1317
+ columns('[Measures].[Children Set]').rows('[Customers].DefaultMember').execute
1318
+ result.row_members.each_with_index do |member, i|
1319
+ result.values[i].first.should == "{#{member.children.map(&:full_name).join(', ')}}"
1320
+ end
1321
+ end
1322
+
1323
+ it "should execute user defined functions with a tuple result" do
1324
+ result = @olap.from('Sales').
1325
+ with_member('[Measures].[First Tuple]').
1326
+ as("TupleToStr(SetFirstTuple([Customers].CurrentMember.Children * [Time].DefaultMember))").
1327
+ columns('[Measures].[First Tuple]').rows('[Customers].DefaultMember').execute
1328
+ result.row_members.each_with_index do |member, i|
1329
+ result.values[i].first.should == "(#{member.children.first.full_name}, [Time].[All Time])"
1330
+ end
1331
+ end
1332
+
1333
+ it "should execute user defined functions with a tuple result" do
1334
+ result = @olap.from('Sales').
1335
+ with_member('[Measures].[First Tuple]').
1336
+ as("SetToStr(SetFirstTuples([Customers].CurrentMember.Children * [Time].DefaultMember, 1))").
1337
+ columns('[Measures].[First Tuple]').rows('[Customers].DefaultMember').execute
1338
+ result.row_members.each_with_index do |member, i|
1339
+ result.values[i].first.should == "{(#{member.children.first.full_name}, [Time].[All Time])}"
1340
+ end
1341
+ end
1228
1342
  end
1229
1343
 
1230
1344
  describe "Shared user defined functions in Ruby" do
@@ -1328,6 +1442,15 @@ describe "Schema definition" do
1328
1442
  @olap.cube('Sales').member('[Measures].[Unit Sales]').cell_formatter_name.should be_nil
1329
1443
  end
1330
1444
 
1445
+ it "should get measure cell formatter" do
1446
+ @olap.cube('Sales').member('[Measures].[Factorial]').cell_formatter.class.name.should ==
1447
+ 'Mondrian::OLAP::Schema::CellFormatter::Integer20DigitsUdf'
1448
+ end
1449
+
1450
+ it "should not get measure cell formatter if not specified" do
1451
+ @olap.cube('Sales').member('[Measures].[Unit Sales]').cell_formatter.should be_nil
1452
+ end
1453
+
1331
1454
  it "should get measure format string" do
1332
1455
  @olap.cube('Sales').member('[Measures].[Unit Sales]').format_string.should == '#,##0'
1333
1456
  end
@@ -1373,6 +1496,136 @@ describe "Schema definition" do
1373
1496
  end
1374
1497
  end
1375
1498
 
1499
+ describe "Parameters" do
1500
+ before(:each) do
1501
+ @schema.define do
1502
+ parameter 'Current User', :type => 'String', :modifiable => true, :default_value => "'demo'"
1503
+ parameter 'Current User 1', :type => 'String', :modifiable => true, :default_value => "''"
1504
+ parameter 'Default User', :type => 'String', :modifiable => false, :default_value => "'default'"
1505
+ cube 'Sales' do
1506
+ table 'sales'
1507
+ measure 'Unit Sales', :column => 'unit_sales', :aggregator => 'sum'
1508
+ end
1509
+ user_defined_function 'ParameterValue' do
1510
+ ruby :shared do
1511
+ parameters :string
1512
+ returns :scalar
1513
+ syntax :function
1514
+ def call_with_evaluator(evaluator, parameter_name)
1515
+ parameter = evaluator.getQuery.getSchemaReader(false).getParameter(parameter_name)
1516
+ parameter && parameter.getValue
1517
+ end
1518
+ end
1519
+ end
1520
+ end
1521
+ @olap = Mondrian::OLAP::Connection.create(CONNECTION_PARAMS.merge :schema => @schema)
1522
+ end
1523
+
1524
+ it "should render XML" do
1525
+ @schema.to_xml.should be_like <<-XML
1526
+ <?xml version="1.0" encoding="UTF-8"?>
1527
+ <Schema name="default">
1528
+ <Parameter defaultValue="'demo'" modifiable="true" name="Current User" type="String"/>
1529
+ <Parameter defaultValue="''" modifiable="true" name="Current User 1" type="String"/>
1530
+ <Parameter defaultValue="'default'" modifiable="false" name="Default User" type="String"/>
1531
+ <Cube name="Sales">
1532
+ <Table name="sales"/>
1533
+ <Measure aggregator="sum" column="unit_sales" name="Unit Sales"/>
1534
+ </Cube>
1535
+ <UserDefinedFunction className="rubyobj.Mondrian.OLAP.Schema.UserDefinedFunction.ParametervalueUdf" name="ParameterValue"/>
1536
+ </Schema>
1537
+ XML
1538
+ end
1539
+
1540
+ it "should get parameter definition from connection" do
1541
+ parameter = @olap.mondrian_parameter('Current User')
1542
+ parameter.should_not be_nil
1543
+ parameter.name.should == 'Current User'
1544
+ parameter.description.should be_nil
1545
+ parameter.should be_modifiable
1546
+ parameter.scope.to_s.should == 'Schema'
1547
+ parameter.type.to_s.should == 'STRING'
1548
+ end
1549
+
1550
+ it "should not get parameter definition with invalid name" do
1551
+ @olap.mondrian_parameter('Current User 2').should be_nil
1552
+ end
1553
+
1554
+ it "should get default parameter value with ParamRef" do
1555
+ result = @olap.from('Sales').
1556
+ with_member('[Measures].[Current User]').as("ParamRef('Current User')").
1557
+ columns('[Measures].[Current User]').execute
1558
+ result.values.should == ['demo']
1559
+ end
1560
+
1561
+ it "should execute query with schema parameter value and get value with ParamRef" do
1562
+ result = @olap.from('Sales').
1563
+ with_member('[Measures].[Current User]').as("ParamRef('Current User 1')").
1564
+ columns('[Measures].[Current User]').execute("Current User 1" => "test")
1565
+ result.values.should == ['test']
1566
+ end
1567
+
1568
+ it "should execute query with query parameter value and get value with Parameter" do
1569
+ result = @olap.from('Sales').
1570
+ with_member('[Measures].[Current User]').as("Parameter('Current User 2', String, 'demo2')").
1571
+ columns('[Measures].[Current User]').execute("Current User 2" => "test2")
1572
+ result.values.should == ['test2']
1573
+ end
1574
+
1575
+ # can be used in user defined functions
1576
+ it "should execute query with additional defined parameter string value" do
1577
+ result = @olap.from('Sales').
1578
+ with_member('[Measures].[Parameter]').as("ParameterValue('String Parameter')").
1579
+ columns('[Measures].[Parameter]').execute(:define_parameters => {"String Parameter" => "test"})
1580
+ result.values.should == ['test']
1581
+ end
1582
+
1583
+ it "should execute query with additional defined parameter integer value" do
1584
+ result = @olap.from('Sales').
1585
+ with_member('[Measures].[Parameter]').as("ParameterValue('Integer Parameter')").
1586
+ columns('[Measures].[Parameter]').execute(:define_parameters => {"Integer Parameter" => 123})
1587
+ result.values.should == [123]
1588
+ end
1589
+
1590
+ it "should execute query with additional defined parameter double value" do
1591
+ result = @olap.from('Sales').
1592
+ with_member('[Measures].[Parameter]').as("ParameterValue('Double Parameter')").
1593
+ columns('[Measures].[Parameter]').execute(:define_parameters => {"Double Parameter" => 123.456})
1594
+ result.values.should == [123.456]
1595
+ end
1596
+
1597
+ it "should execute query with additional defined parameter nil value" do
1598
+ result = @olap.from('Sales').
1599
+ with_member('[Measures].[Parameter]').as("ParameterValue('Nil Parameter')").
1600
+ columns('[Measures].[Parameter]').execute(:define_parameters => {"Nil Parameter" => nil})
1601
+ result.values.should == [nil]
1602
+ end
1603
+
1604
+ it "should fail if executing with invalid parameter name" do
1605
+ expect {
1606
+ @olap.from('Sales').
1607
+ with_member('[Measures].[Current User]').as("'dummy'").
1608
+ columns('[Measures].[Current User]').execute("Current User 2" => "test2")
1609
+ }.to raise_error {|e|
1610
+ e.should be_kind_of(Mondrian::OLAP::Error)
1611
+ e.message.should == "mondrian.olap.MondrianException: Mondrian Error:Unknown parameter 'Current User 2'"
1612
+ e.root_cause_message.should == "Unknown parameter 'Current User 2'"
1613
+ }
1614
+ end
1615
+
1616
+ it "should fail if executing with non-modifiable parameter" do
1617
+ expect {
1618
+ @olap.from('Sales').
1619
+ with_member('[Measures].[Current User]').as("'dummy'").
1620
+ columns('[Measures].[Current User]').execute("Default User" => "test")
1621
+ }.to raise_error {|e|
1622
+ e.should be_kind_of(Mondrian::OLAP::Error)
1623
+ e.message.should == "mondrian.olap.MondrianException: Mondrian Error:Parameter 'Default User' (defined at 'Schema' scope) is not modifiable"
1624
+ e.root_cause_message.should == "Parameter 'Default User' (defined at 'Schema' scope) is not modifiable"
1625
+ }
1626
+ end
1627
+ end
1628
+
1376
1629
  end
1377
1630
 
1378
1631
  describe "connection with schema" do