Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle max=v and x=max(v) correctly.
Fix V:1 not being usable as a keyword.
- Loading branch information
1 parent
2214fc1
commit f025e65
Showing
20 changed files
with
127 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Sql | ||
class AggregateExpression | ||
def self.aggregate_sql(table_set, expr) | ||
return expr.to_sql unless expr.field | ||
self.new(table_set, expr).to_sql | ||
end | ||
|
||
attr_reader :table_set, :expr, :column | ||
|
||
def initialize(table_set, expr) | ||
@table_set = table_set | ||
@expr = expr | ||
@column = @expr.column | ||
STDERR.puts("column name: #{@column.name}, expr: #{@expr.expr}") | ||
end | ||
|
||
def to_sql | ||
return version_maxmin_sql if version_column? && max_min_expr? | ||
@expr.to_sql | ||
end | ||
|
||
def version_column? | ||
@column.name == 'v' || @column.name == 'cv' | ||
end | ||
|
||
def max_min_expr? | ||
@expr.expr =~ /^(?:max|min)/i | ||
end | ||
|
||
private | ||
def version_maxmin_sql | ||
field = @expr.field.field | ||
original_sql_field_name = field.sql_column_name | ||
reference_table = Sql::QueryTable.table(@column.lookup_table) | ||
@table_set.resolve!(reference_table, true) | ||
field.name = field.name + 'num' | ||
key_field_sql = @expr.expr | ||
sql = ("(SELECT #{original_sql_field_name} " + | ||
"FROM #{reference_table.to_sql} WHERE " + | ||
"#{reference_table.field_sql(field)} = #{key_field_sql})") | ||
sql = "#{sql} AS #{@expr.calias}" if @expr.calias | ||
sql | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class StringFixup | ||
def initialize(fixup_map) | ||
@map = Hash[fixup_map.map { |key, value| | ||
value = [value] unless value.is_a?(Array) | ||
value = value.map { |r| | ||
r.sub(%r/\$(\d)/, '\\\1') | ||
} | ||
[%r/#{key}/i, value] | ||
}] | ||
end | ||
|
||
def fixup(text) | ||
for regex, replacements in @map | ||
if text =~ regex | ||
return replacements.map { |r| | ||
text.sub(regex, r) | ||
} | ||
end | ||
end | ||
[text] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters