From 75e17ec02b0cf53e4c89a8d969a3c3931ae9c395 Mon Sep 17 00:00:00 2001 From: piotrkosecki Date: Mon, 31 Jan 2022 17:19:15 +0100 Subject: [PATCH] fixing sorting i count distinct aggregation --- .../conseil/common/generic/chain/DataTypes.scala | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/conseil-common/src/main/scala/tech/cryptonomic/conseil/common/generic/chain/DataTypes.scala b/conseil-common/src/main/scala/tech/cryptonomic/conseil/common/generic/chain/DataTypes.scala index 36c949248..f0170e4cd 100644 --- a/conseil-common/src/main/scala/tech/cryptonomic/conseil/common/generic/chain/DataTypes.scala +++ b/conseil-common/src/main/scala/tech/cryptonomic/conseil/common/generic/chain/DataTypes.scala @@ -243,13 +243,25 @@ object DataTypes { val in, between, like, lt, gt, eq, startsWith, endsWith, before, after, isnull = Value } + /** Helps with changing camel case to snake case */ + object StringHelper { + + /** Helper regex */ + private val separatees = "[a-z](?=[A-Z])|[0-9](?=[a-zA-Z])|[A-Z](?=[A-Z][a-z])|[a-zA-Z](?=[0-9])".r + + /** Helper method for converting camel case to snake case */ + def camel2Snake(s: String): String = separatees.replaceAllIn(s, _.group(0) + '_').toLowerCase + } + + /** Enumeration of aggregation functions */ object AggregationType extends Enumeration { + /** Helper method for extracting prefixes needed for SQL */ - def prefixes: List[String] = values.toList.map(_.toString + "_") + def prefixes: List[String] = values.toList.map(x => StringHelper.camel2Snake(x.toString) + "_") type AggregationType = Value - val sum, count, max, min, avg, countDistinct = Value + val countDistinct, sum, count, max, min, avg = Value } /** Enumeration of aggregation functions */