Skip to main content
Version: Next

'db' Dialect

Imperative Database Dialect

Imperative database dialect, defining abstract/non-trivial types and high-level operations which more closely resemble SQL semantics, e.g. by supporting NULL values.

Supported types are integers (i32/i64), floats, bools (i1), Date, Timestamp, Interval, Decimal, Char (fixed-size buffers), and String (variable-length buffers). Nullable types are supported using nullable<...>; plain NULL values can be represented using nullable<none>.

Operations

db.add (::lingodb::compiler::dialect::db::AddOp)

Add int/float/decimal

Syntax:

operation ::= `db.add` $left `:` type($left) `,` $right `:` type($right) attr-dict

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, DB_NeedsNullWrap, DB_SupportsInvalidValues, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
leftany type or nullable
rightany type or nullable

Results:

ResultDescription
resultany type

db.and (::lingodb::compiler::dialect::db::AndOp)

Logical And

Syntax:

operation ::= `db.and` $vals `:` type($vals) attr-dict

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), SupportsNullabilityChange

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
valsvariadic of 1-bit signless integer or nullable

Results:

ResultDescription
res1-bit signless integer or nullable

db.arrow.append (::lingodb::compiler::dialect::db::AppendArrowOp)

Append value to arrow array

Syntax:

operation ::= `db.arrow.append` $builder `,` $value `->` type($value) attr-dict

Operands:

OperandDescription
builderrepresents an anonymous Apache Arrow builder (building a chunked array), without knowledge of the type stored by it
valueany type or nullable

db.arrow.load (::lingodb::compiler::dialect::db::LoadArrowOp)

Loads value from arrow array

Syntax:

operation ::= `db.arrow.load` $array `,` $offset `->` type($res) attr-dict

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
arrayrepresents an anonymous Apache Arrow array, without knowledge of the type stored by it
offsetindex

Results:

ResultDescription
resany type or nullable

db.as_nullable (::lingodb::compiler::dialect::db::AsNullableOp)

Convert to nullable type

Syntax:

operation ::= `db.as_nullable` $val `:` type($val) ( `,` $null^ )?  `->` type($res) attr-dict

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
valany type
null1-bit signless integer

Results:

ResultDescription
resnullable

db.between (::lingodb::compiler::dialect::db::BetweenOp)

Whether value is between lower and upper

Syntax:

operation ::= `db.between` $val `:` type ($val) `between` $lower `:` type($lower) `,` $upper `:` type($upper) `,` `lowerInclusive` `:` $lowerInclusive `,` `upperInclusive` `:` $upperInclusive attr-dict

Determine whether a value is in a given range. This is preferred over (and also internally derived from) two comparisons to simplify optimizations depending on information about a value range.

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, DB_MaySupportInvalidValues, DB_NeedsNullWrap, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), SupportsNullabilityChange

Effects: MemoryEffects::Effect{}

Attributes:

AttributeMLIR TypeDescription
lowerInclusive::mlir::IntegerAttr1-bit signless integer attribute
upperInclusive::mlir::IntegerAttr1-bit signless integer attribute

Operands:

OperandDescription
valany type or nullable
lowerany type or nullable
upperany type or nullable

Results:

ResultDescription
res1-bit signless integer or nullable

db.cast (::lingodb::compiler::dialect::db::CastOp)

Cast value to different type

Syntax:

operation ::= `db.cast` $val `:` type($val) `->` type($res) attr-dict

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, DB_MaySupportInvalidValues, DB_NeedsNullWrap, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
valany type or nullable

Results:

ResultDescription
resany type or nullable

db.compare (::lingodb::compiler::dialect::db::CmpOp)

Compare int/Decimal/String

Syntax:

operation ::= `db.compare` $predicate $left `:` type($left) `,` $right `:` type($right) attr-dict

Traits: AlwaysSpeculatableImplTrait

Interfaces: CmpOpInterface, ConditionallySpeculatable, DB_MaySupportInvalidValues, DB_NeedsNullWrap, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), SupportsNullabilityChange

Effects: MemoryEffects::Effect{}

Attributes:

AttributeMLIR TypeDescription
predicate::lingodb::compiler::dialect::db::DBCmpPredicateAttr
allowed 64-bit signless integer cases: 0, 1, 2, 3, 4, 5, 6
  • eq: Enum case: eq (eq)
  • neq: Enum case: neq (neq)
  • lt: Enum case: lt (lt)
  • lte: Enum case: lte (lte)
  • gt: Enum case: gt (gt)
  • gte: Enum case: gte (gte)

Operands:

OperandDescription
leftany type or nullable
rightany type or nullable

Results:

ResultDescription
res1-bit signless integer or nullable

db.constant (::lingodb::compiler::dialect::db::ConstantOp)

Create constant value

Syntax:

operation ::= `db.constant` `(` $value `)` `:` type($result) attr-dict

Traits: AlwaysSpeculatableImplTrait, ConstantLike

Interfaces: ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Attributes:

AttributeMLIR TypeDescription
value::mlir::Attributeany attribute

Results:

ResultDescription
resultany type

db.create_dict (::lingodb::compiler::dialect::db::CreateDictOp)

Create dict

Syntax:

operation ::= `db.create_dict` $cmpKeyFn `->` type($dict) attr-dict

Attributes:

AttributeMLIR TypeDescription
cmpKeyFn::mlir::SymbolRefAttrsymbol reference attribute

Results:

ResultDescription
dict

db.create_list (::lingodb::compiler::dialect::db::CreateListOp)

Create list

Syntax:

operation ::= `db.create_list` type($list) attr-dict

Results:

ResultDescription
list

db.derive_truth (::lingodb::compiler::dialect::db::DeriveTruth)

Get whether a value is true-ish

Syntax:

operation ::= `db.derive_truth` $val `:` type($val) attr-dict

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
valany type

Results:

ResultDescription
res1-bit signless integer

db.dict_contains (::lingodb::compiler::dialect::db::DictContainsOp)

Check whether dict contains key

Syntax:

operation ::= `db.dict_contains` $dict `:` type($dict) `[` $key `:` type($key) `->` $hash `]` attr-dict

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
dict
keyany type
hashindex

Results:

ResultDescription
contains1-bit signless integer

db.dict_get (::lingodb::compiler::dialect::db::DictGetOp)

Get value from dict

Syntax:

operation ::= `db.dict_get` $dict `:` type($dict) `[` $key `:` type($key) `->` $hash`]` `:` type($value) attr-dict

Operands:

OperandDescription
dict
keyany type
hashindex

Results:

ResultDescription
valueany type

db.dict_get_iter (::lingodb::compiler::dialect::db::DictGetIter)

Get iterator over dict

Syntax:

operation ::= `db.dict_get_iter` $dict `:` type($dict) `->` type($iter) attr-dict

Operands:

OperandDescription
dict

Results:

ResultDescription
iterdict iterator

db.dict_iter_get_key (::lingodb::compiler::dialect::db::DictIterGetKey)

Get key from dict iterator

Syntax:

operation ::= `db.dict_iter_get_key` $iter `:` type($iter) `->` type($key) attr-dict

Operands:

OperandDescription
iterdict iterator

Results:

ResultDescription
keyany type

db.dict_iter_get_value (::lingodb::compiler::dialect::db::DictIterGetValue)

Get value from dict iterator

Syntax:

operation ::= `db.dict_iter_get_value` $iter `:` type($iter) `->` type($value) attr-dict

Operands:

OperandDescription
iterdict iterator

Results:

ResultDescription
valueany type

db.dict_iter_next (::lingodb::compiler::dialect::db::DictIterNext)

Move to next element in dict iterator

Syntax:

operation ::= `db.dict_iter_next` $iter `:` type($iter) attr-dict

Operands:

OperandDescription
iterdict iterator

db.dict_iter_valid (::lingodb::compiler::dialect::db::DictIterValid)

Check whether dict iterator is valid

Syntax:

operation ::= `db.dict_iter_valid` $iter `:` type($iter) attr-dict

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
iterdict iterator

Results:

ResultDescription
isValid1-bit signless integer

db.dict_length (::lingodb::compiler::dialect::db::DictLengthOp)

Get length of dict

Syntax:

operation ::= `db.dict_length` $dict `:` type($dict) attr-dict

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
dict

Results:

ResultDescription
lengthindex

db.dict_set (::lingodb::compiler::dialect::db::DictSetOp)

Set value in dict

Syntax:

operation ::= `db.dict_set` $dict `:` type($dict) `[` $key `:` type($key)  `->` $hash `]` `=` $value `:` type($value) attr-dict

Operands:

OperandDescription
dict
keyany type
hashindex
valueany type

db.div (::lingodb::compiler::dialect::db::DivOp)

Divide int/float/decimal

Syntax:

operation ::= `db.div` $left `:` type($left) `,` $right `:` type($right) attr-dict

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, DB_NeedsNullWrap, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
leftany type or nullable
rightany type or nullable

Results:

ResultDescription
resultany type

db.hash (::lingodb::compiler::dialect::db::Hash)

Compute hash

Syntax:

operation ::= `db.hash` $val `:` type($val) attr-dict

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
valvariadic of any type

Results:

ResultDescription
hashindex

db.isnull (::lingodb::compiler::dialect::db::IsNullOp)

Indicate whether a nullable value is null

Syntax:

operation ::= `db.isnull` $val `:` type($val) attr-dict

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
valnullable

Results:

ResultDescription
result1-bit signless integer

db.list_append (::lingodb::compiler::dialect::db::ListAppendOp)

Append element to list

Syntax:

operation ::= `db.list_append` $list `:` type($list)  `,` $element `:` type($element) attr-dict

Operands:

OperandDescription
list
elementany type

db.list_get (::lingodb::compiler::dialect::db::ListGetOp)

Get element from list

Syntax:

operation ::= `db.list_get` $list `:` type($list) `[` $index `]` `:` type($element) attr-dict

Operands:

OperandDescription
list
indexindex

Results:

ResultDescription
elementany type

db.list_length (::lingodb::compiler::dialect::db::ListLengthOp)

Get length of list

Syntax:

operation ::= `db.list_length` $list `:` type($list) attr-dict

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
list

Results:

ResultDescription
lengthindex

db.list_set (::lingodb::compiler::dialect::db::ListSetOp)

Set element in list

Syntax:

operation ::= `db.list_set` $list `:` type($list) `[` $index `]` `=` $element `:` type($element) attr-dict

Operands:

OperandDescription
list
indexindex
elementany type

db.mod (::lingodb::compiler::dialect::db::ModOp)

Remainder of int/float/decimal

Syntax:

operation ::= `db.mod` $left `:` type($left) `,` $right `:` type($right) attr-dict

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, DB_NeedsNullWrap, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
leftany type or nullable
rightany type or nullable

Results:

ResultDescription
resultany type

db.mul (::lingodb::compiler::dialect::db::MulOp)

Multiply int/float/decimal

Syntax:

operation ::= `db.mul` $left `:` type($left) `,` $right `:` type($right) attr-dict

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, DB_NeedsNullWrap, DB_SupportsInvalidValues, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
leftany type or nullable
rightany type or nullable

Results:

ResultDescription
resultany type

db.not (::lingodb::compiler::dialect::db::NotOp)

Logical Not

Syntax:

operation ::= `db.not` $val `:` type($val) attr-dict

Traits: AlwaysSpeculatableImplTrait, SameOperandsAndResultType

Interfaces: ConditionallySpeculatable, DB_NeedsNullWrap, DB_SupportsInvalidValues, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
val1-bit signless integer or nullable

Results:

ResultDescription
res1-bit signless integer or nullable

db.null (::lingodb::compiler::dialect::db::NullOp)

Create null value

Syntax:

operation ::= `db.null` `:` type($res) attr-dict

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Results:

ResultDescription
resnullable

db.nullable_get_val (::lingodb::compiler::dialect::db::NullableGetVal)

Get value of nullable type

Syntax:

operation ::= `db.nullable_get_val` $val `:` type($val)  attr-dict

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
valnullable

Results:

ResultDescription
resany type

db.oneof (::lingodb::compiler::dialect::db::OneOfOp)

Whether val is included in vals

Syntax:

operation ::= `db.oneof` $val `:` type ($val) `?` $vals `:` type ($vals) attr-dict

