activerecord-jdbcteradata-adapter 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/activerecord-jdbcteradata-adapter.gemspec +1 -1
- data/lib/arel/visitors/teradata.rb +25 -25
- metadata +2 -2
data/Gemfile.lock
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "activerecord-jdbcteradata-adapter"
|
3
|
-
s.version = "0.3.
|
3
|
+
s.version = "0.3.4"
|
4
4
|
s.authors = ["Chris Parker"]
|
5
5
|
s.email = [ "mrcsparker@gmail.com"]
|
6
6
|
s.homepage = "https://github.com/mrcsparker/activerecord-jdbcteradata-adapter"
|
@@ -24,15 +24,15 @@ module Arel
|
|
24
24
|
|
25
25
|
class SelectManager < Arel::TreeManager
|
26
26
|
|
27
|
-
AR_CA_SQLSA_NAME = '
|
27
|
+
AR_CA_SQLSA_NAME = 'Teradata'.freeze
|
28
28
|
|
29
29
|
# Getting real Ordering objects is very important for us. We need to be able to call #uniq on
|
30
30
|
# a colleciton of them reliably as well as using their true object attributes to mutate them
|
31
31
|
# to grouping objects for the inner sql during a select statment with an offset/rownumber. So this
|
32
32
|
# is here till ActiveRecord & ARel does this for us instead of using SqlLiteral objects.
|
33
|
-
alias :
|
33
|
+
alias :order_without_teradata :order
|
34
34
|
def order(*expr)
|
35
|
-
return
|
35
|
+
return order_without_teradata(*expr) unless engine_activerecord_teradata_adapter?
|
36
36
|
@ast.orders.concat(expr.map{ |x|
|
37
37
|
case x
|
38
38
|
when Arel::Attributes::Attribute
|
@@ -60,9 +60,9 @@ module Arel
|
|
60
60
|
|
61
61
|
# A friendly over ride that allows us to put a special lock object that can have a default or pass
|
62
62
|
# custom string hints down. See the visit_Arel_Nodes_LockWithTeradata delegation method.
|
63
|
-
alias :
|
63
|
+
alias :lock_without_teradata :lock
|
64
64
|
def lock(locking=true)
|
65
|
-
if
|
65
|
+
if engine_activerecord_teradata_adapter?
|
66
66
|
case locking
|
67
67
|
when true
|
68
68
|
locking = Arel.sql('WITH(HOLDLOCK, ROWLOCK)')
|
@@ -73,14 +73,14 @@ module Arel
|
|
73
73
|
@ast.lock = Arel::Nodes::Lock.new(locking)
|
74
74
|
self
|
75
75
|
else
|
76
|
-
|
76
|
+
lock_without_teradata(locking)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
80
|
private
|
81
81
|
|
82
|
-
def
|
83
|
-
@engine.connection && @engine.connection.
|
82
|
+
def engine_activerecord_teradata_adapter?
|
83
|
+
@engine.connection && @engine.connection.adapter_name == AR_CA_SQLSA_NAME
|
84
84
|
end
|
85
85
|
|
86
86
|
end
|
@@ -104,13 +104,13 @@ module Arel
|
|
104
104
|
|
105
105
|
def visit_Arel_Nodes_UpdateStatement(o)
|
106
106
|
if o.orders.any? && o.limit.nil?
|
107
|
-
o.limit = Nodes::Limit.new(
|
107
|
+
o.limit = Nodes::Limit.new(214748364)
|
108
108
|
end
|
109
109
|
super
|
110
110
|
end
|
111
111
|
|
112
112
|
def visit_Arel_Nodes_Offset(o)
|
113
|
-
"WHERE
|
113
|
+
"WHERE __rnt.__rn > (#{visit o.expr})"
|
114
114
|
end
|
115
115
|
|
116
116
|
def visit_Arel_Nodes_Limit(o)
|
@@ -158,7 +158,7 @@ module Arel
|
|
158
158
|
[ ("SELECT" if !windowed),
|
159
159
|
(visit(core.set_quantifier) if core.set_quantifier && !windowed),
|
160
160
|
(visit(o.limit) if o.limit && !windowed),
|
161
|
-
(projections.map{ |x| v = visit(x); v == "1" ? "1 AS
|
161
|
+
(projections.map{ |x| v = visit(x); v == "1" ? "1 AS __wrp" : v }.join(', ')),
|
162
162
|
(source_with_lock_for_select_statement(o)),
|
163
163
|
("WHERE #{core.wheres.map{ |x| visit(x) }.join ' AND ' }" unless core.wheres.empty?),
|
164
164
|
("GROUP BY #{groups.map { |x| visit x }.join ', ' }" unless groups.empty?),
|
@@ -169,17 +169,17 @@ module Arel
|
|
169
169
|
|
170
170
|
def visit_Arel_Nodes_SelectStatementWithOffset(o)
|
171
171
|
core = o.cores.first
|
172
|
-
o.limit ||= Arel::Nodes::Limit.new(
|
172
|
+
o.limit ||= Arel::Nodes::Limit.new(214748364)
|
173
173
|
orders = rowtable_orders(o)
|
174
174
|
[ "SELECT",
|
175
175
|
(visit(o.limit) if o.limit && !windowed_single_distinct_select_statement?(o)),
|
176
176
|
(rowtable_projections(o).map{ |x| visit(x) }.join(', ')),
|
177
177
|
"FROM (",
|
178
|
-
"SELECT #{core.set_quantifier ? 'DISTINCT DENSE_RANK()' : 'ROW_NUMBER()'} OVER (ORDER BY #{orders.map{ |x| visit(x) }.join(', ')}) AS
|
178
|
+
"SELECT #{core.set_quantifier ? 'DISTINCT DENSE_RANK()' : 'ROW_NUMBER()'} OVER (ORDER BY #{orders.map{ |x| visit(x) }.join(', ')}) AS __rn,",
|
179
179
|
visit_Arel_Nodes_SelectStatementWithOutOffset(o,true),
|
180
|
-
") AS
|
180
|
+
") AS __rnt",
|
181
181
|
(visit(o.offset) if o.offset),
|
182
|
-
"ORDER BY
|
182
|
+
"ORDER BY __rnt.__rn ASC"
|
183
183
|
].compact.join ' '
|
184
184
|
end
|
185
185
|
|
@@ -187,18 +187,18 @@ module Arel
|
|
187
187
|
core = o.cores.first
|
188
188
|
o.limit.expr = Arel.sql("#{o.limit.expr} + #{o.offset ? o.offset.expr : 0}") if o.limit
|
189
189
|
orders = rowtable_orders(o)
|
190
|
-
[ "SELECT COUNT(
|
190
|
+
[ "SELECT COUNT(count) AS count_id",
|
191
191
|
"FROM (",
|
192
192
|
"SELECT",
|
193
193
|
(visit(o.limit) if o.limit),
|
194
|
-
"ROW_NUMBER() OVER (ORDER BY #{orders.map{ |x| visit(x) }.join(', ')}) AS
|
195
|
-
"1 AS
|
194
|
+
"ROW_NUMBER() OVER (ORDER BY #{orders.map{ |x| visit(x) }.join(', ')}) AS __rn,",
|
195
|
+
"1 AS count",
|
196
196
|
(source_with_lock_for_select_statement(o)),
|
197
197
|
("WHERE #{core.wheres.map{ |x| visit(x) }.join ' AND ' }" unless core.wheres.empty?),
|
198
198
|
("GROUP BY #{core.groups.map { |x| visit x }.join ', ' }" unless core.groups.empty?),
|
199
199
|
(visit(core.having) if core.having),
|
200
200
|
("ORDER BY #{o.orders.map{ |x| visit(x) }.join(', ')}" if !o.orders.empty?),
|
201
|
-
") AS
|
201
|
+
") AS __rnt",
|
202
202
|
(visit(o.offset) if o.offset)
|
203
203
|
].compact.join ' '
|
204
204
|
end
|
@@ -325,8 +325,8 @@ module Arel
|
|
325
325
|
j2_tn = j2.match(/JOIN \[(.*)\].*ON/).try(:[],1)
|
326
326
|
return unless j1_tn == j2_tn
|
327
327
|
on_index = j2.index(' ON ')
|
328
|
-
j2.insert on_index, " AS
|
329
|
-
j2.sub! "[#{j2_tn}].", "
|
328
|
+
j2.insert on_index, " AS #{j2_tn}_crltd"
|
329
|
+
j2.sub! "[#{j2_tn}].", "#{j2_tn}_crltd."
|
330
330
|
end
|
331
331
|
|
332
332
|
def rowtable_projections(o)
|
@@ -337,7 +337,7 @@ module Arel
|
|
337
337
|
x.dup.tap do |p|
|
338
338
|
p.sub! 'DISTINCT', ''
|
339
339
|
p.insert 0, visit(o.limit) if o.limit
|
340
|
-
p.gsub! /\
|
340
|
+
p.gsub! /\"?#{tn}\\"?\./, '__rnt.'
|
341
341
|
p.strip!
|
342
342
|
end
|
343
343
|
end
|
@@ -346,7 +346,7 @@ module Arel
|
|
346
346
|
core.projections.map do |x|
|
347
347
|
x.dup.tap do |p|
|
348
348
|
p.sub! 'DISTINCT', "DISTINCT #{visit(o.limit)}".strip if o.limit
|
349
|
-
p.gsub! /\
|
349
|
+
p.gsub! /\"?#{tn}\\"?\./, '__rnt.'
|
350
350
|
p.strip!
|
351
351
|
end
|
352
352
|
end
|
@@ -355,9 +355,9 @@ module Arel
|
|
355
355
|
Arel.sql visit(x).split(',').map{ |y| y.split(' AS ').last.strip }.join(', ')
|
356
356
|
end
|
357
357
|
elsif select_primary_key_sql?(o)
|
358
|
-
[Arel.sql("
|
358
|
+
[Arel.sql("__rnt.#{quote_column_name(core.projections.first.name)}")]
|
359
359
|
else
|
360
|
-
[Arel.sql('
|
360
|
+
[Arel.sql('__rnt.*')]
|
361
361
|
end
|
362
362
|
end
|
363
363
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-jdbcteradata-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|