From 7f422091872c341bf226e5d37ffeb41786068709 Mon Sep 17 00:00:00 2001 From: Akhilesh Bhadauriya Date: Mon, 2 Dec 2024 18:33:37 +0530 Subject: [PATCH] Backend/feat:added-few-operator-in-clickhouse --- .../Storage/ClickhouseV2/Internal/Types.hs | 12 ++++++++ .../Kernel/Storage/ClickhouseV2/Operators.hs | 30 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/lib/mobility-core/src/Kernel/Storage/ClickhouseV2/Internal/Types.hs b/lib/mobility-core/src/Kernel/Storage/ClickhouseV2/Internal/Types.hs index cdde93719..edd4d7bf3 100644 --- a/lib/mobility-core/src/Kernel/Storage/ClickhouseV2/Internal/Types.hs +++ b/lib/mobility-core/src/Kernel/Storage/ClickhouseV2/Internal/Types.hs @@ -43,6 +43,12 @@ data Column (a :: IsAggregated) t v where ValColumn :: (ClickhouseTable t, ClickhouseValue v) => v -> Column a t v If :: (ClickhouseTable t, ClickhouseValue v) => Column a t Bool -> Column a t v -> Column a t v -> Column a t v EqColumn :: (ClickhouseTable t, ClickhouseValue v) => Column a t v -> Column a t v -> Column a t Bool + AndColumn :: (ClickhouseTable t, ClickhouseValue Bool) => Column a t Bool -> Column a t Bool -> Column a t Bool + OrColumn :: (ClickhouseTable t, ClickhouseValue Bool) => Column a t Bool -> Column a t Bool -> Column a t Bool + GreaterOrEqual :: (ClickhouseTable t, ClickhouseValue v) => Column a t v -> Column a t v -> Column a t Bool + LessOrEqual :: (ClickhouseTable t, ClickhouseValue v) => Column a t v -> Column a t v -> Column a t Bool + Greater :: (ClickhouseTable t, ClickhouseValue v) => Column a t v -> Column a t v -> Column a t Bool + Less :: (ClickhouseTable t, ClickhouseValue v) => Column a t v -> Column a t v -> Column a t Bool mkTableColumns :: ClickhouseTable t => FieldModifications t -> Columns 'NOT_AGG t mkTableColumns = mapTable Column @@ -160,6 +166,12 @@ showColumn (TimeDiff column1 column2) = "timeDiff" <> addBrackets' (showColumn c showColumn (ValColumn v) = valToString . toClickhouseValue $ v showColumn (If cond v1 v2) = "if" <> addBrackets' (showColumn cond <> ", " <> showColumn v1 <> ", " <> showColumn v2) showColumn (EqColumn column1 column2) = addBrackets' $ showColumn column1 <> "=" <> showColumn column2 +showColumn (AndColumn column1 column2) = addBrackets' $ showColumn column1 <> " AND " <> showColumn column2 +showColumn (OrColumn column1 column2) = addBrackets' $ showColumn column1 <> " OR " <> showColumn column2 +showColumn (GreaterOrEqual column1 column2) = addBrackets' $ showColumn column1 <> ">=" <> showColumn column2 +showColumn (LessOrEqual column1 column2) = addBrackets' $ showColumn column1 <> "<=" <> showColumn column2 +showColumn (Greater column1 column2) = addBrackets' $ showColumn column1 <> ">" <> showColumn column2 +showColumn (Less column1 column2) = addBrackets' $ showColumn column1 <> "<" <> showColumn column2 addBrackets' :: String -> String addBrackets' rq = "(" <> rq <> ")" diff --git a/lib/mobility-core/src/Kernel/Storage/ClickhouseV2/Operators.hs b/lib/mobility-core/src/Kernel/Storage/ClickhouseV2/Operators.hs index be633250b..aa38c14e6 100644 --- a/lib/mobility-core/src/Kernel/Storage/ClickhouseV2/Operators.hs +++ b/lib/mobility-core/src/Kernel/Storage/ClickhouseV2/Operators.hs @@ -157,4 +157,34 @@ if_ = If (==..) :: (ClickhouseTable t, ClickhouseValue v) => Column a t v -> Column a t v -> Column a t Bool (==..) = EqColumn +(&&..) :: ClickhouseTable t => Column a t Bool -> Column a t Bool -> Column a t Bool +(&&..) = AndColumn + +(||..) :: ClickhouseTable t => Column a t Bool -> Column a t Bool -> Column a t Bool +(||..) = OrColumn + +(>..) :: (ClickhouseTable t, ClickhouseValue v) => Column a t v -> Column a t v -> Column a t Bool +(>..) = Greater + +(<..) :: (ClickhouseTable t, ClickhouseValue v) => Column a t v -> Column a t v -> Column a t Bool +(<..) = Less + +(>=..) :: (ClickhouseTable t, ClickhouseValue v) => Column a t v -> Column a t v -> Column a t Bool +(>=..) = GreaterOrEqual + +(<=..) :: (ClickhouseTable t, ClickhouseValue v) => Column a t v -> Column a t v -> Column a t Bool +(<=..) = LessOrEqual + infix 4 ==.. + +infix 3 &&.. + +infix 3 ||.. + +infix 4 >.. + +infix 4 <.. + +infix 4 >=.. + +infix 4 <=..