Files
scylladb/cql3/expr/evaluate.hh
Nadav Har'El 4ac63de063 cql3: parse per-element timestamps/TTLs in the selection layer
Wire up the selection and result-set infrastructure to consume the
extended collection wire format introduced in the previous patch and
expose per-element timestamps and TTLs to the expression evaluator.

* Add collection_cell_metadata: maps from raw element-key bytes to
  timestamp and remaining TTL, one entry per collection or UDT cell.
  Add a corresponding collection_element_metadata span to
  evaluation_inputs so that evaluators can access it.

* Add a flag _collect_collection_timestamps to selection (selection.hh/cc).
  When any selected expression contains a WRITETIME(col[key])/TTL(col[key])
  or WRITETIME(col.field)/TTL(col.field) attribute, the flag is set and
  the send_collection_timestamps partition-slice option is enabled,
  causing storage nodes to use the extended wire format from the
  previous patch.

* Implement result_set_builder::add_collection() (selection.cc): when
  _collect_collection_timestamps is set, parse the extended format,
  decode per-element timestamps and remaining TTLs (computed from the
  stored expiry time and the query time), and store them in
  _collection_element_metadata indexed by column position.  When the
  flag is not set, the existing plain-bytes path is unchanged.

After this patch, the new selection feature is still not available to
the end-user because the prepare step still forbids it. The next patch
will finally complete the expression preparation and evaluation.
It will read the new collection_element_metadata and return the correct
timestamp or TTL value.
2026-04-12 12:51:06 +03:00

42 lines
1.4 KiB
C++

// Copyright (C) 2023-present ScyllaDB
// SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
#pragma once
#include "collection_cell_metadata.hh"
#include "expression.hh"
#include "bytes.hh"
namespace cql3 {
class query_options;
class raw_value;
}
namespace cql3::expr {
// Input data needed to evaluate an expression. Individual members can be
// null if not applicable (e.g. evaluating outside a row context)
struct evaluation_inputs {
std::span<const bytes> partition_key;
std::span<const bytes> clustering_key;
std::span<const managed_bytes_opt> static_and_regular_columns; // indexes match `selection` member
const cql3::selection::selection* selection = nullptr;
const query_options* options = nullptr;
std::span<const api::timestamp_type> static_and_regular_timestamps; // indexes match `selection` member
std::span<const int32_t> static_and_regular_ttls; // indexes match `selection` member
std::span<const cql3::raw_value> temporaries; // indexes match temporary::index
std::span<const collection_cell_metadata> collection_element_metadata; // indexes match `selection` member
};
// Takes a prepared expression and calculates its value.
// Evaluates bound values, calls functions and returns just the bytes and type.
cql3::raw_value evaluate(const expression& e, const evaluation_inputs&);
cql3::raw_value evaluate(const expression& e, const query_options&);
}