[MediaWiki-commits] [Gerrit] Rename some date model keys to be clearer - change (operations...labsdb-auditor)

2015-01-10 Thread Yuvipanda (Code Review)
Yuvipanda has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/184131

Change subject: Rename some date model keys to be clearer
..

Rename some date model keys to be clearer

- Remove 'replacewith', since we will replace everything with only
  SQL 'NULL'
- 'condition' in the columns becomes 'null_if' since replacewith
  is no longer a thing, and 'null_if' makes it clearer that we
  are nulling columns if this is true, rather than false.
- 'where' in the table defintion becomes 'include_only_if', which
  makes it extremely clear what exactly it does.

Change-Id: I892f0ba4e6fa2db25696f1b7922f1e7c44630466
---
M auditor/models.py
M auditor/reports/viewdiffs.py
M greylisted.yaml
3 files changed, 95 insertions(+), 101 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/software/labsdb-auditor 
refs/changes/31/184131/1

diff --git a/auditor/models.py b/auditor/models.py
index 83d9b53..04829ec 100644
--- a/auditor/models.py
+++ b/auditor/models.py
@@ -24,7 +24,7 @@
 
 A column that is potentially conditionally or unconditionally nulled
 
-def __init__(self, name, whitelisted=True, condition=None, 
replacewith=None):
+def __init__(self, name, whitelisted=True, null_if=None):
 
 A column in a table that can be whitelisted or conditionally nulled
 
@@ -32,16 +32,15 @@
 
 :param name: Name of this column
 :param whitelisted: True if the column is whitelisted
-:param condition: Conditions under which this column is replaced.
-  Specified as a string that is valid SQL expression
-:param replacewith: What to replace the column's value with if 
condition is matched
-If set to None with whitelisted = False, implies 
SQL None
+:param null_if: Conditions under which this column is nulled.
+Specified as a string that is valid SQL expression.
+If set to None  whitelisted=False, then nulled all 
the time
+
 :return:
 
 self.name = name
 self.whitelisted = whitelisted
-self.condition = condition
-self.replacewith = replacewith
+self.null_if = null_if
 
 
 class Table(object):
@@ -70,10 +69,8 @@
 for c in self.columns.values():
 columndict = {}
 columndict['whitelisted'] = c.whitelisted
-if c.condition:
-columndict['condition'] = c.condition
-if c.replacewith:
-columndict['replacewith'] = c.replacewith
+if c.null_if:
+columndict['null_if'] = c.null_if
 tabledict['columns'][c.name] = columndict
 if self.table_name != self.name:
 tabledict['table_name'] = self.table_name
@@ -89,10 +86,7 @@
 else:
 # Greylisted table!
 for colname, coldata in tabledata['columns'].items():
-col = Column(colname,
- whitelisted=coldata.get('whitelisted'),
- condition=coldata.get('condition'),
- replacewith=coldata.get('replacewith'))
+col = Column(colname, coldata.get('whitelisted'), 
coldata.get('null_if'))
 table.add_column(col)
 return table
 
diff --git a/auditor/reports/viewdiffs.py b/auditor/reports/viewdiffs.py
index 7e9a54b..b9fa163 100644
--- a/auditor/reports/viewdiffs.py
+++ b/auditor/reports/viewdiffs.py
@@ -33,7 +33,7 @@
 
 
 def diff_columns(expected, actual):
-return _diff(expected, actual, ('name', 'whitelisted', 'condition', 
'replacewith'))
+return _diff(expected, actual, ('name', 'whitelisted', 'null_if'))
 
 
 def diff_tables(expected, actual):
@@ -88,7 +88,7 @@
 # Where cond is a valid SQL relational expression, column-name, wikiname, 
tablename are strings
 
 identifier = alphanums + _
-if_definition = if( + SkipTo(,)(condition) + , + Word(identifier) + 
, + Word(identifier) + )
+if_definition = if( + SkipTo(,)(null_if) + , + Word(identifier) + , 
+ Word(identifier) + )
 column_definition = (if_definition ^ Word(identifier)('expression')) + AS + 
Word(identifier)(name) + Optional(,)
 sql_definition = select + OneOrMore(column_definition)(columns) + \
  from + Word(identifier) + . + 
Word(identifier)(tablename) + \
@@ -103,8 +103,8 @@
 table = Table(viewname, {}, res.where if res.where else None, 
res.tablename)
 for tokens, start, end in column_definition.scanString(sql):
 table.add_column(Column(tokens.name,
-whitelisted=tokens.condition == '' and 
tokens.expression != 'NULL',
-condition=tokens.condition if tokens.condition 
else None))
+whitelisted=tokens.null_if == '' and 
tokens.expression != 'NULL',
+   

