Commit e4aa5476 authored by Vincent Pelletier's avatar Vincent Pelletier

ZSQLCatalog: Also render ignored columns

Ignored columns are produced when aliasing a column. For example,
aliasing "catalog.reference" as "reference".
Before this change, this would cause conditions on "reference" to be
rendered non-mapped, which can cause SQL execution issues when there is
more than one "reference" column available (catalog.reference and its
alias counting as only one), which is the case when
catalog-category-catalog joins happen.

Instead, render all columns which could be mapped, independently from
their "ignored" status.

Also, use a different local variable for table aliases than for column
aliases.
Also, use more "return" statements, and simplify conditional structure.
parent 8b6865ae
......@@ -435,13 +435,10 @@ class ColumnMap(object):
LOG('ColumnMap', INFO, ' %r as %r' % (table_name, table_alias))
def asSQLColumn(self, raw_column, group=DEFAULT_GROUP_ID):
if self.catalog_table_name is None or raw_column in self.column_ignore_set or \
'.' in raw_column or '*' in raw_column:
if self.catalog_table_name is None or '.' in raw_column or '*' in raw_column:
if raw_column.endswith('__score__'):
result = raw_column.replace('.', '_')
else:
result = raw_column
else:
return raw_column.replace('.', '_')
return raw_column
if raw_column.endswith('__score__'):
raw_column = raw_column[:-9]
column_suffix = '__score__'
......@@ -450,11 +447,18 @@ class ColumnMap(object):
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))
alias = self.table_alias_dict[(group, self.column_map[(group, column)])]
try:
table_name = self.column_map[(group, column)]
except KeyError:
if raw_column not in self.column_ignore_set:
raise
result = raw_column
else:
table_alias = self.table_alias_dict[(group, table_name)]
if column_suffix:
result = '%s_%s%s' % (alias, column, column_suffix)
result = '%s_%s%s' % (table_alias, column, column_suffix)
else:
result = '`%s`.`%s`' % (alias, column)
result = '`%s`.`%s`' % (table_alias, column)
if function is not None:
result = '%s(%s)' % (function, result)
return result
......
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