mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-23 10:00:35 +00:00
Merge branch 'cql' of github.com:cloudius-systems/seastar-dev into db
CQL3Type and Functions conversion.
This commit is contained in:
@@ -225,6 +225,8 @@ deps = {
|
||||
'log.cc',
|
||||
'cql3/abstract_marker.cc',
|
||||
'cql3/cql3.cc',
|
||||
'cql3/cql3_type.cc',
|
||||
'cql3/functions/functions.cc',
|
||||
'thrift/handler.cc',
|
||||
'thrift/server.cc',
|
||||
'utils/murmur_hash.cc',
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "functions/function_call.hh"
|
||||
#include "functions/uuid_fcts.hh"
|
||||
#include "functions/bytes_conversion_fcts.hh"
|
||||
#include "functions/functions.hh"
|
||||
|
||||
#include "statements/alter_keyspace_statement.hh"
|
||||
#include "statements/alter_type_statement.hh"
|
||||
@@ -46,4 +47,5 @@
|
||||
#include "term.hh"
|
||||
#include "sets.hh"
|
||||
#include "cql3_row.hh"
|
||||
#include "cql3_type.hh"
|
||||
#include "attributes.hh"
|
||||
|
||||
45
cql3/cql3_type.cc
Normal file
45
cql3/cql3_type.cc
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Cloudius Systems, Ltd.
|
||||
*/
|
||||
|
||||
#include "cql3_type.hh"
|
||||
|
||||
namespace cql3 {
|
||||
|
||||
thread_local shared_ptr<cql3_type> native_cql3_type::ascii = make("ascii", ascii_type);
|
||||
thread_local shared_ptr<cql3_type> native_cql3_type::bigint = make("bigint", long_type);
|
||||
thread_local shared_ptr<cql3_type> native_cql3_type::blob = make("blob", bytes_type);
|
||||
thread_local shared_ptr<cql3_type> native_cql3_type::boolean = make("boolean", boolean_type);
|
||||
//thread_local shared_ptr<cql3_type> native_cql3_type::double = make("double", double_type);
|
||||
//thread_local shared_ptr<cql3_type> native_cql3_type::float = make("float", float_type);
|
||||
thread_local shared_ptr<cql3_type> native_cql3_type::int_ = make("int", int32_type);
|
||||
thread_local shared_ptr<cql3_type> native_cql3_type::text = make("text", utf8_type);
|
||||
thread_local shared_ptr<cql3_type> native_cql3_type::timestamp = make("timestamp", timestamp_type);
|
||||
thread_local shared_ptr<cql3_type> native_cql3_type::uuid = make("uuid", uuid_type);
|
||||
thread_local shared_ptr<cql3_type> native_cql3_type::varchar = make("varchar", utf8_type);
|
||||
thread_local shared_ptr<cql3_type> native_cql3_type::timeuuid = make("timeuuid", timeuuid_type);
|
||||
|
||||
const std::vector<shared_ptr<cql3_type>>&
|
||||
native_cql3_type::values() {
|
||||
static thread_local std::vector<shared_ptr<cql3_type>> v = {
|
||||
native_cql3_type::ascii,
|
||||
native_cql3_type::bigint,
|
||||
native_cql3_type::blob,
|
||||
native_cql3_type::boolean,
|
||||
#if 0
|
||||
native_cql3_type::double_,
|
||||
native_cql3_type::float_,
|
||||
#endif
|
||||
native_cql3_type::int_,
|
||||
native_cql3_type::text,
|
||||
native_cql3_type::timestamp,
|
||||
native_cql3_type::uuid,
|
||||
native_cql3_type::varchar,
|
||||
native_cql3_type::timeuuid,
|
||||
};
|
||||
return v;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -15,70 +15,65 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.cassandra.cql3;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
/*
|
||||
* Modified by Cloudius Systems
|
||||
*
|
||||
* Copyright 2015 Cloudius Systems
|
||||
*/
|
||||
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.db.marshal.*;
|
||||
import org.apache.cassandra.exceptions.InvalidRequestException;
|
||||
import org.apache.cassandra.exceptions.ConfigurationException;
|
||||
import org.apache.cassandra.exceptions.SyntaxException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
#pragma once
|
||||
|
||||
public interface CQL3Type
|
||||
{
|
||||
static final Logger logger = LoggerFactory.getLogger(CQL3Type.class);
|
||||
#include "database.hh"
|
||||
#include "exceptions/exceptions.hh"
|
||||
#include <iosfwd>
|
||||
|
||||
public boolean isCollection();
|
||||
public AbstractType<?> getType();
|
||||
namespace cql3 {
|
||||
|
||||
public enum Native implements CQL3Type
|
||||
{
|
||||
ASCII (AsciiType.instance),
|
||||
BIGINT (LongType.instance),
|
||||
BLOB (BytesType.instance),
|
||||
BOOLEAN (BooleanType.instance),
|
||||
class cql3_type {
|
||||
sstring _name;
|
||||
data_type _type;
|
||||
public:
|
||||
cql3_type(sstring name, data_type type) : _name(std::move(name)), _type(std::move(type)) {}
|
||||
virtual ~cql3_type() {}
|
||||
virtual bool is_collection() const = 0;
|
||||
data_type get_type() const { return _type; }
|
||||
sstring to_string() const { return _name; }
|
||||
};
|
||||
|
||||
class native_cql3_type : public cql3_type {
|
||||
static shared_ptr<cql3_type> make(sstring name, data_type type) {
|
||||
return make_shared<native_cql3_type>(std::move(name), std::move(type));
|
||||
}
|
||||
public:
|
||||
static thread_local shared_ptr<cql3_type> ascii;
|
||||
static thread_local shared_ptr<cql3_type> bigint;
|
||||
static thread_local shared_ptr<cql3_type> blob;
|
||||
static thread_local shared_ptr<cql3_type> boolean;
|
||||
//static thread_local shared_ptr<cql3_type> double;
|
||||
//static thread_local shared_ptr<cql3_type> float;
|
||||
static thread_local shared_ptr<cql3_type> int_;
|
||||
static thread_local shared_ptr<cql3_type> text;
|
||||
static thread_local shared_ptr<cql3_type> timestamp;
|
||||
static thread_local shared_ptr<cql3_type> uuid;
|
||||
static thread_local shared_ptr<cql3_type> varchar;
|
||||
static thread_local shared_ptr<cql3_type> timeuuid;
|
||||
|
||||
#if 0
|
||||
COUNTER (CounterColumnType.instance),
|
||||
DECIMAL (DecimalType.instance),
|
||||
DOUBLE (DoubleType.instance),
|
||||
FLOAT (FloatType.instance),
|
||||
INET (InetAddressType.instance),
|
||||
INT (Int32Type.instance),
|
||||
TEXT (UTF8Type.instance),
|
||||
TIMESTAMP(TimestampType.instance),
|
||||
UUID (UUIDType.instance),
|
||||
VARCHAR (UTF8Type.instance),
|
||||
VARINT (IntegerType.instance),
|
||||
TIMEUUID (TimeUUIDType.instance);
|
||||
|
||||
private final AbstractType<?> type;
|
||||
|
||||
private Native(AbstractType<?> type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public boolean isCollection()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public AbstractType<?> getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
#endif
|
||||
static const std::vector<shared_ptr<cql3_type>>& values();
|
||||
public:
|
||||
using cql3_type::cql3_type;
|
||||
virtual bool is_collection() const override {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
#if 0
|
||||
public static class Custom implements CQL3Type
|
||||
{
|
||||
private final AbstractType<?> type;
|
||||
@@ -591,4 +586,6 @@ public interface CQL3Type
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -24,6 +24,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "aggregate_function.hh"
|
||||
#include "native_aggregate_function.hh"
|
||||
|
||||
namespace cql3 {
|
||||
namespace functions {
|
||||
|
||||
@@ -50,7 +53,8 @@ public:
|
||||
* The function used to count the number of rows of a result set. This function is called when COUNT(*) or COUNT(1)
|
||||
* is specified.
|
||||
*/
|
||||
std::unique_ptr<aggregate_function>
|
||||
inline
|
||||
shared_ptr<aggregate_function>
|
||||
make_count_rows_function() {
|
||||
return make_native_aggregate_function_using<impl_count_function>("countRows", long_type);
|
||||
}
|
||||
@@ -62,7 +66,7 @@ public:
|
||||
virtual void reset() override {
|
||||
_sum = {};
|
||||
}
|
||||
virtual opt_bytes compute() override {
|
||||
virtual opt_bytes compute(int protocol_version) override {
|
||||
return data_type_for<Type>()->decompose(_sum);
|
||||
}
|
||||
virtual void add_input(int protocol_version, const std::vector<opt_bytes>& values) override {
|
||||
@@ -84,9 +88,10 @@ public:
|
||||
|
||||
|
||||
template <typename Type>
|
||||
std::unique_ptr<aggregate_function>
|
||||
inline
|
||||
shared_ptr<aggregate_function>
|
||||
make_sum_function() {
|
||||
return std::make_unique<sum_function_for<Type>>();
|
||||
return make_shared<sum_function_for<Type>>();
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
@@ -98,19 +103,19 @@ public:
|
||||
_sum = {};
|
||||
_count = 0;
|
||||
}
|
||||
virtual opt_bytes compute() override {
|
||||
virtual opt_bytes compute(int protocol_version) override {
|
||||
Type ret = 0;
|
||||
if (_count) {
|
||||
ret = _sum / _count;
|
||||
}
|
||||
return data_type_for<Type>().decompose(ret);
|
||||
return data_type_for<Type>()->decompose(ret);
|
||||
}
|
||||
virtual void add_input(int protocol_version, const std::vector<opt_bytes>& values) override {
|
||||
if (!values[0]) {
|
||||
return;
|
||||
}
|
||||
++_count;
|
||||
_sum += boost::any_cast<Type>(data_type_for<Type>().compose(*values[0]));
|
||||
_sum += boost::any_cast<Type>(data_type_for<Type>()->compose(*values[0]));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -124,9 +129,10 @@ public:
|
||||
};
|
||||
|
||||
template <typename Type>
|
||||
std::unique_ptr<aggregate_function>
|
||||
inline
|
||||
shared_ptr<aggregate_function>
|
||||
make_avg_function() {
|
||||
return std::make_unique<avg_function_for<Type>>();
|
||||
return make_shared<avg_function_for<Type>>();
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
@@ -171,9 +177,9 @@ public:
|
||||
* @return a MAX function for the specified type.
|
||||
*/
|
||||
template <typename Type>
|
||||
std::unique_ptr<aggregate_function>
|
||||
shared_ptr<aggregate_function>
|
||||
make_max_function() {
|
||||
return std::make_unique<max_function_for<Type>>();
|
||||
return shared_ptr<max_function_for<Type>>();
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
@@ -183,20 +189,20 @@ public:
|
||||
virtual void reset() override {
|
||||
_min = {};
|
||||
}
|
||||
virtual opt_bytes compute() override {
|
||||
virtual opt_bytes compute(int protocol_version) override {
|
||||
if (!_min) {
|
||||
return {};
|
||||
}
|
||||
return data_type_for<Type>().decompose(*_min);
|
||||
return data_type_for<Type>()->decompose(*_min);
|
||||
}
|
||||
virtual void add_input(int protocol_version, const std::vector<opt_bytes>& values) override {
|
||||
if (!values[0]) {
|
||||
return;
|
||||
}
|
||||
auto val = boost::any_cast<Type>(data_type_for<Type>()->compose(*values[0]));
|
||||
if (!_min) {
|
||||
_min = values[0];
|
||||
_min = val;
|
||||
} else {
|
||||
auto val = boost::any_cast<Type>(data_type_for<Type>().compose(*values[0]));
|
||||
_min = std::min(*_min, val);
|
||||
}
|
||||
}
|
||||
@@ -219,9 +225,9 @@ public:
|
||||
* @return a MIN function for the specified type.
|
||||
*/
|
||||
template <typename Type>
|
||||
std::unique_ptr<aggregate_function>
|
||||
shared_ptr<aggregate_function>
|
||||
make_min_function() {
|
||||
return std::make_unique<min_function_for<Type>>();
|
||||
return make_shared<min_function_for<Type>>();
|
||||
}
|
||||
|
||||
|
||||
@@ -232,7 +238,7 @@ public:
|
||||
virtual void reset() override {
|
||||
_count = 0;
|
||||
}
|
||||
virtual opt_bytes compute() override {
|
||||
virtual opt_bytes compute(int protocol_version) override {
|
||||
return long_type->decompose(_count);
|
||||
}
|
||||
virtual void add_input(int protocol_version, const std::vector<opt_bytes>& values) override {
|
||||
@@ -259,9 +265,9 @@ public:
|
||||
* @return a COUNT function for the specified type.
|
||||
*/
|
||||
template <typename Type>
|
||||
std::unique_ptr<aggregate_function>
|
||||
shared_ptr<aggregate_function>
|
||||
make_count_function() {
|
||||
return std::make_unique<count_function_for<Type>>();
|
||||
return make_shared<count_function_for<Type>>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,8 +22,11 @@
|
||||
* Copyright 2015 Cloudius Systems
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "native_scalar_function.hh"
|
||||
#include "exceptions/exceptions.hh"
|
||||
#include "core/print.hh"
|
||||
|
||||
namespace cql3 {
|
||||
|
||||
@@ -33,7 +36,7 @@ namespace functions {
|
||||
// bytes internally. They only "trick" the type system.
|
||||
|
||||
inline
|
||||
std::unique_ptr<function>
|
||||
shared_ptr<function>
|
||||
make_to_blob_function(data_type from_type) {
|
||||
// FIXME: use cql3 type name
|
||||
auto name = from_type->name() + "asblob";
|
||||
@@ -44,7 +47,7 @@ make_to_blob_function(data_type from_type) {
|
||||
}
|
||||
|
||||
inline
|
||||
std::unique_ptr<function>
|
||||
shared_ptr<function>
|
||||
make_from_blob_function(data_type to_type) {
|
||||
// FIXME: use cql3 type name
|
||||
sstring name = sstring("blobas") + to_type->name();
|
||||
@@ -67,7 +70,7 @@ make_from_blob_function(data_type to_type) {
|
||||
}
|
||||
|
||||
inline
|
||||
std::unique_ptr<function>
|
||||
shared_ptr<function>
|
||||
make_varchar_as_blob_fct() {
|
||||
return make_native_scalar_function<true>("varcharasblob", bytes_type, { utf8_type },
|
||||
[] (int protocol_version, const std::vector<bytes>& parameters) {
|
||||
@@ -76,7 +79,7 @@ make_varchar_as_blob_fct() {
|
||||
}
|
||||
|
||||
inline
|
||||
std::unique_ptr<function>
|
||||
shared_ptr<function>
|
||||
make_blob_as_varchar_fct() {
|
||||
return make_native_scalar_function<true>("blobasvarchar", utf8_type, { bytes_type },
|
||||
[] (int protocol_version, const std::vector<bytes>& parameters) {
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#ifndef CQL3_FUNCTIONS_FUNCTION_HH
|
||||
#define CQL3_FUNCTIONS_FUNCTION_HH
|
||||
|
||||
#include "function_name.hh"
|
||||
#include "database.hh"
|
||||
#include <vector>
|
||||
#include <experimental/optional>
|
||||
@@ -69,6 +70,7 @@ protected:
|
||||
friend std::ostream& operator<<(std::ostream& os, const function& f);
|
||||
};
|
||||
|
||||
inline
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const function& f) {
|
||||
f.print(os);
|
||||
|
||||
@@ -65,6 +65,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
inline
|
||||
std::ostream& operator<<(std::ostream& os, const function_name& fn) {
|
||||
if (!fn.keyspace.empty()) {
|
||||
os << fn.keyspace << ".";
|
||||
|
||||
15
cql3/functions/functions.cc
Normal file
15
cql3/functions/functions.cc
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Cloudius Systems, Ltd.
|
||||
*/
|
||||
|
||||
#include "functions.hh"
|
||||
|
||||
namespace cql3 {
|
||||
namespace functions {
|
||||
|
||||
thread_local std::unordered_multimap<function_name, shared_ptr<function>> functions::_declared = init();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,79 +15,101 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.cassandra.cql3.functions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
/*
|
||||
* Modified by Cloudius Systems
|
||||
*
|
||||
* Copyright 2015 Cloudius Systems
|
||||
*/
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
#pragma once
|
||||
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.cql3.*;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.exceptions.InvalidRequestException;
|
||||
import org.apache.cassandra.service.IMigrationListener;
|
||||
import org.apache.cassandra.service.MigrationManager;
|
||||
#include "function.hh"
|
||||
#include "aggregate_fcts.hh"
|
||||
#include "time_uuid_fcts.hh"
|
||||
#include "uuid_fcts.hh"
|
||||
#include "bytes_conversion_fcts.hh"
|
||||
#include "aggregate_fcts.hh"
|
||||
#include "bytes_conversion_fcts.hh"
|
||||
#include "cql3/assignment_testable.hh"
|
||||
#include "cql3/cql3_type.hh"
|
||||
#include <unordered_map>
|
||||
|
||||
public abstract class Functions
|
||||
{
|
||||
namespace cql3 {
|
||||
|
||||
namespace functions {
|
||||
|
||||
#if 0
|
||||
// We special case the token function because that's the only function whose argument types actually
|
||||
// depend on the table on which the function is called. Because it's the sole exception, it's easier
|
||||
// to handle it as a special case.
|
||||
private static final FunctionName TOKEN_FUNCTION_NAME = FunctionName.nativeFunction("token");
|
||||
#endif
|
||||
|
||||
private Functions() {}
|
||||
class functions {
|
||||
static thread_local std::unordered_multimap<function_name, shared_ptr<function>> _declared;
|
||||
private:
|
||||
static std::unordered_multimap<function_name, shared_ptr<function>> init() {
|
||||
std::unordered_multimap<function_name, shared_ptr<function>> ret;
|
||||
auto declare = [&ret] (shared_ptr<function> f) { ret.emplace(f->name(), std::move(f)); };
|
||||
declare(aggregate_fcts::make_count_rows_function());
|
||||
declare(time_uuid_fcts::make_now_fct());
|
||||
declare(time_uuid_fcts::make_min_timeuuid_fct());
|
||||
declare(time_uuid_fcts::make_max_timeuuid_fct());
|
||||
declare(time_uuid_fcts::make_date_of_fct());
|
||||
declare(time_uuid_fcts::make_unix_timestamp_of_fcf());
|
||||
declare(make_uuid_fct());
|
||||
|
||||
private static final ArrayListMultimap<FunctionName, Function> declared = ArrayListMultimap.create();
|
||||
|
||||
static
|
||||
{
|
||||
declare(AggregateFcts.countRowsFunction);
|
||||
declare(TimeuuidFcts.nowFct);
|
||||
declare(TimeuuidFcts.minTimeuuidFct);
|
||||
declare(TimeuuidFcts.maxTimeuuidFct);
|
||||
declare(TimeuuidFcts.dateOfFct);
|
||||
declare(TimeuuidFcts.unixTimestampOfFct);
|
||||
declare(UuidFcts.uuidFct);
|
||||
|
||||
for (CQL3Type type : CQL3Type.Native.values())
|
||||
{
|
||||
for (auto&& type : native_cql3_type::values()) {
|
||||
// Note: because text and varchar ends up being synonimous, our automatic makeToBlobFunction doesn't work
|
||||
// for varchar, so we special case it below. We also skip blob for obvious reasons.
|
||||
if (type == CQL3Type.Native.VARCHAR || type == CQL3Type.Native.BLOB)
|
||||
if (type == native_cql3_type::varchar || type == native_cql3_type::blob) {
|
||||
continue;
|
||||
}
|
||||
|
||||
declare(BytesConversionFcts.makeToBlobFunction(type.getType()));
|
||||
declare(BytesConversionFcts.makeFromBlobFunction(type.getType()));
|
||||
|
||||
declare(AggregateFcts.makeCountFunction(type.getType()));
|
||||
declare(AggregateFcts.makeMaxFunction(type.getType()));
|
||||
declare(AggregateFcts.makeMinFunction(type.getType()));
|
||||
declare(make_to_blob_function(type->get_type()));
|
||||
declare(make_from_blob_function(type->get_type()));
|
||||
}
|
||||
declare(BytesConversionFcts.VarcharAsBlobFct);
|
||||
declare(BytesConversionFcts.BlobAsVarcharFact);
|
||||
declare(AggregateFcts.sumFunctionForInt32);
|
||||
declare(AggregateFcts.sumFunctionForLong);
|
||||
declare(aggregate_fcts::make_count_function<int32_t>());
|
||||
declare(aggregate_fcts::make_max_function<int32_t>());
|
||||
declare(aggregate_fcts::make_min_function<int32_t>());
|
||||
|
||||
declare(aggregate_fcts::make_count_function<int64_t>());
|
||||
declare(aggregate_fcts::make_max_function<int64_t>());
|
||||
declare(aggregate_fcts::make_min_function<int64_t>());
|
||||
|
||||
//FIXME:
|
||||
//declare(aggregate_fcts::make_count_function<bytes>());
|
||||
//declare(aggregate_fcts::make_max_function<bytes>());
|
||||
//declare(aggregate_fcts::make_min_function<bytes>());
|
||||
|
||||
// FIXME: more count/min/max
|
||||
|
||||
declare(make_varchar_as_blob_fct());
|
||||
declare(make_blob_as_varchar_fct());
|
||||
declare(aggregate_fcts::make_sum_function<int32_t>());
|
||||
declare(aggregate_fcts::make_sum_function<int64_t>());
|
||||
declare(aggregate_fcts::make_avg_function<int32_t>());
|
||||
declare(aggregate_fcts::make_avg_function<int64_t>());
|
||||
#if 0
|
||||
declare(AggregateFcts.sumFunctionForFloat);
|
||||
declare(AggregateFcts.sumFunctionForDouble);
|
||||
declare(AggregateFcts.sumFunctionForDecimal);
|
||||
declare(AggregateFcts.sumFunctionForVarint);
|
||||
declare(AggregateFcts.avgFunctionForInt32);
|
||||
declare(AggregateFcts.avgFunctionForLong);
|
||||
declare(AggregateFcts.avgFunctionForFloat);
|
||||
declare(AggregateFcts.avgFunctionForDouble);
|
||||
declare(AggregateFcts.avgFunctionForVarint);
|
||||
declare(AggregateFcts.avgFunctionForDecimal);
|
||||
#endif
|
||||
|
||||
// also needed for smp:
|
||||
#if 0
|
||||
MigrationManager.instance.register(new FunctionsMigrationListener());
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static void declare(Function fun)
|
||||
{
|
||||
declared.put(fun.name(), fun);
|
||||
}
|
||||
|
||||
#if 0
|
||||
public static ColumnSpecification makeArgSpec(String receiverKs, String receiverCf, Function fun, int i)
|
||||
{
|
||||
return new ColumnSpecification(receiverKs,
|
||||
@@ -95,20 +117,19 @@ public abstract class Functions
|
||||
new ColumnIdentifier("arg" + i + "(" + fun.name().toString().toLowerCase() + ")", true),
|
||||
fun.argTypes().get(i));
|
||||
}
|
||||
|
||||
public static int getOverloadCount(FunctionName name)
|
||||
{
|
||||
return declared.get(name).size();
|
||||
#endif
|
||||
static int get_overload_count(const function_name& name) {
|
||||
return _declared.count(name);
|
||||
}
|
||||
|
||||
public static Function get(String keyspace,
|
||||
FunctionName name,
|
||||
List<? extends AssignmentTestable> providedArgs,
|
||||
String receiverKs,
|
||||
String receiverCf)
|
||||
throws InvalidRequestException
|
||||
{
|
||||
if (name.hasKeyspace()
|
||||
static shared_ptr<function> get(const sstring& keyspace,
|
||||
const function_name& name,
|
||||
const std::vector<shared_ptr<assignment_testable>>& provided_args,
|
||||
const sstring& receiver_ks,
|
||||
const sstring& receiver_cf) {
|
||||
#if 0
|
||||
// later
|
||||
if (name.has_keyspace()
|
||||
? name.equals(TOKEN_FUNCTION_NAME)
|
||||
: name.name.equals(TOKEN_FUNCTION_NAME.name))
|
||||
return new TokenFct(Schema.instance.getCFMetaData(receiverKs, receiverCf));
|
||||
@@ -164,24 +185,30 @@ public abstract class Functions
|
||||
name, toString(compatibles)));
|
||||
|
||||
return compatibles.get(0);
|
||||
#endif
|
||||
abort();
|
||||
}
|
||||
|
||||
public static List<Function> find(FunctionName name)
|
||||
{
|
||||
return declared.get(name);
|
||||
}
|
||||
|
||||
public static Function find(FunctionName name, List<AbstractType<?>> argTypes)
|
||||
{
|
||||
assert name.hasKeyspace() : "function name not fully qualified";
|
||||
for (Function f : declared.get(name))
|
||||
{
|
||||
if (typeEquals(f.argTypes(), argTypes))
|
||||
return f;
|
||||
static std::vector<shared_ptr<function>> find(const function_name& name) {
|
||||
auto range = _declared.equal_range(name);
|
||||
std::vector<shared_ptr<function>> ret;
|
||||
for (auto i = range.first; i != range.second; ++i) {
|
||||
ret.push_back(i->second);
|
||||
}
|
||||
return null;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static shared_ptr<function> find(const function_name& name, const std::vector<data_type>& arg_types) {
|
||||
assert(name.has_keyspace()); // : "function name not fully qualified";
|
||||
for (auto&& f : find(name)) {
|
||||
if (type_equals(f->arg_types(), arg_types)) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
#if 0
|
||||
// This method and matchArguments are somewhat duplicate, but this method allows us to provide more precise errors in the common
|
||||
// case where there is no override for a given function. This is thus probably worth the minor code duplication.
|
||||
private static void validateTypes(String keyspace,
|
||||
@@ -292,16 +319,21 @@ public abstract class Functions
|
||||
return t1.asCQL3Type().toString().equals(t2.asCQL3Type().toString());
|
||||
}
|
||||
|
||||
public static boolean typeEquals(List<AbstractType<?>> t1, List<AbstractType<?>> t2)
|
||||
{
|
||||
#endif
|
||||
|
||||
static bool type_equals(const std::vector<data_type>& t1, const std::vector<data_type>& t2) {
|
||||
#if 0
|
||||
if (t1.size() != t2.size())
|
||||
return false;
|
||||
for (int i = 0; i < t1.size(); i ++)
|
||||
if (!typeEquals(t1.get(i), t2.get(i)))
|
||||
return false;
|
||||
return true;
|
||||
#endif
|
||||
abort();
|
||||
}
|
||||
|
||||
#if 0
|
||||
private static class FunctionsMigrationListener implements IMigrationListener
|
||||
{
|
||||
public void onCreateKeyspace(String ksName) { }
|
||||
@@ -326,4 +358,8 @@ public abstract class Functions
|
||||
public void onDropFunction(String ksName, String functionName) { }
|
||||
public void onDropAggregate(String ksName, String aggregateName) { }
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "database.hh"
|
||||
#include "native_function.hh"
|
||||
#include "core/shared_ptr.hh"
|
||||
|
||||
namespace cql3 {
|
||||
namespace functions {
|
||||
@@ -59,9 +60,9 @@ public:
|
||||
};
|
||||
|
||||
template <class Aggregate>
|
||||
std::unique_ptr<native_aggregate_function>
|
||||
shared_ptr<native_aggregate_function>
|
||||
make_native_aggregate_function_using(sstring name, shared_ptr<abstract_type> type) {
|
||||
return std::make_unique<native_aggregate_function_using<Aggregate>>(name, type);
|
||||
return ::make_shared<native_aggregate_function_using<Aggregate>>(name, type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "native_function.hh"
|
||||
#include "scalar_function.hh"
|
||||
#include "core/shared_ptr.hh"
|
||||
|
||||
namespace cql3 {
|
||||
namespace functions {
|
||||
@@ -63,12 +64,12 @@ public:
|
||||
};
|
||||
|
||||
template <bool Pure, typename Func>
|
||||
std::unique_ptr<function>
|
||||
shared_ptr<function>
|
||||
make_native_scalar_function(sstring name,
|
||||
data_type return_type,
|
||||
std::vector<data_type> args_type,
|
||||
Func&& func) {
|
||||
return std::make_unique<native_scalar_function_for<Func, Pure>>(std::move(name),
|
||||
return ::make_shared<native_scalar_function_for<Func, Pure>>(std::move(name),
|
||||
std::move(return_type),
|
||||
std::move(args_type),
|
||||
std::forward<Func>(func));
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace functions {
|
||||
namespace time_uuid_fcts {
|
||||
|
||||
inline
|
||||
std::unique_ptr<function>
|
||||
shared_ptr<function>
|
||||
make_now_fct() {
|
||||
return make_native_scalar_function<false>("now", timeuuid_type, {},
|
||||
[] (int protocol_version, const std::vector<bytes>& values) {
|
||||
@@ -45,7 +45,7 @@ make_now_fct() {
|
||||
}
|
||||
|
||||
inline
|
||||
std::unique_ptr<function>
|
||||
shared_ptr<function>
|
||||
make_min_timeuuid_fct() {
|
||||
return make_native_scalar_function<true>("mintimeuuid", timeuuid_type, { timestamp_type },
|
||||
[] (int protocol_version, const std::vector<bytes>& values) {
|
||||
@@ -66,7 +66,7 @@ make_min_timeuuid_fct() {
|
||||
}
|
||||
|
||||
inline
|
||||
std::unique_ptr<function>
|
||||
shared_ptr<function>
|
||||
make_max_timeuuid_fct() {
|
||||
return make_native_scalar_function<true>("maxtimeuuid", timeuuid_type, { timestamp_type },
|
||||
[] (int protocol_version, const std::vector<bytes>& values) {
|
||||
@@ -87,7 +87,7 @@ make_max_timeuuid_fct() {
|
||||
}
|
||||
|
||||
inline
|
||||
std::unique_ptr<function>
|
||||
shared_ptr<function>
|
||||
make_date_of_fct() {
|
||||
return make_native_scalar_function<true>("dateof", timestamp_type, { timeuuid_type },
|
||||
[] (int protocol, const std::vector<bytes>& values) {
|
||||
@@ -102,7 +102,7 @@ make_date_of_fct() {
|
||||
}
|
||||
|
||||
inline
|
||||
std::unique_ptr<function>
|
||||
shared_ptr<function>
|
||||
make_unix_timestamp_of_fcf() {
|
||||
return make_native_scalar_function<true>("unixtimestampof", long_type, { timeuuid_type },
|
||||
[] (int protocol, const std::vector<bytes>& values) {
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
* Copyright 2015 Cloudius Systems
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "database.hh"
|
||||
#include "native_scalar_function.hh"
|
||||
#include "utils/UUID.hh"
|
||||
@@ -31,7 +33,7 @@ namespace cql3 {
|
||||
namespace functions {
|
||||
|
||||
inline
|
||||
std::unique_ptr<function>
|
||||
shared_ptr<function>
|
||||
make_uuid_fct() {
|
||||
return make_native_scalar_function<false>("uuid", uuid_type, {},
|
||||
[] (int protocol_version, const std::vector<bytes>& parameters) {
|
||||
|
||||
@@ -278,7 +278,7 @@ struct uuid_type_impl : abstract_type {
|
||||
// FIXME: isCompatibleWith(uuid)
|
||||
};
|
||||
|
||||
thread_local shared_ptr<abstract_type> int_type(make_shared<int32_type_impl>());
|
||||
thread_local shared_ptr<abstract_type> int32_type(make_shared<int32_type_impl>());
|
||||
thread_local shared_ptr<abstract_type> long_type(make_shared<long_type_impl>());
|
||||
thread_local shared_ptr<abstract_type> ascii_type(make_shared<string_type_impl>("ascii"));
|
||||
thread_local shared_ptr<abstract_type> bytes_type(make_shared<bytes_type_impl>());
|
||||
|
||||
Reference in New Issue
Block a user