directiverecord 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.rdoc +4 -0
- data/VERSION +1 -1
- data/lib/directive_record/query/big_query.rb +11 -5
- data/lib/directive_record/version.rb +1 -1
- data/test/unit/query/test_big_query.rb +26 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODE3NDA0NWNiMzAzMmNlMTg5YjFjNmFkMTFmOWFhOGEwOThjZDdhNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTU3ZWYyYzhhY2U2MTcxOGFkNGMzOWUxZDgwNDVjN2U5ZDZjMjFiYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODhjZTIzZGNhNTE3OTExNjRhMzEwYzkyYjJlNTExMzBhN2QyZmNhMDkyMmRl
|
10
|
+
ZDhhZTU2MTM1MzM2MzIyOWJmYTZhNDI2ZmFlYWM0OTQ4YTZlMjJkZGMxODM3
|
11
|
+
ODE0OGVjNzYxYmYzYTdjZmFkYTU0ODRmMDNkZjQ0MThmYzllZDI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTBiZWE5Y2QwYWQ3M2QyZTE5ZjlhYmIxMDUxOTQ1MjM5MjEyNDA3MzQzODM0
|
14
|
+
MjZiMmJhMjU3ODAzZjc0ZjZhOTAwZTQzZWRmOTgzN2Y1NDBiYWZkNDE4MWU5
|
15
|
+
MWY4YTEyMzVmZmQ0YzkzYTQzMjFlYTEzZjRmYTJlYjIzZTMwNTQ=
|
data/CHANGELOG.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.6
|
@@ -33,12 +33,18 @@ module DirectiveRecord
|
|
33
33
|
aliases = options[:aliases] || {}
|
34
34
|
|
35
35
|
options[:select].collect! do |string|
|
36
|
-
|
37
|
-
|
38
|
-
aliases[
|
39
|
-
|
36
|
+
if string.match(/^(.*) AS (.*)$/)
|
37
|
+
select_expression, select_alias = $1, $2
|
38
|
+
aliases[select_expression] = select_alias
|
39
|
+
end
|
40
|
+
|
41
|
+
select_expression ||= string
|
42
|
+
group_by_expression = select_alias || string
|
43
|
+
|
44
|
+
if options[:group_by].include?(group_by_expression) || !select_expression.match(/^\w+(\.\w+)*$/)
|
45
|
+
string
|
40
46
|
else
|
41
|
-
|
47
|
+
["MAX(#{select_expression})", select_alias].compact.join(" AS ")
|
42
48
|
end
|
43
49
|
end if options[:group_by]
|
44
50
|
|
@@ -18,7 +18,7 @@ module Unit
|
|
18
18
|
it "generates the expected SQL" do
|
19
19
|
assert_equal(
|
20
20
|
%Q{
|
21
|
-
SELECT
|
21
|
+
SELECT id,
|
22
22
|
SUM(order_details_quantity_ordered) AS sum__order_details_quantity_ordered,
|
23
23
|
SUM(order_details_price_each) AS sum__order_details_price_each,
|
24
24
|
SUM(order_details_quantity_ordered * order_details_price_each) AS price
|
@@ -43,7 +43,7 @@ module Unit
|
|
43
43
|
|
44
44
|
assert_equal(
|
45
45
|
%Q{
|
46
|
-
SELECT
|
46
|
+
SELECT id, SUM(order_details_quantity_ordered * order_details_price_each)
|
47
47
|
FROM
|
48
48
|
[my_stats.orders_20150115],
|
49
49
|
[my_stats.orders_20150116],
|
@@ -64,6 +64,30 @@ module Unit
|
|
64
64
|
:period => "order_date"
|
65
65
|
).strip.gsub(/\s+/, " ")
|
66
66
|
)
|
67
|
+
|
68
|
+
assert_equal(
|
69
|
+
%Q{
|
70
|
+
SELECT id, MAX(customer_id), SUM(order_details_quantity_ordered * order_details_price_each)
|
71
|
+
FROM
|
72
|
+
[my_stats.orders_20150115],
|
73
|
+
[my_stats.orders_20150116],
|
74
|
+
[my_stats.orders_20150117],
|
75
|
+
[my_stats.orders_20150118],
|
76
|
+
[my_stats.orders_20150119],
|
77
|
+
[my_stats.orders_20150120],
|
78
|
+
[my_stats.orders_20150121]
|
79
|
+
GROUP BY id
|
80
|
+
ORDER BY id
|
81
|
+
}.strip.gsub(/\s+/, " "),
|
82
|
+
Order.to_qry(
|
83
|
+
"id", "customer_id", "SUM(order_details.quantity_ordered * order_details.price_each)",
|
84
|
+
:connection => BigQuery.connection,
|
85
|
+
:where => "order_date >= '2015-01-15' AND order_date <= '2015-01-21'",
|
86
|
+
:group_by => "id",
|
87
|
+
:order_by => "id",
|
88
|
+
:period => "order_date"
|
89
|
+
).strip.gsub(/\s+/, " ")
|
90
|
+
)
|
67
91
|
end
|
68
92
|
end
|
69
93
|
|