Skip to content

Commit

Permalink
Merge pull request DIRACGrid#7772 from chrisburr/agg-date
Browse files Browse the repository at this point in the history
feat: Support aggregating by date in MySQL.getCounters
  • Loading branch information
fstagni authored Aug 30, 2024
2 parents cfe7863 + d940f15 commit 9554fff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/DIRAC/Core/Utilities/MySQL.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def _checkFields(inFields, inValues):
return S_OK()


def _quotedList(fieldList=None):
def _quotedList(fieldList=None, allowDate=False):
"""
Quote a list of MySQL Field Names with "`"
Return a comma separated list of quoted Field Names
Expand All @@ -192,7 +192,11 @@ def _quotedList(fieldList=None):
quotedFields = []
try:
for field in fieldList:
quotedFields.append(f"`{field.replace('`', '')}`")
if allowDate and field.startswith("date(") and field.endswith(")"):
field = field[len("date(") : -len(")")]
quotedFields.append(f"date(`{field.replace('`', '')}`)")
else:
quotedFields.append(f"`{field.replace('`', '')}`")
except Exception:
return None
if not quotedFields:
Expand Down Expand Up @@ -1115,7 +1119,7 @@ def getCounters(
# self.log.debug('getCounters:', error)
return S_ERROR(DErrno.EMYSQL, error)

attrNames = _quotedList(attrList)
attrNames = _quotedList(attrList, allowDate=True)
if attrNames is None:
error = "Invalid updateFields argument"
# self.log.debug('getCounters:', error)
Expand Down
2 changes: 1 addition & 1 deletion src/DIRAC/TransformationSystem/DB/TransformationDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ def getTransformationFilesCount(self, transName, field, selection=None, connecti
connection = res["Value"]["Connection"]
transID = res["Value"]["TransformationID"]
selection["TransformationID"] = transID
if field not in self.TRANSFILEPARAMS:
if field not in self.TRANSFILEPARAMS + ["date(LastUpdate)", "date(InsertedTime)"]:
return S_ERROR("Supplied field not in TransformationFiles table")
res = self.getCounters("TransformationFiles", ["TransformationID", field], selection)
if not res["OK"]:
Expand Down

0 comments on commit 9554fff

Please sign in to comment.