22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/fluent-query/drivers/shared/tokens/sql/groupby.rb', line 22
def render!(mode = :build)
stack = [ ]
unknown = [ ]
fields = [ ]
aliases = { }
distinct = false
result = "GROUP BY "
processor = @_query.processor
_class = self.unknown_token
@_subtokens.each do |token|
arguments = token.arguments
name = token.name
if name == :groupBy
length = arguments.length
if length > 0
first = arguments.first
if first.symbol?
stack << arguments
elsif first.string?
stack << processor.process_formatted(arguments, mode)
else
arguments.each do |argument|
if argument.array?
fields += argument
end
end
end
end
if unknown.length > 0
native = _class::new(@_driver, @_query, unknown)
stack << native.render!
unknown = [ ]
end
else
unknown << token
end
end
if unknown.length > 0
native = _class::new(@_driver, @_query, unknown)
stack << native.render!
unknown = [ ]
end
first = true
if not fields.empty?
stack.unshift(fields.uniq)
end
stack.each do |item|
if item.array?
if not first
result << ", "
end
result << processor.process_identifiers(item)
first = false
elsif item.string?
if not first
result << ", "
end
result << item.strip!
first = false
end
end
return result
end
|