activecube 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.idea/workspace.xml +114 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +60 -0
- data/Rakefile +6 -0
- data/activecube.gemspec +32 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/activecube.rb +6 -0
- data/lib/activecube/active_record_extension.rb +20 -0
- data/lib/activecube/base.rb +6 -0
- data/lib/activecube/clickhouse/metric/count.rb +10 -0
- data/lib/activecube/clickhouse/metric/sum.rb +11 -0
- data/lib/activecube/cube_definition.rb +62 -0
- data/lib/activecube/dimension.rb +5 -0
- data/lib/activecube/dimension_definition_methods.rb +32 -0
- data/lib/activecube/field.rb +12 -0
- data/lib/activecube/metric.rb +5 -0
- data/lib/activecube/processor/composer.rb +76 -0
- data/lib/activecube/processor/index.rb +17 -0
- data/lib/activecube/processor/measure_tables.rb +42 -0
- data/lib/activecube/processor/optimizer.rb +123 -0
- data/lib/activecube/processor/table.rb +54 -0
- data/lib/activecube/query/chain_appender.rb +25 -0
- data/lib/activecube/query/cube_query.rb +112 -0
- data/lib/activecube/query/item.rb +22 -0
- data/lib/activecube/query/limit.rb +17 -0
- data/lib/activecube/query/measure.rb +40 -0
- data/lib/activecube/query/or_selector.rb +20 -0
- data/lib/activecube/query/ordering.rb +17 -0
- data/lib/activecube/query/selector.rb +84 -0
- data/lib/activecube/query/slice.rb +57 -0
- data/lib/activecube/query_methods.rb +11 -0
- data/lib/activecube/selector.rb +11 -0
- data/lib/activecube/version.rb +3 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9a7d156d972363abe7b4b6fcd10ca0198701ffae6378546ec8d9d6167ffbd031
|
4
|
+
data.tar.gz: 3cb7a21db62dd00b5047db0625e429462f8d2654d54395f74cd1833500a896a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 15afed4e4c5f034fa0284ae345486e4783ed50fa4a2c525b7c03dd4fa06ab44ddd732eb74b9c3a4cab7efa4bd56fdf2d23b6e361f9fd565c23976bb85374997d
|
7
|
+
data.tar.gz: 845d64b1bbd1a555c3ff8273f96769021baffe84768e4db792ad579e3d548acd6e2a7634565902d7b643af81600cf57379ea6ab3dbdd99f9a6e656a552de5f3b
|
data/.gitignore
ADDED
data/.idea/workspace.xml
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="BranchesTreeState">
|
4
|
+
<expand>
|
5
|
+
<path>
|
6
|
+
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
|
7
|
+
<item name="LOCAL_ROOT" type="e8cecc67:BranchNodeDescriptor" />
|
8
|
+
</path>
|
9
|
+
</expand>
|
10
|
+
<select />
|
11
|
+
</component>
|
12
|
+
<component name="ChangeListManager">
|
13
|
+
<list default="true" id="77368870-4045-496a-9737-2c7f83086a16" name="Default Changelist" comment="initial implementation">
|
14
|
+
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
|
15
|
+
<change beforePath="$PROJECT_DIR$/activecube.gemspec" beforeDir="false" afterPath="$PROJECT_DIR$/activecube.gemspec" afterDir="false" />
|
16
|
+
</list>
|
17
|
+
<option name="SHOW_DIALOG" value="false" />
|
18
|
+
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
19
|
+
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
20
|
+
<option name="LAST_RESOLUTION" value="IGNORE" />
|
21
|
+
</component>
|
22
|
+
<component name="Git.Settings">
|
23
|
+
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
24
|
+
</component>
|
25
|
+
<component name="ProjectId" id="1Xu9Qappwp8FcqKJZrxzkXK80UI" />
|
26
|
+
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
27
|
+
<component name="ProjectViewState">
|
28
|
+
<option name="hideEmptyMiddlePackages" value="true" />
|
29
|
+
<option name="showLibraryContents" value="true" />
|
30
|
+
</component>
|
31
|
+
<component name="PropertiesComponent">
|
32
|
+
<property name="WebServerToolWindowFactoryState" value="false" />
|
33
|
+
<property name="last_opened_file_path" value="$PROJECT_DIR$/lib/activecube" />
|
34
|
+
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
|
35
|
+
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
|
36
|
+
<property name="settings.editor.selected.configurable" value="preferences.lookFeel" />
|
37
|
+
</component>
|
38
|
+
<component name="RecentsManager">
|
39
|
+
<key name="CopyFile.RECENT_KEYS">
|
40
|
+
<recent name="$PROJECT_DIR$/lib/activecube" />
|
41
|
+
</key>
|
42
|
+
</component>
|
43
|
+
<component name="SpringUtil" SPRING_PRE_LOADER_OPTION="true" RAKE_SPRING_PRE_LOADER_OPTION="true" RAILS_SPRING_PRE_LOADER_OPTION="true" />
|
44
|
+
<component name="SvnConfiguration">
|
45
|
+
<configuration />
|
46
|
+
</component>
|
47
|
+
<component name="TaskManager">
|
48
|
+
<task active="true" id="Default" summary="Default task">
|
49
|
+
<changelist id="77368870-4045-496a-9737-2c7f83086a16" name="Default Changelist" comment="" />
|
50
|
+
<created>1581885096407</created>
|
51
|
+
<option name="number" value="Default" />
|
52
|
+
<option name="presentableId" value="Default" />
|
53
|
+
<updated>1581885096407</updated>
|
54
|
+
<workItem from="1581885099890" duration="963000" />
|
55
|
+
</task>
|
56
|
+
<task id="LOCAL-00001" summary="initial commit">
|
57
|
+
<created>1581885128091</created>
|
58
|
+
<option name="number" value="00001" />
|
59
|
+
<option name="presentableId" value="LOCAL-00001" />
|
60
|
+
<option name="project" value="LOCAL" />
|
61
|
+
<updated>1581885128091</updated>
|
62
|
+
</task>
|
63
|
+
<task id="LOCAL-00002" summary="initial implementation">
|
64
|
+
<created>1581885329956</created>
|
65
|
+
<option name="number" value="00002" />
|
66
|
+
<option name="presentableId" value="LOCAL-00002" />
|
67
|
+
<option name="project" value="LOCAL" />
|
68
|
+
<updated>1581885329956</updated>
|
69
|
+
</task>
|
70
|
+
<option name="localTasksCounter" value="3" />
|
71
|
+
<servers />
|
72
|
+
</component>
|
73
|
+
<component name="TypeScriptGeneratedFilesManager">
|
74
|
+
<option name="version" value="2" />
|
75
|
+
</component>
|
76
|
+
<component name="Vcs.Log.Tabs.Properties">
|
77
|
+
<option name="TAB_STATES">
|
78
|
+
<map>
|
79
|
+
<entry key="MAIN">
|
80
|
+
<value>
|
81
|
+
<State />
|
82
|
+
</value>
|
83
|
+
</entry>
|
84
|
+
</map>
|
85
|
+
</option>
|
86
|
+
</component>
|
87
|
+
<component name="VcsManagerConfiguration">
|
88
|
+
<MESSAGE value="initial commit" />
|
89
|
+
<MESSAGE value="initial implementation" />
|
90
|
+
<option name="LAST_COMMIT_MESSAGE" value="initial implementation" />
|
91
|
+
</component>
|
92
|
+
<component name="WindowStateProjectService">
|
93
|
+
<state width="1207" height="201" key="GridCell.Tab.0.bottom" timestamp="1581885116972">
|
94
|
+
<screen x="0" y="23" width="1440" height="786" />
|
95
|
+
</state>
|
96
|
+
<state width="1207" height="201" key="GridCell.Tab.0.bottom/0.23.1440.786@0.23.1440.786" timestamp="1581885116972" />
|
97
|
+
<state width="1207" height="201" key="GridCell.Tab.0.center" timestamp="1581885116972">
|
98
|
+
<screen x="0" y="23" width="1440" height="786" />
|
99
|
+
</state>
|
100
|
+
<state width="1207" height="201" key="GridCell.Tab.0.center/0.23.1440.786@0.23.1440.786" timestamp="1581885116972" />
|
101
|
+
<state width="1207" height="201" key="GridCell.Tab.0.left" timestamp="1581885116971">
|
102
|
+
<screen x="0" y="23" width="1440" height="786" />
|
103
|
+
</state>
|
104
|
+
<state width="1207" height="201" key="GridCell.Tab.0.left/0.23.1440.786@0.23.1440.786" timestamp="1581885116971" />
|
105
|
+
<state width="1207" height="201" key="GridCell.Tab.0.right" timestamp="1581885116972">
|
106
|
+
<screen x="0" y="23" width="1440" height="786" />
|
107
|
+
</state>
|
108
|
+
<state width="1207" height="201" key="GridCell.Tab.0.right/0.23.1440.786@0.23.1440.786" timestamp="1581885116972" />
|
109
|
+
<state x="352" y="201" width="819" height="558" key="find.popup" timestamp="1581885294826">
|
110
|
+
<screen x="0" y="23" width="1440" height="786" />
|
111
|
+
</state>
|
112
|
+
<state x="352" y="201" width="819" height="558" key="find.popup/0.23.1440.786@0.23.1440.786" timestamp="1581885294826" />
|
113
|
+
</component>
|
114
|
+
</project>
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at astudnev@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 astudnev
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Activecube: Multi-Dimensional Queries with Rails
|
2
|
+
|
3
|
+
Activecube is the library to make multi-dimensional queries to data warehouse, such as:
|
4
|
+
|
5
|
+
```sql
|
6
|
+
|
7
|
+
Cube.slice(
|
8
|
+
date: cube.dimensions[:date][:date].format('%Y-%m'),
|
9
|
+
currency: cube.dimensions[:currency][:symbol]
|
10
|
+
).measure(:count).
|
11
|
+
when(cube.selectors[:currency].in('USD','EUR').to_sql
|
12
|
+
```
|
13
|
+
|
14
|
+
Cube, dimensions, metrics and selectors are defined in the Model, similary to
|
15
|
+
ActiveRecord.
|
16
|
+
|
17
|
+
Activecube uses Rails ActiveRecord in implementation.
|
18
|
+
|
19
|
+
In particular, you have to define all tables, used in
|
20
|
+
Activecube, as ActiveRecord tables.
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
gem 'activecube'
|
30
|
+
```
|
31
|
+
|
32
|
+
And then execute:
|
33
|
+
|
34
|
+
$ bundle
|
35
|
+
|
36
|
+
Or install it yourself as:
|
37
|
+
|
38
|
+
$ gem install activecube
|
39
|
+
|
40
|
+
## Usage
|
41
|
+
|
42
|
+
TBD
|
43
|
+
|
44
|
+
## Development
|
45
|
+
|
46
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
47
|
+
|
48
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/activecube. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
57
|
+
|
58
|
+
## Code of Conduct
|
59
|
+
|
60
|
+
Everyone interacting in the Activecube project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/activecube/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/activecube.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "activecube/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "activecube"
|
8
|
+
spec.version = Activecube::VERSION
|
9
|
+
spec.authors = ["Aleksey Studnev"]
|
10
|
+
spec.email = ["astudnev@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Multi-Dimensional Queries with Rails}
|
13
|
+
spec.description = %q{Activecube is the library to make multi-dimensional queries to data.Cube, dimensions, metrics and selectors are defined in the Model, similary to ActiveRecord.
|
14
|
+
Activecube uses Rails ActiveRecord in implementation. In particular, you have to define all tables, used in Activecube, as ActiveRecord tables.}
|
15
|
+
spec.homepage = "https://github.com/bitquery/activecube"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_runtime_dependency 'activerecord', '>= 5.2'
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "activecube"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/activecube.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Activecube::ActiveRecordExtension
|
4
|
+
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
class_methods do
|
8
|
+
|
9
|
+
attr_reader :activecube_indexes
|
10
|
+
private
|
11
|
+
def index index_name, *args
|
12
|
+
(@activecube_indexes ||= []) << Activecube::Processor::Index.new(index_name,*args)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
# include the extension
|
20
|
+
ActiveRecord::Base.send(:include, Activecube::ActiveRecordExtension)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Activecube::Clickhouse::Metric
|
2
|
+
|
3
|
+
class Sum < Activecube::Metric
|
4
|
+
|
5
|
+
def expression arel_table, measure, cube_query
|
6
|
+
column = arel_table[self.class.column_name.to_sym]
|
7
|
+
measure.selectors.empty? ? column.sum : column.sumIf(measure.condition_query arel_table, cube_query)
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Activecube
|
2
|
+
module CubeDefinition
|
3
|
+
|
4
|
+
class DefinitionError < ::StandardError
|
5
|
+
end
|
6
|
+
|
7
|
+
class NamedHash < Hash
|
8
|
+
|
9
|
+
def initialize cube, entry_class
|
10
|
+
@cube = cube
|
11
|
+
@entry_class = entry_class
|
12
|
+
end
|
13
|
+
|
14
|
+
def [] key
|
15
|
+
v = super key
|
16
|
+
v.nil? ? nil : @entry_class.new(@cube, key, v)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :dimensions, :metrics, :selectors, :tables
|
22
|
+
|
23
|
+
def inspect
|
24
|
+
name +
|
25
|
+
(@dimensions && " Dimensions: #{@dimensions.keys.join(',')}")+
|
26
|
+
(@metrics && " Metrics: #{@metrics.keys.join(',')}")+
|
27
|
+
(@selectors && " Selectors: #{@selectors.keys.join(',')}")+
|
28
|
+
(@tables && " Tables: #{@tables.map(&:name).join(',')}")
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def dimension data
|
34
|
+
store_definition_map! 'dimension', (@dimensions ||= NamedHash.new(self, Query::Slice) ), data
|
35
|
+
end
|
36
|
+
|
37
|
+
def metric data
|
38
|
+
store_definition_map! 'metric', (@metrics ||= NamedHash.new(self, Query::Measure)), data
|
39
|
+
end
|
40
|
+
|
41
|
+
def selector data
|
42
|
+
store_definition_map! 'filter', (@selectors ||= NamedHash.new(self, Query::Selector)), data
|
43
|
+
end
|
44
|
+
|
45
|
+
def table *args
|
46
|
+
store_definition_array! 'table', (@tables ||= []), [*args].flatten.map{|t| Processor::Table.new t }
|
47
|
+
end
|
48
|
+
|
49
|
+
def store_definition_map! name, map, data
|
50
|
+
data.each_pair do |key, class_def|
|
51
|
+
raise DefinitionError, "#{key} already defined for #{name}" if map.has_key?(key)
|
52
|
+
map[key] = class_def.new
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def store_definition_array! name, array, data
|
57
|
+
values = data & array
|
58
|
+
raise DefinitionError, "#{values.join(',')} already defined for #{name}" unless values.empty?
|
59
|
+
array.concat data
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|