directiverecord 0.1.20 → 0.1.21

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
- Nzc2MmU5YWE1N2FhM2VhYzFhYmQ3OWMyOTYzNjAwNDZjYjgyOTAzNw==
4
+ MmYzMWQ2NTkwOWRkMWJhNTRhNDVjM2U5ODYzNTgwY2ZhZWU4YzkyMQ==
5
5
  data.tar.gz: !binary |-
6
- ZjdmNzkzNGNhYTJmYTM1YzVlYWRlY2NkNzk0MzNmNjFmMWQzODllNw==
6
+ Mzg2NmQzNmJjYmI0Y2ZhOGY1ODM1YTBhMmE3NjUzNjU5ZjBmZWU4Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OTZjYjJjMzliZDljNjY3OTQ2MzU0MWMwOTJlZWU1ODNlMzM1Mjk0MmE0ZmJm
10
- MWEwOGMwYzNlMzEzMmIyYjBlNzJlM2MzMWI4ZDZhZmNlMGFlMzcwNjM4NjUz
11
- YjRjZjY3YWM1ZTkxYzhlOTE2Y2RkNGY3YWVmMjA5YjI0OGJlMWI=
9
+ MGRjNjBmNmQ5ZTJkNTVmMjUxMDk3MDM4ZTdlYWQ3MTY0YmY4OGI0Mzk3Y2Ix
10
+ MmZmY2MyYTI1ZTc0Mjc4MmQ2YjA3NWZhNmRiNTFlOGU2ZDk0NDk5NDJmYjA1
11
+ NmY5YmQwYTczNWM3MGY2MTI2ZTg4MzBiYTk4MDZmNDQ4NGVlZWY=
12
12
  data.tar.gz: !binary |-
13
- NGU5ZDkzYjIyZGE1MDU2ZjgzODFjODgzZmZhM2Y5OGM1ODgxOTkwZjE5Mzhk
14
- NmU0NjY1ZWI4ZWI2ZGU3ZTljOTlkOTEyOTBjY2UwZmYyZjQwMmQwOTU0NmY4
15
- OGY2ZmE1NjJjY2FmZTA2OGNhNzZkOWUyMmJlZDVhYWIzOGNmNWQ=
13
+ NDRjNjg0NmJhZjhkYmY0OTZmOTg1YjA3MjQ1YmQ5MDAzY2E0OTQ1OGZlYjRl
14
+ NzQzMDQ0MGVmNTRiNDE0NzIwNGRkYjUwMzljYjA4YTFkOWEyNjAxMWIyODhk
15
+ Mzc5YWY0MjBiMmVhYzVhNzMzMGVkMWMyYTVhY2JlZmJmMjk2MzI=
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,11 @@
1
1
  = DirectiveRecord CHANGELOG
2
2
 
3
+ == Version 0.1.21 (April 3, 2015)
4
+
5
+ * Storing original sql alias of a calculated column when numerizing aliases
6
+ * Updating SELECT statement when dealing with auto-aggregated field as a HAVING statement
7
+ * Corrected having multiple HAVING statements within a BigQuery query
8
+
3
9
  == Version 0.1.20 (April 3, 2015)
4
10
 
5
11
  * Improved HAVING statement detection
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.20
1
+ 0.1.21
@@ -45,11 +45,13 @@ module DirectiveRecord
45
45
  end
46
46
  end if options[:group_by]
47
47
 
48
- [:group_by, :having, :order_by].each do |key|
49
- if value = options[key]
50
- value = value.join ", "
51
- aliases.each{|pattern, replacement| value.gsub! pattern, replacement}
52
- options[key] = value
48
+ {", " => [:group_by, :order_by], " AND " => [:having]}.each do |delimiter, keys|
49
+ keys.each do |key|
50
+ if value = options[key]
51
+ value = value.join delimiter
52
+ aliases.each{|pattern, replacement| value.gsub! pattern, replacement}
53
+ options[key] = value
54
+ end
53
55
  end
54
56
  end
55
57
  end
@@ -150,16 +150,19 @@ SQL
150
150
  sql = "ROUND(#{sql}, #{scale})"
151
151
  sql_alias ||= quote_alias(path)
152
152
  end
153
- if options[:numerize_aliases]
154
- sql = sql.gsub(/ AS .*$/, "")
155
- sql_alias = options[:aliases][prepend_base_alias(sql_alias || sql)] = "c#{array.size + 1}"
156
- end
153
+
157
154
  unless sql_alias
158
155
  sql.match(/^(.*) AS (.*)$/)
159
156
  sql = $1 if $1
160
157
  sql_alias = $2
161
158
  end
162
159
 
160
+ if options[:numerize_aliases]
161
+ c_alias = "c#{array.size + 1}"
162
+ options[:aggregated][sql_alias] = c_alias if !aggregate_method && sql_alias
163
+ sql_alias = options[:aliases][prepend_base_alias(sql_alias || sql)] = c_alias
164
+ end
165
+
163
166
  sql.gsub!(/sub:(\w+)\./) { "#{quote_alias($1)}." } if sql.is_a?(String)
164
167
  options[:aliases][sql] = sql_alias if sql_alias
165
168
 
@@ -242,7 +245,15 @@ SQL
242
245
  .all? do |sql|
243
246
  sql.match /(.*?)\s*(=|<=>|>=|>|<=|<|<>|!=|is|like|rlike|regexp|in|between|not|sounds|soundex)(\b|\s|$)/i
244
247
  path = $1.strip
245
- !(aliases[path] || path).match(/\b(count|sum|min|max|avg)\(/i)
248
+
249
+ if (options[:aggregates] || {})[path]
250
+ normalize_select!(opts = options.deep_dup.merge(:select => [path]))
251
+ options[:select].concat(opts[:select]).uniq!
252
+ options[:aggregated].merge!(opts[:aggregated])
253
+ false
254
+ else
255
+ !(aliases[path] || path).match(/\b(count|sum|min|max|avg)\(/i)
256
+ end
246
257
  end
247
258
  end
248
259
 
@@ -1,7 +1,7 @@
1
1
  module DirectiveRecord
2
2
  MAJOR = 0
3
3
  MINOR = 1
4
- TINY = 20
4
+ TINY = 21
5
5
 
6
6
  VERSION = [MAJOR, MINOR, TINY].join(".")
7
7
  end
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.20
4
+ version: 0.1.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Engel