An expr::constant is an expression that happens to represent a constant,
so it's too heavyweight to be used for evaluation. Right now the extra
weight is just a type (which causes extra work by having to maintain
the shared_ptr reference count), but it will grow in the future to include
source location (for error reporting) and maybe other things.
Prior to e9b6171b5 ("Merge 'cql3: expr: unify left-hand-side and
right-hand-side of binary_operator prepares' from Avi Kivity"), we had
to use expr::constant since there was not enough type infomation in
expressions. But now every expression carries its type (in programming
language terms, expressions are now statically typed), so carrying types
in values is not needed.
So change evaluate() to return cql3::raw_value. The majority of the
patch just changes that. The rest deals with some fallout:
- cql3::raw_value gains a view() helper to convert to a raw_value_view,
and is_null_or_unset() to match with expr::constant and reduce further
churn.
- some helpers that worked on expr::constant and now receive a
raw_value now need the type passed via an additional argument. The
type is computed from the expression by the caller.
- many type checks during expression evaluation were dropped. This is
a consequence of static typing - we must trust the expression prepare
phase to perform full type checking since values no longer carry type
information.
Closes #10797
67 lines
2.2 KiB
C++
67 lines
2.2 KiB
C++
/*
|
|
* Copyright (C) 2015-present ScyllaDB
|
|
*
|
|
* Modified by ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: (AGPL-3.0-or-later and Apache-2.0)
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "cql3/abstract_marker.hh"
|
|
#include "maps.hh"
|
|
#include "column_specification.hh"
|
|
#include "column_identifier.hh"
|
|
#include "to_string.hh"
|
|
#include <unordered_set>
|
|
|
|
namespace cql3 {
|
|
|
|
/**
|
|
* Static helper methods and classes for sets.
|
|
*/
|
|
class sets {
|
|
sets() = delete;
|
|
public:
|
|
static lw_shared_ptr<column_specification> value_spec_of(const column_specification& column);
|
|
|
|
class setter : public operation {
|
|
public:
|
|
setter(const column_definition& column, expr::expression e)
|
|
: operation(column, std::move(e)) {
|
|
}
|
|
virtual void execute(mutation& m, const clustering_key_prefix& row_key, const update_parameters& params) override;
|
|
static void execute(mutation& m, const clustering_key_prefix& row_key, const update_parameters& params, const column_definition& column, const cql3::raw_value& value);
|
|
};
|
|
|
|
class adder : public operation {
|
|
public:
|
|
adder(const column_definition& column, expr::expression e)
|
|
: operation(column, std::move(e)) {
|
|
}
|
|
virtual void execute(mutation& m, const clustering_key_prefix& row_key, const update_parameters& params) override;
|
|
static void do_add(mutation& m, const clustering_key_prefix& row_key, const update_parameters& params,
|
|
const cql3::raw_value& value, const column_definition& column);
|
|
};
|
|
|
|
// Note that this is reused for Map subtraction too (we subtract a set from a map)
|
|
class discarder : public operation {
|
|
public:
|
|
discarder(const column_definition& column, expr::expression e)
|
|
: operation(column, std::move(e)) {
|
|
}
|
|
virtual void execute(mutation& m, const clustering_key_prefix& row_key, const update_parameters& params) override;
|
|
};
|
|
|
|
class element_discarder : public operation {
|
|
public:
|
|
element_discarder(const column_definition& column, expr::expression e)
|
|
: operation(column, std::move(e)) { }
|
|
virtual void execute(mutation& m, const clustering_key_prefix& row_key, const update_parameters& params) override;
|
|
};
|
|
};
|
|
|
|
}
|