Determine whether val is included in vals; similar to IN in SQL.

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, DB_NeedsNullWrap, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), SupportsNullabilityChange

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
valany type or nullable
valsvariadic of any type or nullable

Results:

ResultDescription
res1-bit signless integer or nullable

db.or (::lingodb::compiler::dialect::db::OrOp)

Logical Or

Syntax:

operation ::= `db.or` $vals `:` type($vals) attr-dict

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), SupportsNullabilityChange

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
valsvariadic of any type

Results:

ResultDescription
res1-bit signless integer or nullable

db.runtime_call (::lingodb::compiler::dialect::db::RuntimeCall)

Call runtime function

Syntax:

operation ::= `db.runtime_call` $fn  `(` $args `)` `:`  functional-type($args,$res)  attr-dict

Interfaces: DB_MayNeedNullWrap, DB_MaySupportInvalidValues

Attributes:

AttributeMLIR TypeDescription
fn::mlir::StringAttrstring attribute

Operands:

OperandDescription
argsvariadic of any type

Results:

ResultDescription
resany type

db.sort_compare (::lingodb::compiler::dialect::db::SortCompare)

Get whether a value is true-ish

Syntax:

operation ::= `db.sort_compare` $left `:` type($left) `,` $right `:` type($right) attr-dict

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
leftany type
rightany type

Results:

ResultDescription
res8-bit signless integer

db.sub (::lingodb::compiler::dialect::db::SubOp)

Subtract int/float/decimal

Syntax:

operation ::= `db.sub` $left `:` type($left) `,` $right `:` type($right) attr-dict

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, DB_NeedsNullWrap, DB_SupportsInvalidValues, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
leftany type or nullable
rightany type or nullable

Results:

ResultDescription
resultany type

Types

CharType

char

Syntax:

!db.char<
unsigned # len
>

Fixed-size array of chars.

Parameters:

ParameterC++ typeDescription
lenunsigned

DateType

date

Syntax:

!db.date<
DateUnitAttr # unit
>

Parameters:

ParameterC++ typeDescription
unitDateUnitAttr

DecimalType

decimal

Syntax:

!db.decimal<
int, # p
int # s
>

Decimal type with p digits in total and s digits after the decimal point.

Parameters:

ParameterC++ typeDescription
pint
sint

IntervalType

interval

Syntax:

!db.interval<
IntervalUnitAttr # unit
>

Parameters:

ParameterC++ typeDescription
unitIntervalUnitAttr

StringType

string

Syntax: !db.string

Variable-length string.

TimestampType

timestamp

Syntax:

!db.timestamp<
TimeUnitAttr # unit
>

Parameters:

ParameterC++ typeDescription
unitTimeUnitAttr

DictIterType

dict iterator

Syntax:

!db.dict_iter<
mlir::Type, # keyType
mlir::Type # valueType
>

Iterator over a dict, yielding key-value pairs.

Parameters:

ParameterC++ typeDescription
keyTypemlir::Type
valueTypemlir::Type

DictType

Syntax:

!db.dict<
mlir::Type, # keyType
mlir::Type # valueType
>

Parameters:

ParameterC++ typeDescription
keyTypemlir::Type
valueTypemlir::Type

ListType

Syntax:

!db.list<
mlir::Type # elementType
>

Parameters:

ParameterC++ typeDescription
elementTypemlir::Type

NullableType

nullable

Syntax:

!db.nullable<
mlir::Type # type
>

Parameters:

ParameterC++ typeDescription
typemlir::Type

Enums

DBCmpPredicate

allowed 64-bit signless integer cases: 0, 1, 2, 3, 4, 5, 6

Cases:

SymbolValueString
eq0eq
neq1neq
lt2lt
lte3lte
gt4gt
gte5gte
isa6isa

DateUnitAttr

allowed 64-bit signless integer cases: 0, 1

Cases:

SymbolValueString
day0day
millisecond1millisecond

IntervalUnitAttr

allowed 64-bit signless integer cases: 0, 1

Cases:

SymbolValueString
months0months
daytime1daytime

TimeUnitAttr

allowed 64-bit signless integer cases: 0, 1, 2, 3

Cases:

SymbolValueString
second0second
millisecond1millisecond
microsecond2microsecond
nanosecond3nanosecond