[MediaWiki-commits] [Gerrit] Rename some date model keys to be clearer - change (operations...labsdb-auditor)

2015-01-10 Thread Merlijn van Deen (Code Review)
Merlijn van Deen has submitted this change and it was merged.

Change subject: Rename some date model keys to be clearer
..


Rename some date model keys to be clearer

- Remove 'replacewith', since we will replace everything with only
  SQL 'NULL'
- 'condition' in the columns becomes 'null_if' since replacewith
  is no longer a thing, and 'null_if' makes it clearer that we
  are nulling columns if this is true, rather than false.
- 'where' in the table defintion becomes 'include_row_if', which
  makes it extremely clear what exactly it does.

Change-Id: I892f0ba4e6fa2db25696f1b7922f1e7c44630466
---
M auditor/models.py
M auditor/reports/viewdiffs.py
M greylisted.yaml
3 files changed, 103 insertions(+), 109 deletions(-)

Approvals:
  Merlijn van Deen: Verified; Looks good to me, approved



diff --git a/auditor/models.py b/auditor/models.py
index af4131c..5d5cd92 100644
--- a/auditor/models.py
+++ b/auditor/models.py
@@ -24,7 +24,7 @@
 
 A column that is potentially conditionally or unconditionally nulled
 
-def __init__(self, name, whitelisted=True, condition=None, 
replacewith=None):
+def __init__(self, name, whitelisted=True, null_if=None):
 
 A column in a table that can be whitelisted or conditionally nulled
 
@@ -32,23 +32,22 @@
 
 :param name: Name of this column
 :param whitelisted: True if the column is whitelisted
-:param condition: Conditions under which this column is replaced.
-  Specified as a string that is valid SQL expression
-:param replacewith: What to replace the column's value with if 
condition is matched
-If set to None with whitelisted = False, implies 
SQL None
+:param null_if: Conditions under which this column is nulled.
+Specified as a string that is valid SQL expression.
+If set to None  whitelisted=False, then nulled all 
the time
+
 :return:
 
 self.name = name
 self.whitelisted = whitelisted
-self.condition = condition
-self.replacewith = replacewith
+self.null_if = null_if
 
 
 class Table(object):
-def __init__(self, name, columns={}, where=None, table_name=None):
+def __init__(self, name, columns={}, include_row_if=None, table_name=None):
 self.name = name
 self.columns = columns
-self.where = where
+self.include_row_if = include_row_if
 self.table_name = table_name if table_name else name
 
 def add_column(self, column):
@@ -60,8 +59,8 @@
 Convert Table to a minimal dict from which it can be reconstituted
 
 tabledict = {}
-if self.where:
-tabledict['where'] = self.where
+if self.include_row_if:
+tabledict['include_row_if'] = self.include_row_if
 if all([c.whitelisted for c in self.columns.values()]):
 # Everything is whitelisted!
 tabledict['columns'] = [c.name for c in self.columns]
@@ -70,10 +69,8 @@
 for c in self.columns.values():
 columndict = {}
 columndict['whitelisted'] = c.whitelisted
-if c.condition:
-columndict['condition'] = c.condition
-if c.replacewith:
-columndict['replacewith'] = c.replacewith
+if c.null_if:
+columndict['null_if'] = c.null_if
 tabledict['columns'][c.name] = columndict
 if self.table_name != self.name:
 tabledict['table_name'] = self.table_name
@@ -81,7 +78,7 @@
 
 @classmethod
 def from_dict(cls, tablename, tabledata):
-table = cls(tablename, {}, tabledata.get('where', None), 
tabledata.get('table_name', None))
+table = cls(tablename, {}, tabledata.get('include_row_if', None), 
tabledata.get('table_name', None))
 if isinstance(tabledata['columns'], list):
 # Whitelisted table
 for colname in tabledata['columns']:
@@ -89,10 +86,7 @@
 else:
 # Greylisted table!
 for colname, coldata in tabledata['columns'].items():
-col = Column(colname,
- whitelisted=coldata.get('whitelisted'),
- condition=coldata.get('condition'),
- replacewith=coldata.get('replacewith'))
+col = Column(colname, coldata.get('whitelisted'), 
coldata.get('null_if'))
 table.add_column(col)
 return table
 
diff --git a/auditor/reports/viewdiffs.py b/auditor/reports/viewdiffs.py
index e9e91d0..6bd800c 100644
--- a/auditor/reports/viewdiffs.py
+++ b/auditor/reports/viewdiffs.py
@@ -33,11 +33,11 @@
 
 
 def diff_columns(expected, actual):
-return _diff(expected, actual, ('name', 'whitelisted', 'condition', 
'replacewith'))
+