Commit be816eed authored by Boris Kocherov's avatar Boris Kocherov

ColumnMap: use complex sql function as column name

also fix default value search in related_key_dict
parent df06708b
......@@ -50,6 +50,7 @@ MAPPING_TRACE = False
# TODO: rename all "related_key" references into "virtual_column"
re_sql_as = re.compile("\s+AS\s[^)]+$", re.IGNORECASE | re.MULTILINE)
re_sql_function_column = re.compile("([\s\w\(]*\()\s*([`\s*\w.]*)\s*([=,\)][=,\)+-:%'\"\s\w]*)")
class ColumnMap(object):
......@@ -114,10 +115,10 @@ class ColumnMap(object):
# XXX This is not enough to parse something like:
# GROUP_CONCAT(DISTINCT foo ORDER BY bar)
if '(' in raw_column:
function, column = raw_column.split('(')
__traceback_info__ = raw_column
function_begin, column, function_end = re_sql_function_column.match(raw_column).groups()
column = column.strip()
assert column[-1] == ')', column
column = column[:-1].strip()
function = function_begin.strip(), function_end.strip()
else:
function = None
column = raw_column
......@@ -465,14 +466,15 @@ class ColumnMap(object):
column_suffix = ''
function, column = self.raw_column_dict.get(raw_column, (None, raw_column))
if group is DEFAULT_GROUP_ID:
group, column = self.related_key_dict.get(column, (group, raw_column))
group, column = self.related_key_dict.get(column, (group, column))
alias = self.table_alias_dict[(group, self.column_map[(group, column)])]
if column_suffix:
result = '%s_%s%s' % (alias, column, column_suffix)
else:
result = '`%s`.`%s`' % (alias, column)
if function is not None:
result = '%s(%s)' % (function, result)
function_begin, function_end = function
result = "".join((function_begin, result, function_end))
return result
def getCatalogTableAlias(self, group=DEFAULT_GROUP_ID):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment