napkin-0.5.14
Copyright(c) Soostone Inc 2020
LicenseAllRightsReserved
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe-Inferred
LanguageGHC2021

Napkin.Untyped.Ops

Description

 
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

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 Lits 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

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

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 #