Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend/feat:added-few-operator-in-clickhouse #699

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 30 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,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
Copy link
Contributor

@roman-bodavskiy roman-bodavskiy Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls add precedence the same as for corresponding Clause operators


infix 4 ==..

infix 3 &&..

infix 3 ||..

infix 4 >..

infix 4 <..

infix 4 >=..

infix 4 <=..