napkin-spec-2.0.0
Safe HaskellNone
LanguageGHC2024

Napkin.Untyped.Ops

Synopsis

Documentation

(||.) :: SExp -> SExp -> SExp #

Concatenate two strings using ||

concatPortable :: [SExp] -> SExp #

"portable" concat for backends that do not have a native concat function.

avg :: SExp -> SExp #

Basic aggregations

max :: SExp -> SExp #

min :: SExp -> SExp #

sum :: SExp -> SExp #

countd :: SExp -> SExp #

Distinct count of expression

nullary :: Ref Function -> SExp #

Function calls and common control flow

raw :: Text -> SExp #

type SExp_ (a :: Symbol) = SExp #

case_ :: [(SExp, SExp)] -> SExp -> SExp #

caseMatch_ #

Arguments

:: SExp

column to check

-> [(SExp, SExp)]

check equal on left assume right

-> SExp

default

-> SExp 

if_ :: SExp -> SExp -> SExp -> SExp #

sign :: SExp -> SExp #

Basic arithmetic

(/.) :: SExp -> SExp -> SExp #

cast :: SExp -> Type -> SExp #

Type casts

(==.) :: SExp -> SExp -> SExp infix 4 #

Logical operators

(/=.) :: SExp -> SExp -> SExp infix 4 #

(>=.) :: SExp -> SExp -> SExp infix 4 #

(>.) :: SExp -> SExp -> SExp infix 4 #

(<=.) :: SExp -> SExp -> SExp infix 4 #

(<.) :: SExp -> SExp -> SExp infix 4 #

is :: SExp -> SExp -> SExp #

isNot :: SExp -> SExp -> SExp #

in_ :: SExp -> [SExp] -> SExp #

notIn :: SExp -> [SExp] -> SExp #

any_ :: SExp -> SExp #

all_ :: SExp -> SExp #

not :: SExp -> SExp #

(.&&.) :: SExp -> SExp -> SExp infixr 3 #

(.||.) :: SExp -> SExp -> SExp infixr 2 #

and :: [SExp] -> SExp #

or :: [SExp] -> SExp #

maxOf :: SExp -> SExp -> SExp #

minOf :: SExp -> SExp -> SExp #

hardCount :: SExp #

Higher level combinators and utilities

sum 1

valueIf :: SExp -> SExp -> SExp -> SExp #

Replace exp if its equal to val with replace.

nullifyUnless :: SExp -> SExp -> SExp #

Set to null unless predicate in first argument is true

nullifyIf :: SExp -> SExp -> SExp #

Set to null if predicate in first argument is true

nullifyIfEmpty :: SExp -> SExp #

Make empty string NULL.

deepApply :: (SExp -> SExp) -> SExp -> SExp #

Apply a function on Literals and Vars, recursing deep into function calls, etc.

isEmpty :: SExp -> SExp #

Common case of a string column possibly being empty either by being a blank string or properly being NULL.

notEmpty :: SExp -> SExp #

Opposite of isEmpty

countTrue :: SExp -> SExp #

(Agg) Count number of Trues in a boolean expression.

boolToInt :: SExp -> SExp #

True -> 1, False -> 0, NULL -> 0

coalesce :: [SExp] -> SExp #

returns the first non-null value in the arguments list.

scopeGeneric :: [(Ref Function, SExp)] -> SExp -> SExp -> SExp #

Apply a given predicate condition deeply within a given expression, such that the predicate is pushed inside all the aggregating function calls in SQL.

This makes it possible to have conditional aggregations without needing additional CTEs.

TODO. This is may have holes; we need a principled end-to-end review of this transformation. Perhaps even put it as a primitive into the SExp type.

data BackendFunctionMeta #

Constructors

BackendFunctionMeta 

Fields

Instances

Instances details
Generic BackendFunctionMeta # 
Instance details

Defined in Napkin.Untyped.Ops

Associated Types

type Rep BackendFunctionMeta 
Instance details

Defined in Napkin.Untyped.Ops

type Rep BackendFunctionMeta = D1 ('MetaData "BackendFunctionMeta" "Napkin.Untyped.Ops" "napkin-spec-2.0.0-7NH5JHRFo7V8BQP5NCfMo1" 'False) (C1 ('MetaCons "BackendFunctionMeta" 'PrefixI 'True) (S1 ('MetaSel ('Just "aggs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(Ref Function, SExp)]) :*: S1 ('MetaSel ('Just "analytics") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Ref Function])))
Show BackendFunctionMeta # 
Instance details

Defined in Napkin.Untyped.Ops

Eq BackendFunctionMeta # 
Instance details

Defined in Napkin.Untyped.Ops

type Rep BackendFunctionMeta # 
Instance details

Defined in Napkin.Untyped.Ops

type Rep BackendFunctionMeta = D1 ('MetaData "BackendFunctionMeta" "Napkin.Untyped.Ops" "napkin-spec-2.0.0-7NH5JHRFo7V8BQP5NCfMo1" 'False) (C1 ('MetaCons "BackendFunctionMeta" 'PrefixI 'True) (S1 ('MetaSel ('Just "aggs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(Ref Function, SExp)]) :*: S1 ('MetaSel ('Just "analytics") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Ref Function])))

inferAggGeneric :: BackendFunctionMeta -> SExp -> AggLevel #

Infer aggregation level of an expression.

TODO: ExternRaw and NativeExpr cant be inferred at the moment; needs more info inside the SExp if this becomes a problem.

unitBoundaryGeneric :: BackendFunctionMeta -> SExp -> [SExp] #

Explore expression's insides to pull out top level Unit expressions within its branches, but no deeper in each branch.

Originally created to help with common expression caching - since you can commonolize unit-level expressions without any side-effect.

Orphan instances

Num SExp # 
Instance details

Methods

(+) :: SExp -> SExp -> SExp #

(-) :: SExp -> SExp -> SExp #

(*) :: SExp -> SExp -> SExp #

negate :: SExp -> SExp #

abs :: SExp -> SExp #

signum :: SExp -> SExp #

fromInteger :: Integer -> SExp #

Fractional SExp # 
Instance details

Methods

(/) :: SExp -> SExp -> SExp #

recip :: SExp -> SExp #

fromRational :: Rational -> SExp #