vortex_layout/layouts/row_idx/
expr.rs1use std::fmt::Formatter;
5
6use vortex_array::ArrayRef;
7use vortex_array::expr::Arity;
8use vortex_array::expr::ChildName;
9use vortex_array::expr::EmptyOptions;
10use vortex_array::expr::ExecutionArgs;
11use vortex_array::expr::ExprId;
12use vortex_array::expr::Expression;
13use vortex_array::expr::VTable;
14use vortex_array::expr::VTableExt;
15use vortex_dtype::DType;
16use vortex_dtype::Nullability;
17use vortex_dtype::PType;
18use vortex_error::VortexResult;
19use vortex_error::vortex_bail;
20
21pub struct RowIdx;
22
23impl VTable for RowIdx {
24 type Options = EmptyOptions;
25
26 fn id(&self) -> ExprId {
27 ExprId::from("vortex.row_idx")
28 }
29
30 fn arity(&self, _options: &Self::Options) -> Arity {
31 Arity::Exact(0)
32 }
33
34 fn child_name(&self, _instance: &Self::Options, _child_idx: usize) -> ChildName {
35 unreachable!()
36 }
37
38 fn fmt_sql(
39 &self,
40 _options: &Self::Options,
41 _expr: &Expression,
42 f: &mut Formatter<'_>,
43 ) -> std::fmt::Result {
44 write!(f, "#row_idx")
45 }
46
47 fn return_dtype(&self, _options: &Self::Options, _arg_dtypes: &[DType]) -> VortexResult<DType> {
48 Ok(DType::Primitive(PType::U64, Nullability::NonNullable))
49 }
50
51 fn execute(&self, _options: &Self::Options, _args: ExecutionArgs) -> VortexResult<ArrayRef> {
52 vortex_bail!(
53 "RowIdxExpr should not be executed directly, use it in the context of a Vortex scan and it will be substituted for a row index array"
54 );
55 }
56}
57
58pub fn row_idx() -> Expression {
59 RowIdx.new_expr(EmptyOptions, [])
60}