Commit ed8461a5 authored by Jérome Perrin's avatar Jérome Perrin

inventory/catalog: use catalog to select, group & order by slot_index

Instead of having complex logic expressed in dtml in the template.

Extend `extra_column_list` argument meaning: it becomes list of columns
that exists because they are in the template SQL.
parent 788bcaa1
Pipeline #4602 skipped
......@@ -507,10 +507,24 @@ class SimulationTool(BaseTool):
new_sort_on.append((column_id, sort_direction))
new_kw['sort_on'] = tuple(new_sort_on)
# Remove some internal parameters that does not have any meaning for
# catalog
new_kw.pop('ignore_group_by', None)
# When group_by_time_sequence_list is used, the ZSQL method template will use a variable
# slot_index, we want to select it, group and order by it, but it's not
# a known catalog columns.
# The temporary solution is to use SQLCatalog query builder with this
# column passed in extra_column_list and by extending extra_column_list
# meaning to just pass-through non mapped columns (ie. in "column"
# format and not "table.column" format)
if sql_kw.get('group_by_time_sequence_list'):
new_kw['extra_column_list'] = new_kw.get('extra_column_list', []) + ['slot_index']
new_kw['group_by_list'] = new_kw.get('group_by_list', []) + ['slot_index']
new_kw['order_by_list'] = new_kw.get('order_by_list', []) + [('slot_index', )]
new_kw.setdefault('select_dict', {})['slot_index'] = 'slot_index'
sql_kw.update(ctool.buildSQLQuery(**new_kw))
return sql_kw
......
......@@ -77,7 +77,6 @@ SELECT
COUNT(DISTINCT <dtml-var stock_table_id>.uid) AS stock_uid,
MAX(<dtml-var stock_table_id>.date) AS date
</dtml-if>
<dtml-if group_by_time_sequence_list>, slot_index </dtml-if> <dtml-comment>XXX is this really needed? are empty slots returned ? </dtml-comment>
<dtml-if select_expression>, <dtml-var select_expression></dtml-if>
......@@ -188,16 +187,11 @@ WHERE
<dtml-if group_by_expression>
GROUP BY
<dtml-if transformed_uid>transformation.transformed_uid,</dtml-if>
<dtml-if group_by_time_sequence_list>slot_index,</dtml-if>
<dtml-var group_by_expression>
</dtml-if>
<dtml-if order_by_expression>
ORDER BY
<dtml-var order_by_expression>
<dtml-else>
<dtml-if group_by_time_sequence_list>
ORDER BY slot_index
</dtml-if>
</dtml-if>
</dtml-let>
......@@ -94,9 +94,10 @@ class EntireQuery(object):
self.column_map = column_map
if 1:
for extra_column in self.extra_column_list:
table, column = extra_column.replace('`', '').split('.')
if table != self.catalog_table_name:
raise ValueError, 'Extra columns must be catalog columns. %r does not follow this rule (catalog=%r, extra_column_list=%r)' % (extra_column, self.catalog_table_name, self.extra_column_list)
if '.' in extra_column:
table, column = extra_column.replace('`', '').split('.')
if table != self.catalog_table_name:
raise ValueError, 'Extra columns must be catalog columns. %r does not follow this rule (catalog=%r, extra_column_list=%r)' % (extra_column, self.catalog_table_name, self.extra_column_list)
column_map.registerColumn(extra_column)
for column in self.group_by_list:
column_map.registerColumn(column)
......
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