row condition, fix table literal
This commit is contained in:
parent
062821039a
commit
d33d21e1dc
|
@ -115,6 +115,7 @@ impl BlockBuilder {
|
|||
| Literal::Binary(_)
|
||||
| Literal::Block(_)
|
||||
| Literal::Closure(_)
|
||||
| Literal::RowCondition(_)
|
||||
| Literal::List { capacity: _ }
|
||||
| Literal::Record { capacity: _ }
|
||||
| Literal::Filepath {
|
||||
|
|
|
@ -146,7 +146,7 @@ pub(crate) fn compile_expression(
|
|||
compile_external_call(working_set, builder, head, args, redirect_modes, out_reg)
|
||||
}
|
||||
Expr::Operator(_) => Err(unexpected("Operator")),
|
||||
Expr::RowCondition(_) => Err(todo("RowCondition")),
|
||||
Expr::RowCondition(block_id) => lit(builder, Literal::RowCondition(*block_id)),
|
||||
Expr::UnaryNot(subexpr) => {
|
||||
drop_input(builder)?;
|
||||
compile_expression(
|
||||
|
@ -286,13 +286,20 @@ pub(crate) fn compile_expression(
|
|||
)?;
|
||||
builder.push(
|
||||
Instruction::RecordInsert {
|
||||
src_dst: out_reg,
|
||||
src_dst: row_reg,
|
||||
key: column_reg,
|
||||
val: item_reg,
|
||||
}
|
||||
.into_spanned(item.span),
|
||||
)?;
|
||||
}
|
||||
builder.push(
|
||||
Instruction::ListPush {
|
||||
src_dst: out_reg,
|
||||
item: row_reg,
|
||||
}
|
||||
.into_spanned(expr.span),
|
||||
)?;
|
||||
}
|
||||
|
||||
// Free the column registers, since they aren't needed anymore
|
||||
|
|
|
@ -586,7 +586,7 @@ fn literal_value(
|
|||
Literal::Int(i) => Value::int(*i, span),
|
||||
Literal::Float(f) => Value::float(*f, span),
|
||||
Literal::Binary(bin) => Value::binary(&ctx.data[*bin], span),
|
||||
Literal::Block(block_id) => Value::closure(
|
||||
Literal::Block(block_id) | Literal::RowCondition(block_id) => Value::closure(
|
||||
Closure {
|
||||
block_id: *block_id,
|
||||
captures: vec![],
|
||||
|
|
|
@ -3272,6 +3272,8 @@ pub fn parse_row_condition(working_set: &mut StateWorkingSet, spans: &[Span]) ->
|
|||
default_value: None,
|
||||
});
|
||||
|
||||
compile_block(working_set, &mut block);
|
||||
|
||||
working_set.add_block(Arc::new(block))
|
||||
}
|
||||
};
|
||||
|
|
|
@ -279,6 +279,7 @@ impl<'a> fmt::Display for FmtLiteral<'a> {
|
|||
Literal::Binary(b) => write!(f, "binary({})", FmtData(self.data, *b)),
|
||||
Literal::Block(id) => write!(f, "block({id})"),
|
||||
Literal::Closure(id) => write!(f, "closure({id})"),
|
||||
Literal::RowCondition(id) => write!(f, "row_condition({id})"),
|
||||
Literal::Range {
|
||||
start,
|
||||
step,
|
||||
|
|
|
@ -204,6 +204,7 @@ pub enum Literal {
|
|||
Binary(DataSlice),
|
||||
Block(BlockId),
|
||||
Closure(BlockId),
|
||||
RowCondition(BlockId),
|
||||
Range {
|
||||
start: RegId,
|
||||
step: RegId,
|
||||
|
|
|
@ -139,6 +139,11 @@ fn literal_record() {
|
|||
test_eval("{foo: bar, baz: quux}", Matches("foo.*bar.*baz.*quux"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn literal_table() {
|
||||
test_eval("[[a b]; [1 2] [3 4]]", Matches("a.*b.*1.*2.*3.*4"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn literal_string() {
|
||||
test_eval(r#""foobar""#, Eq("foobar"))
|
||||
|
@ -430,3 +435,11 @@ fn try_catch_with_non_literal_closure() {
|
|||
Eq("foobar"),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn row_condition() {
|
||||
test_eval(
|
||||
"[[a b]; [1 2] [3 4]] | where a < 3 | to nuon",
|
||||
Eq("[[a, b]; [1, 2]]"),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user