From 39c6cfae5f7e7a30bb48f27877692f0f9dda5953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannis=20Christopher=20K=C3=B6hl?= Date: Thu, 12 Dec 2024 13:40:56 +0100 Subject: [PATCH] Validate legacy expressions when splitting for predicate pushdown --- changelog/next/bug-fixes/4861--fix-export-where.md | 3 +++ libtenzir/src/tql2/ast.cpp | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 changelog/next/bug-fixes/4861--fix-export-where.md diff --git a/changelog/next/bug-fixes/4861--fix-export-where.md b/changelog/next/bug-fixes/4861--fix-export-where.md new file mode 100644 index 00000000000..74a43f0beb8 --- /dev/null +++ b/changelog/next/bug-fixes/4861--fix-export-where.md @@ -0,0 +1,3 @@ +Pipelines that begin with `export | where` followed by an expression that does +not depend on the incoming events, such as `export | where 1 == 1`, no longer +cause an internal error. diff --git a/libtenzir/src/tql2/ast.cpp b/libtenzir/src/tql2/ast.cpp index 42a17cce88c..b3834875d82 100644 --- a/libtenzir/src/tql2/ast.cpp +++ b/libtenzir/src/tql2/ast.cpp @@ -311,9 +311,15 @@ auto split_legacy_expression(const ast::expression& x) if (not left || not right) { return std::pair{trivially_true_expression(), x}; } + auto result + = expression{predicate{std::move(*left), *rel_op, std::move(*right)}}; + if (not normalize_and_validate(result)) { + return std::pair{trivially_true_expression(), x}; + } return std::pair{ - expression{predicate{std::move(*left), *rel_op, std::move(*right)}}, - ast::expression{ast::constant{true, location::unknown}}}; + std::move(result), + ast::expression{ast::constant{true, location::unknown}}, + }; } if (y.op.inner == ast::binary_op::and_) { auto [lo, ln] = split_legacy_expression(y.left);