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): ...@@ -507,10 +507,24 @@ class SimulationTool(BaseTool):
new_sort_on.append((column_id, sort_direction)) new_sort_on.append((column_id, sort_direction))
new_kw['sort_on'] = tuple(new_sort_on) new_kw['sort_on'] = tuple(new_sort_on)
# Remove some internal parameters that does not have any meaning for # Remove some internal parameters that does not have any meaning for
# catalog # catalog
new_kw.pop('ignore_group_by', None) 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)) sql_kw.update(ctool.buildSQLQuery(**new_kw))
return sql_kw return sql_kw
......
...@@ -77,7 +77,6 @@ SELECT ...@@ -77,7 +77,6 @@ SELECT
COUNT(DISTINCT <dtml-var stock_table_id>.uid) AS stock_uid, COUNT(DISTINCT <dtml-var stock_table_id>.uid) AS stock_uid,
MAX(<dtml-var stock_table_id>.date) AS date MAX(<dtml-var stock_table_id>.date) AS date
</dtml-if> </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> <dtml-if select_expression>, <dtml-var select_expression></dtml-if>
...@@ -188,16 +187,11 @@ WHERE ...@@ -188,16 +187,11 @@ WHERE
<dtml-if group_by_expression> <dtml-if group_by_expression>
GROUP BY GROUP BY
<dtml-if transformed_uid>transformation.transformed_uid,</dtml-if> <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-var group_by_expression>
</dtml-if> </dtml-if>
<dtml-if order_by_expression> <dtml-if order_by_expression>
ORDER BY ORDER BY
<dtml-var order_by_expression> <dtml-var order_by_expression>
<dtml-else>
<dtml-if group_by_time_sequence_list>
ORDER BY slot_index
</dtml-if>
</dtml-if> </dtml-if>
</dtml-let> </dtml-let>
...@@ -94,6 +94,7 @@ class EntireQuery(object): ...@@ -94,6 +94,7 @@ class EntireQuery(object):
self.column_map = column_map self.column_map = column_map
if 1: if 1:
for extra_column in self.extra_column_list: for extra_column in self.extra_column_list:
if '.' in extra_column:
table, column = extra_column.replace('`', '').split('.') table, column = extra_column.replace('`', '').split('.')
if table != self.catalog_table_name: 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) 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)
......
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