mondrian-olap 1.1.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +33 -0
- data/LICENSE-Mondrian.txt +87 -0
- data/LICENSE.txt +1 -1
- data/README.md +4 -4
- data/VERSION +1 -1
- data/lib/mondrian/jars/guava-17.0.jar +0 -0
- data/lib/mondrian/jars/log4j-api-2.17.1.jar +0 -0
- data/lib/mondrian/jars/log4j-core-2.17.1.jar +0 -0
- data/lib/mondrian/jars/log4j2-config.jar +0 -0
- data/lib/mondrian/jars/mondrian-9.3.0.0.jar +0 -0
- data/lib/mondrian/olap/connection.rb +126 -73
- data/lib/mondrian/olap/cube.rb +46 -4
- data/lib/mondrian/olap/error.rb +10 -2
- data/lib/mondrian/olap/query.rb +1 -0
- data/lib/mondrian/olap/result.rb +132 -56
- data/lib/mondrian/olap/schema.rb +9 -3
- data/lib/mondrian/olap/schema_element.rb +6 -3
- data/lib/mondrian/olap/schema_udf.rb +8 -82
- data/lib/mondrian/olap.rb +11 -7
- data/spec/connection_role_spec.rb +4 -1
- data/spec/connection_spec.rb +38 -5
- data/spec/cube_cache_control_spec.rb +7 -17
- data/spec/cube_spec.rb +36 -2
- data/spec/fixtures/MondrianTest.xml +40 -6
- data/spec/fixtures/MondrianTestOracle.xml +40 -6
- data/spec/mondrian_spec.rb +203 -1
- data/spec/query_spec.rb +94 -25
- data/spec/rake_tasks.rb +319 -165
- data/spec/schema_definition_spec.rb +8 -241
- data/spec/spec_helper.rb +330 -112
- data/spec/support/data/customers.csv +10902 -0
- data/spec/support/data/product_classes.csv +101 -0
- data/spec/support/data/products.csv +101 -0
- data/spec/support/data/promotions.csv +11 -0
- data/spec/support/data/sales.csv +101 -0
- data/spec/support/data/time.csv +731 -0
- data/spec/support/data/warehouse.csv +101 -0
- data/spec/support/matchers/be_like.rb +1 -0
- metadata +42 -83
- data/LICENSE-Mondrian.html +0 -259
- data/lib/mondrian/jars/log4j-1.2.17.jar +0 -0
- data/lib/mondrian/jars/log4j.properties +0 -3
- data/lib/mondrian/jars/mondrian-8.3.0.5.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
|
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
|
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
|
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
|
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>
|
@@ -863,241 +865,6 @@ describe "Schema definition" do
|
|
863
865
|
end
|
864
866
|
end
|
865
867
|
|
866
|
-
describe "User defined functions and formatters in JavaScript" do
|
867
|
-
next pending "not supported by Mondrian in Java 8" if ENV_JAVA["java.version"] >= "1.8"
|
868
|
-
|
869
|
-
before(:each) do
|
870
|
-
@schema.define do
|
871
|
-
cube 'Sales' do
|
872
|
-
table 'sales'
|
873
|
-
dimension 'Customers', :foreign_key => 'customer_id' do
|
874
|
-
hierarchy :has_all => true, :all_member_name => 'All Customers', :primary_key => 'id' do
|
875
|
-
table 'customers'
|
876
|
-
level 'Name', :column => 'fullname' do
|
877
|
-
member_formatter { javascript "return member.getName().toUpperCase();" }
|
878
|
-
property 'City', :column => 'city' do
|
879
|
-
property_formatter { javascript "return propertyValue.toUpperCase();" }
|
880
|
-
end
|
881
|
-
end
|
882
|
-
end
|
883
|
-
end
|
884
|
-
calculated_member 'Factorial' do
|
885
|
-
dimension 'Measures'
|
886
|
-
formula 'Factorial(6)'
|
887
|
-
cell_formatter do
|
888
|
-
javascript <<-JS
|
889
|
-
var s = value.toString();
|
890
|
-
while (s.length < 20) {
|
891
|
-
s = "0" + s;
|
892
|
-
}
|
893
|
-
return s;
|
894
|
-
JS
|
895
|
-
end
|
896
|
-
end
|
897
|
-
calculated_member 'City' do
|
898
|
-
dimension 'Measures'
|
899
|
-
formula "[Customers].CurrentMember.Properties('City')"
|
900
|
-
end
|
901
|
-
end
|
902
|
-
user_defined_function 'Factorial' do
|
903
|
-
javascript <<-JS
|
904
|
-
function getParameterTypes() {
|
905
|
-
return new Array(
|
906
|
-
new mondrian.olap.type.NumericType());
|
907
|
-
}
|
908
|
-
function getReturnType(parameterTypes) {
|
909
|
-
return new mondrian.olap.type.NumericType();
|
910
|
-
}
|
911
|
-
function execute(evaluator, arguments) {
|
912
|
-
var n = arguments[0].evaluateScalar(evaluator);
|
913
|
-
return factorial(n);
|
914
|
-
}
|
915
|
-
function factorial(n) {
|
916
|
-
return n <= 1 ? 1 : n * factorial(n - 1);
|
917
|
-
}
|
918
|
-
JS
|
919
|
-
end
|
920
|
-
end
|
921
|
-
@olap = Mondrian::OLAP::Connection.create(CONNECTION_PARAMS.merge :schema => @schema)
|
922
|
-
end
|
923
|
-
|
924
|
-
it "should render XML" do
|
925
|
-
@schema.to_xml.should be_like <<-XML
|
926
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
927
|
-
<Schema name="default">
|
928
|
-
<Cube name="Sales">
|
929
|
-
<Table name="sales"/>
|
930
|
-
<Dimension foreignKey="customer_id" name="Customers">
|
931
|
-
<Hierarchy allMemberName="All Customers" hasAll="true" primaryKey="id">
|
932
|
-
<Table name="customers"/>
|
933
|
-
<Level column="fullname" name="Name" uniqueMembers="true">
|
934
|
-
<MemberFormatter>
|
935
|
-
<Script language="JavaScript">return member.getName().toUpperCase();</Script>
|
936
|
-
</MemberFormatter>
|
937
|
-
<Property column="city" name="City">
|
938
|
-
<PropertyFormatter>
|
939
|
-
<Script language="JavaScript">return propertyValue.toUpperCase();</Script>
|
940
|
-
</PropertyFormatter>
|
941
|
-
</Property>
|
942
|
-
</Level>
|
943
|
-
</Hierarchy>
|
944
|
-
</Dimension>
|
945
|
-
<CalculatedMember dimension="Measures" name="Factorial">
|
946
|
-
<Formula>Factorial(6)</Formula>
|
947
|
-
<CellFormatter>
|
948
|
-
<Script language="JavaScript">
|
949
|
-
var s = value.toString();
|
950
|
-
while (s.length < 20) {
|
951
|
-
s = "0" + s;
|
952
|
-
}
|
953
|
-
return s;
|
954
|
-
</Script>
|
955
|
-
</CellFormatter>
|
956
|
-
</CalculatedMember>
|
957
|
-
<CalculatedMember dimension="Measures" name="City">
|
958
|
-
<Formula>[Customers].CurrentMember.Properties('City')</Formula>
|
959
|
-
</CalculatedMember>
|
960
|
-
</Cube>
|
961
|
-
<UserDefinedFunction name="Factorial">
|
962
|
-
<Script language="JavaScript">
|
963
|
-
function getParameterTypes() {
|
964
|
-
return new Array(
|
965
|
-
new mondrian.olap.type.NumericType());
|
966
|
-
}
|
967
|
-
function getReturnType(parameterTypes) {
|
968
|
-
return new mondrian.olap.type.NumericType();
|
969
|
-
}
|
970
|
-
function execute(evaluator, arguments) {
|
971
|
-
var n = arguments[0].evaluateScalar(evaluator);
|
972
|
-
return factorial(n);
|
973
|
-
}
|
974
|
-
function factorial(n) {
|
975
|
-
return n <= 1 ? 1 : n * factorial(n - 1);
|
976
|
-
}
|
977
|
-
</Script>
|
978
|
-
</UserDefinedFunction>
|
979
|
-
</Schema>
|
980
|
-
XML
|
981
|
-
end
|
982
|
-
|
983
|
-
it "should execute user defined function" do
|
984
|
-
result = @olap.from('Sales').columns('[Measures].[Factorial]').execute
|
985
|
-
value = 1*2*3*4*5*6
|
986
|
-
result.values.should == [value]
|
987
|
-
result.formatted_values.should == ["%020d" % value]
|
988
|
-
end
|
989
|
-
|
990
|
-
it "should format members and properties" do
|
991
|
-
result = @olap.from('Sales').columns('[Measures].[City]').rows('[Customers].[All Customers].Children').execute
|
992
|
-
result.row_members.each_with_index do |member, i|
|
993
|
-
member.caption.should == member.name.upcase
|
994
|
-
city = member.property_value('City')
|
995
|
-
result.formatted_values[i].first.should == city
|
996
|
-
member.property_formatted_value('City').should == city.upcase
|
997
|
-
end
|
998
|
-
end
|
999
|
-
end
|
1000
|
-
|
1001
|
-
describe "User defined functions and formatters in CoffeeScript" do
|
1002
|
-
next pending "not supported by Mondrian in Java 8" if ENV_JAVA["java.version"] >= "1.8"
|
1003
|
-
|
1004
|
-
before(:each) do
|
1005
|
-
@schema.define do
|
1006
|
-
cube 'Sales' do
|
1007
|
-
table 'sales'
|
1008
|
-
dimension 'Customers', :foreign_key => 'customer_id' do
|
1009
|
-
hierarchy :has_all => true, :all_member_name => 'All Customers', :primary_key => 'id' do
|
1010
|
-
table 'customers'
|
1011
|
-
level 'Name', :column => 'fullname' do
|
1012
|
-
member_formatter { coffeescript "member.getName().toUpperCase()" }
|
1013
|
-
property 'City', :column => 'city' do
|
1014
|
-
property_formatter { coffeescript "propertyValue.toUpperCase()" }
|
1015
|
-
end
|
1016
|
-
end
|
1017
|
-
end
|
1018
|
-
end
|
1019
|
-
calculated_member 'Factorial' do
|
1020
|
-
dimension 'Measures'
|
1021
|
-
formula 'Factorial(6)'
|
1022
|
-
cell_formatter do
|
1023
|
-
coffeescript <<-CS
|
1024
|
-
s = value.toString()
|
1025
|
-
s = "0" + s while s.length < 20
|
1026
|
-
s
|
1027
|
-
CS
|
1028
|
-
end
|
1029
|
-
end
|
1030
|
-
calculated_member 'City' do
|
1031
|
-
dimension 'Measures'
|
1032
|
-
formula "[Customers].CurrentMember.Properties('City')"
|
1033
|
-
end
|
1034
|
-
end
|
1035
|
-
user_defined_function 'Factorial' do
|
1036
|
-
coffeescript <<-CS
|
1037
|
-
parameters: ["Numeric"]
|
1038
|
-
returns: "Numeric"
|
1039
|
-
execute: (n) ->
|
1040
|
-
if n <= 1 then 1 else n * @execute(n - 1)
|
1041
|
-
CS
|
1042
|
-
end
|
1043
|
-
user_defined_function 'UpperName' do
|
1044
|
-
coffeescript <<-CS
|
1045
|
-
parameters: ["Member"]
|
1046
|
-
returns: "String"
|
1047
|
-
syntax: "Property"
|
1048
|
-
execute: (member) ->
|
1049
|
-
member.getName().toUpperCase()
|
1050
|
-
CS
|
1051
|
-
end
|
1052
|
-
user_defined_function 'toUpperName' do
|
1053
|
-
coffeescript <<-CS
|
1054
|
-
parameters: ["Member", "String"]
|
1055
|
-
returns: "String"
|
1056
|
-
syntax: "Method"
|
1057
|
-
execute: (member, dummy) ->
|
1058
|
-
member.getName().toUpperCase()
|
1059
|
-
CS
|
1060
|
-
end
|
1061
|
-
end
|
1062
|
-
@olap = Mondrian::OLAP::Connection.create(CONNECTION_PARAMS.merge :schema => @schema)
|
1063
|
-
end
|
1064
|
-
|
1065
|
-
it "should execute user defined function" do
|
1066
|
-
result = @olap.from('Sales').columns('[Measures].[Factorial]').execute
|
1067
|
-
value = 1*2*3*4*5*6
|
1068
|
-
result.values.should == [value]
|
1069
|
-
result.formatted_values.should == ["%020d" % value]
|
1070
|
-
end
|
1071
|
-
|
1072
|
-
it "should format members and properties" do
|
1073
|
-
result = @olap.from('Sales').columns('[Measures].[City]').rows('[Customers].[All Customers].Children').execute
|
1074
|
-
result.row_members.each_with_index do |member, i|
|
1075
|
-
member.caption.should == member.name.upcase
|
1076
|
-
city = member.property_value('City')
|
1077
|
-
result.formatted_values[i].first.should == city
|
1078
|
-
member.property_formatted_value('City').should == city.upcase
|
1079
|
-
end
|
1080
|
-
end
|
1081
|
-
|
1082
|
-
it "should execute user defined property on member" do
|
1083
|
-
result = @olap.from('Sales').
|
1084
|
-
with_member('[Measures].[Upper Name]').as('[Customers].CurrentMember.UpperName').
|
1085
|
-
columns('[Measures].[Upper Name]').rows('[Customers].Children').execute
|
1086
|
-
result.row_members.each_with_index do |member, i|
|
1087
|
-
result.values[i].should == [member.name.upcase]
|
1088
|
-
end
|
1089
|
-
end
|
1090
|
-
|
1091
|
-
it "should execute user defined method on member" do
|
1092
|
-
result = @olap.from('Sales').
|
1093
|
-
with_member('[Measures].[Upper Name]').as("[Customers].CurrentMember.toUpperName('dummy')").
|
1094
|
-
columns('[Measures].[Upper Name]').rows('[Customers].Children').execute
|
1095
|
-
result.row_members.each_with_index do |member, i|
|
1096
|
-
result.values[i].should == [member.name.upcase]
|
1097
|
-
end
|
1098
|
-
end
|
1099
|
-
end
|
1100
|
-
|
1101
868
|
describe "User defined functions and formatters in Ruby" do
|
1102
869
|
before(:each) do
|
1103
870
|
@schema.define do
|