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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmViNTQwODFjYWQxNThmMzJjYzg0NzI1YjEwMzI3NmU1YzhiYjA1ZA==
4
+ ODE3NDA0NWNiMzAzMmNlMTg5YjFjNmFkMTFmOWFhOGEwOThjZDdhNw==
5
5
  data.tar.gz: !binary |-
6
- ZTJjNzVlZDY1YzRmZTQ0NTc5M2VlZDkyYjQ5YWVlZWZlMjhmMGNjMg==
6
+ ZTU3ZWYyYzhhY2U2MTcxOGFkNGMzOWUxZDgwNDVjN2U5ZDZjMjFiYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDZjZjQ1NGFhMzUwNzUyMzJlMzU0MzQwNGQ3YTQzYTQ5NTQyYWE2ZWFhMDI4
10
- NzZlNTgxYjE4OTAxMzJmZTZhN2UzOTRiZmIyODU3NWQwYzc4Y2M3YWM2MzA0
11
- NzA3OTA0MjE3ZTVhOGFiNzM3ZTIwOTU1NzZmNDU3ZjNhYTkxNzk=
9
+ ODhjZTIzZGNhNTE3OTExNjRhMzEwYzkyYjJlNTExMzBhN2QyZmNhMDkyMmRl
10
+ ZDhhZTU2MTM1MzM2MzIyOWJmYTZhNDI2ZmFlYWM0OTQ4YTZlMjJkZGMxODM3
11
+ ODE0OGVjNzYxYmYzYTdjZmFkYTU0ODRmMDNkZjQ0MThmYzllZDI=
12
12
  data.tar.gz: !binary |-
13
- MWQwZWM4NDU1ZmFiZDlkYmE5NDY4ZTZiYmIwNTM2NTI1Mjk1NjhjNjIxNDZi
14
- YjI2N2JjOGY5NDUyZDllZGZiMTMxMzI4ODc2Y2I2NGIwZDVmYzkyOGNkYzdl
15
- ODYwOTY4Y2QzNDRhZTg1MmU1Mzk1NWQyNDI4MTAzODE1NzU2NGE=
13
+ MTBiZWE5Y2QwYWQ3M2QyZTE5ZjlhYmIxMDUxOTQ1MjM5MjEyNDA3MzQzODM0
14
+ MjZiMmJhMjU3ODAzZjc0ZjZhOTAwZTQzZWRmOTgzN2Y1NDBiYWZkNDE4MWU5
15
+ MWY4YTEyMzVmZmQ0YzkzYTQzMjFlYTEzZjRmYTJlYjIzZTMwNTQ=
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,9 @@
1
1
  = DirectiveRecord CHANGELOG
2
2
 
3
+ == Version 0.1.6 (February 11, 2015)
4
+
5
+ * Improved BigQuery select statement correction concerning the group by statement
6
+
3
7
  == Version 0.1.5 (February 11, 2015)
4
8
 
5
9
  * Dropped :group_by => :all option
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
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
- expression, select_alias = string.match(/^(.*) AS (.*)$/).try(:captures)
37
- if select_alias
38
- aliases[expression] = select_alias
39
- options[:group_by].to_s.include?(expression) || !expression.match(/^\w+(\.\w+)*$/) ? string : "MAX(#{expression}) AS #{select_alias}"
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
- string.match(/^\w+(\.\w+)*$/) ? "MAX(#{string})" : string
47
+ ["MAX(#{select_expression})", select_alias].compact.join(" AS ")
42
48
  end
43
49
  end if options[:group_by]
44
50
 
@@ -1,7 +1,7 @@
1
1
  module DirectiveRecord
2
2
  MAJOR = 0
3
3
  MINOR = 1
4
- TINY = 5
4
+ TINY = 6
5
5
 
6
6
  VERSION = [MAJOR, MINOR, TINY].join(".")
7
7
  end
@@ -18,7 +18,7 @@ module Unit
18
18
  it "generates the expected SQL" do
19
19
  assert_equal(
20
20
  %Q{
21
- SELECT MAX(id),
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 MAX(id), SUM(order_details_quantity_ordered * order_details_price_each)
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: directiverecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Engel