Skip to content

Commit

Permalink
fix bugs on ConstraintFeaturizer
Browse files Browse the repository at this point in the history
When generating relaxed sql, the operation should be flipped to
keep the sql right when non-symmetric operation is used in DC.
  • Loading branch information
zaqthss committed Apr 4, 2019
1 parent 6db22a6 commit 57a4187
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
13 changes: 13 additions & 0 deletions dcparser/constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ def is_symmetric(operation):
return False


def get_flip_operation(operation):
if operation == '<=':
return '>='
elif operation == '>=':
return '<='
elif operation == '<':
return '>'
elif operation == '>':
return '<'
else:
return operation


def contains_operation(string):
"""
Method to check if a given string contains one of the operation signs.
Expand Down
6 changes: 5 additions & 1 deletion repair/featurize/constraintfeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .featurizer import Featurizer
from dataset import AuxTables
from dcparser.constraint import is_symmetric
from dcparser.constraint import is_symmetric, get_flip_operation

# unary_template is used for constraints where the current predicate
# used for detecting violations in pos_values have a reference to only
Expand Down Expand Up @@ -111,6 +111,10 @@ def relax_binary_predicate(self, predicate, rel_idx):
"""
attr = predicate.components[rel_idx][1]
op = predicate.operation
# the latter one should flip the operation,
# if t3.rv_val is always on the left side in query template
if rel_idx == 1:
op = get_flip_operation(op)
const = '{}."{}"'.format(
predicate.components[1-rel_idx][0],
predicate.components[1-rel_idx][1])
Expand Down

0 comments on commit 57a4187

Please sign in to comment.