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)

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

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_NeedsNullWrap, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

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)

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.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.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
valany 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.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)

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)

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

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