Skip to content

Commit

Permalink
Backend/feat:added-few-operator-in-clickhouse
Browse files Browse the repository at this point in the history
  • Loading branch information
Akhilesh Bhadauriya committed Dec 2, 2024
1 parent 9cc2912 commit b66fe29
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <> ")"
Expand Down
18 changes: 18 additions & 0 deletions lib/mobility-core/src/Kernel/Storage/ClickhouseV2/Operators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,22 @@ 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 ==..

0 comments on commit b66fe29

Please sign in to comment.