Skip to content
This repository was archived by the owner on Feb 8, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/PrintToScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void PrintToScreen::printTuple(const TupleStorageSubBlock &tuple_store,
*width_it,
"NULL");
} else {
attr_it->getType().printValueToFile(value, out, *width_it);
attr_it->getType().printTypedValueToFile(value, out, *width_it);
}

fputc('|', out);
Expand Down
3 changes: 2 additions & 1 deletion compression/CompressionDictionaryBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ void CompressionDictionaryBuilder::buildDictionary(void *location) {
bool CompressionDictionaryBuilder::insertEntryInternal(const TypedValue &value,
bool by_reference) {
DCHECK(!built_);
DCHECK(value.isPlausibleInstanceOf(type_.getSignature()));
// DCHECK(value.isPlausibleInstanceOf(type_.getSignature()));
// TODO(refactor-type): fix signature.

if (type_is_nullable_ && value.isNull()) {
last_insert_was_null_ = !null_value_present_;
Expand Down
6 changes: 4 additions & 2 deletions compression/CompressionDictionaryBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ class CompressionDictionaryBuilder {
* value.
**/
bool containsValue(const TypedValue &value) const {
DCHECK(value.isPlausibleInstanceOf(type_.getSignature()));
// DCHECK(value.isPlausibleInstanceOf(type_.getSignature()));
// TODO(refactor-type): fix signature.
if (value.isNull()) {
return null_value_present_;
}
Expand All @@ -133,7 +134,8 @@ class CompressionDictionaryBuilder {
* @return The code that maps to value.
**/
inline std::uint32_t getCodeForValue(const TypedValue &value) const {
DCHECK(value.isPlausibleInstanceOf(type_.getSignature()));
// DCHECK(value.isPlausibleInstanceOf(type_.getSignature()));
// TODO(refactor-type): fix signature.
DCHECK(containsValue(value));
DCHECK(built_);
if (value.isNull()) {
Expand Down
4 changes: 2 additions & 2 deletions expressions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ target_link_libraries(quickstep_expressions_ExpressionFactories
quickstep_expressions_scalar_ScalarUnaryExpression
quickstep_types_TypeFactory
quickstep_types_TypedValue
quickstep_types_operations_binaryoperations_BinaryOperationFactory
quickstep_types_operations_OperationFactory
quickstep_types_operations_OperationSignature
quickstep_types_operations_comparisons_ComparisonFactory
quickstep_types_operations_unaryoperations_UnaryOperationFactory
quickstep_utility_Macros)
target_link_libraries(quickstep_expressions_Expressions_proto
quickstep_types_Type_proto
Expand Down
61 changes: 39 additions & 22 deletions expressions/ExpressionFactories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
#include "expressions/scalar/ScalarUnaryExpression.hpp"
#include "types/TypeFactory.hpp"
#include "types/TypedValue.hpp"
#include "types/operations/binary_operations/BinaryOperationFactory.hpp"
#include "types/operations/OperationFactory.hpp"
#include "types/operations/OperationSignature.hpp"
#include "types/operations/comparisons/ComparisonFactory.hpp"
#include "types/operations/unary_operations/UnaryOperationFactory.hpp"
#include "utility/Macros.hpp"

#include "glog/logging.h"
Expand Down Expand Up @@ -168,17 +168,43 @@ Scalar* ScalarFactory::ReconstructFromProto(const serialization::Scalar &proto,
proto.GetExtension(serialization::ScalarAttribute::attribute_id)));
}
case serialization::Scalar::UNARY_EXPRESSION: {
std::vector<TypedValue> static_arguments;
const int num_static_args =
proto.ExtensionSize(serialization::ScalarUnaryExpression::static_arguments);
for (int i = 0; i < num_static_args; ++i) {
static_arguments.emplace_back(
TypedValue::ReconstructFromProto(
proto.GetExtension(serialization::ScalarUnaryExpression::static_arguments, i)));
}
const OperationSignaturePtr op_signature =
OperationSignature::ReconstructFromProto(
proto.GetExtension(serialization::ScalarUnaryExpression::op_signature));
return new ScalarUnaryExpression(
UnaryOperationFactory::ReconstructFromProto(
proto.GetExtension(serialization::ScalarUnaryExpression::operation)),
ReconstructFromProto(proto.GetExtension(serialization::ScalarUnaryExpression::operand), database));
op_signature,
OperationFactory::GetUnaryOperation(op_signature),
ReconstructFromProto(proto.GetExtension(serialization::ScalarUnaryExpression::operand), database),
std::make_shared<std::vector<TypedValue>>(std::move(static_arguments)));
}
case serialization::Scalar::BINARY_EXPRESSION: {
std::vector<TypedValue> static_arguments;
const int num_static_args =
proto.ExtensionSize(serialization::ScalarBinaryExpression::static_arguments);
for (int i = 0; i < num_static_args; ++i) {
static_arguments.emplace_back(
TypedValue::ReconstructFromProto(
proto.GetExtension(serialization::ScalarBinaryExpression::static_arguments, i)));
}
const OperationSignaturePtr op_signature =
OperationSignature::ReconstructFromProto(
proto.GetExtension(serialization::ScalarBinaryExpression::op_signature));
return new ScalarBinaryExpression(
BinaryOperationFactory::ReconstructFromProto(
proto.GetExtension(serialization::ScalarBinaryExpression::operation)),
ReconstructFromProto(proto.GetExtension(serialization::ScalarBinaryExpression::left_operand), database),
ReconstructFromProto(proto.GetExtension(serialization::ScalarBinaryExpression::right_operand), database));
op_signature,
OperationFactory::GetBinaryOperation(op_signature),
ReconstructFromProto(
proto.GetExtension(serialization::ScalarBinaryExpression::left_operand), database),
ReconstructFromProto(
proto.GetExtension(serialization::ScalarBinaryExpression::right_operand), database),
std::make_shared<std::vector<TypedValue>>(std::move(static_arguments)));
}
case serialization::Scalar::CASE_EXPRESSION: {
const Type &result_type = TypeFactory::ReconstructFromProto(
Expand Down Expand Up @@ -248,22 +274,13 @@ bool ScalarFactory::ProtoIsValid(const serialization::Scalar &proto,
break;
}
case serialization::Scalar::UNARY_EXPRESSION: {
if (proto.HasExtension(serialization::ScalarUnaryExpression::operation)
&& proto.HasExtension(serialization::ScalarUnaryExpression::operand)) {
return UnaryOperationFactory::ProtoIsValid(proto.GetExtension(serialization::ScalarUnaryExpression::operation))
&& ProtoIsValid(proto.GetExtension(serialization::ScalarUnaryExpression::operand), database);
}
// TODO
return true;
break;
}
case serialization::Scalar::BINARY_EXPRESSION: {
if (proto.HasExtension(serialization::ScalarBinaryExpression::operation)
&& proto.HasExtension(serialization::ScalarBinaryExpression::left_operand)
&& proto.HasExtension(serialization::ScalarBinaryExpression::right_operand)) {
return BinaryOperationFactory::ProtoIsValid(
proto.GetExtension(serialization::ScalarBinaryExpression::operation))
&& ProtoIsValid(proto.GetExtension(serialization::ScalarBinaryExpression::left_operand), database)
&& ProtoIsValid(proto.GetExtension(serialization::ScalarBinaryExpression::right_operand), database);
}
// TODO
return true;
break;
}
case serialization::Scalar::CASE_EXPRESSION: {
Expand Down
12 changes: 7 additions & 5 deletions expressions/Expressions.proto
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,18 @@ message ScalarAttribute {

message ScalarUnaryExpression {
extend Scalar {
optional UnaryOperation operation = 96;
optional Scalar operand = 97;
optional OperationSignature op_signature = 97;
optional Scalar operand = 98;
repeated TypedValue static_arguments = 99;
}
}

message ScalarBinaryExpression {
extend Scalar {
optional BinaryOperation operation = 128;
optional Scalar left_operand = 129;
optional Scalar right_operand = 130;
optional OperationSignature op_signature = 129;
optional Scalar left_operand = 130;
optional Scalar right_operand = 131;
repeated TypedValue static_arguments = 132;
}
}

Expand Down
18 changes: 10 additions & 8 deletions expressions/aggregation/AggregateFunctionAvg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
#include "types/Type.hpp"
#include "types/TypeFactory.hpp"
#include "types/TypeID.hpp"
#include "types/operations/OperationFactory.hpp"
#include "types/operations/binary_operations/BinaryOperation.hpp"
#include "types/operations/binary_operations/BinaryOperationFactory.hpp"
#include "types/operations/binary_operations/BinaryOperationID.hpp"

#include "glog/logging.h"

Expand All @@ -41,10 +40,12 @@ bool AggregateFunctionAvg::canApplyToTypes(
}

// Argument must be addable and divisible.
return BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd)
.canApplyToTypes(*argument_types.front(), *argument_types.front())
&& BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide)
.canApplyToTypes(*argument_types.front(), TypeFactory::GetType(kDouble));
const Type &type = *argument_types.front();
if (!OperationFactory::CanApplyAddOperation(type, type)) {
return false;
}
return OperationFactory::CanApplyDivideOperation(
type, TypeFactory::GetType(kDouble));
}

const Type* AggregateFunctionAvg::resultTypeForArgumentTypes(
Expand All @@ -67,8 +68,9 @@ const Type* AggregateFunctionAvg::resultTypeForArgumentTypes(
break;
}

return BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide)
.resultTypeForArgumentTypes(*sum_type, TypeFactory::GetType(kDouble));
return OperationFactory::GetDivideOperation(
sum_type->getTypeID(), kDouble)
->getResultType(*sum_type, TypeFactory::GetType(kDouble));
}

AggregationHandle* AggregateFunctionAvg::createHandle(
Expand Down
7 changes: 3 additions & 4 deletions expressions/aggregation/AggregateFunctionSum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
#include "types/Type.hpp"
#include "types/TypeFactory.hpp"
#include "types/TypeID.hpp"
#include "types/operations/OperationFactory.hpp"
#include "types/operations/binary_operations/BinaryOperation.hpp"
#include "types/operations/binary_operations/BinaryOperationFactory.hpp"
#include "types/operations/binary_operations/BinaryOperationID.hpp"

#include "glog/logging.h"

Expand All @@ -41,8 +40,8 @@ bool AggregateFunctionSum::canApplyToTypes(
}

// Argument must be addable.
return BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd)
.canApplyToTypes(*argument_types.front(), *argument_types.front());
const Type &type = *argument_types.front();
return OperationFactory::CanApplyAddOperation(type, type);
}

const Type* AggregateFunctionSum::resultTypeForArgumentTypes(
Expand Down
22 changes: 10 additions & 12 deletions expressions/aggregation/AggregationHandleAvg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
#include "types/TypeFactory.hpp"
#include "types/TypeID.hpp"
#include "types/TypedValue.hpp"
#include "types/operations/OperationFactory.hpp"
#include "types/operations/binary_operations/BinaryOperation.hpp"
#include "types/operations/binary_operations/BinaryOperationFactory.hpp"
#include "types/operations/binary_operations/BinaryOperationID.hpp"

#include "glog/logging.h"

Expand Down Expand Up @@ -69,24 +68,23 @@ AggregationHandleAvg::AggregationHandleAvg(const Type &type)
// Make operators to do arithmetic:
// Add operator for summing argument values.
fast_add_operator_.reset(
BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd)
.makeUncheckedBinaryOperatorForTypes(sum_type, argument_type_));
OperationFactory::GetAddOperation(type_precision_id, argument_type_.getTypeID())
->makeUncheckedBinaryOperator(sum_type, argument_type_));
// Add operator for merging states.
merge_add_operator_.reset(
BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd)
.makeUncheckedBinaryOperatorForTypes(sum_type, sum_type));
OperationFactory::GetAddOperation(type_precision_id, type_precision_id)
->makeUncheckedBinaryOperator(sum_type, sum_type));
// Divide operator for dividing sum by count to get final average.
divide_operator_.reset(
BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide)
.makeUncheckedBinaryOperatorForTypes(sum_type,
TypeFactory::GetType(kDouble)));
OperationFactory::GetDivideOperation(type_precision_id, kDouble)
->makeUncheckedBinaryOperator(sum_type, TypeFactory::GetType(kDouble)));

// Result is nullable, because AVG() over 0 values (or all NULL values) is
// NULL.
result_type_ =
&(BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide)
.resultTypeForArgumentTypes(sum_type, TypeFactory::GetType(kDouble))
->getNullableVersion());
&OperationFactory::GetDivideOperation(type_precision_id, kDouble)
->getResultType(sum_type, TypeFactory::GetType(kDouble))
->getNullableVersion();
}

AggregationState* AggregationHandleAvg::accumulateValueAccessor(
Expand Down
8 changes: 5 additions & 3 deletions expressions/aggregation/AggregationHandleAvg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class AggregationHandleAvg : public AggregationConcreteHandle {

inline void iterateUnaryInl(AggregationStateAvg *state,
const TypedValue &value) const {
DCHECK(value.isPlausibleInstanceOf(argument_type_.getSignature()));
// DCHECK(value.isPlausibleInstanceOf(argument_type_.getSignature()));
// TODO(refactor-type): fix signature.
if (value.isNull()) return;

SpinMutexLock lock(state->mutex_);
Expand All @@ -127,8 +128,9 @@ class AggregationHandleAvg : public AggregationConcreteHandle {

inline void iterateUnaryInl(const TypedValue &value,
std::uint8_t *byte_ptr) const {
DCHECK(value.isPlausibleInstanceOf(argument_type_.getSignature()));
if (value.isNull()) return;
// DCHECK(value.isPlausibleInstanceOf(argument_type_.getSignature()));
// TODO(refactor-type): fix signature.
if (value.isNull()) return;
TypedValue *sum_ptr =
reinterpret_cast<TypedValue *>(byte_ptr + blank_state_.sum_offset_);
std::int64_t *count_ptr =
Expand Down
6 changes: 4 additions & 2 deletions expressions/aggregation/AggregationHandleMax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@ class AggregationHandleMax : public AggregationConcreteHandle {

inline void iterateUnaryInl(AggregationStateMax *state,
const TypedValue &value) const {
DCHECK(value.isPlausibleInstanceOf(type_.getSignature()));
// DCHECK(value.isPlausibleInstanceOf(type_.getSignature()));
// TODO(refactor-type): fix signature.
compareAndUpdate(static_cast<AggregationStateMax *>(state), value);
}

inline void iterateUnaryInl(const TypedValue &value,
std::uint8_t *byte_ptr) const {
DCHECK(value.isPlausibleInstanceOf(type_.getSignature()));
// DCHECK(value.isPlausibleInstanceOf(type_.getSignature()));
// TODO(refactor-type): fix signature.
TypedValue *max_ptr = reinterpret_cast<TypedValue *>(byte_ptr);
compareAndUpdate(max_ptr, value);
}
Expand Down
6 changes: 4 additions & 2 deletions expressions/aggregation/AggregationHandleMin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ class AggregationHandleMin : public AggregationConcreteHandle {

inline void iterateUnaryInl(AggregationStateMin *state,
const TypedValue &value) const {
DCHECK(value.isPlausibleInstanceOf(type_.getSignature()));
// DCHECK(value.isPlausibleInstanceOf(type_.getSignature()));
// TODO(refactor-type): fix signature.
compareAndUpdate(state, value);
}

inline void iterateUnaryInl(const TypedValue &value,
std::uint8_t *byte_ptr) const {
DCHECK(value.isPlausibleInstanceOf(type_.getSignature()));
// DCHECK(value.isPlausibleInstanceOf(type_.getSignature()));
// TODO(refactor-type): fix signature.
TypedValue *min_ptr = reinterpret_cast<TypedValue *>(byte_ptr);
compareAndUpdate(min_ptr, value);
}
Expand Down
11 changes: 5 additions & 6 deletions expressions/aggregation/AggregationHandleSum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
#include "types/TypeFactory.hpp"
#include "types/TypeID.hpp"
#include "types/TypedValue.hpp"
#include "types/operations/OperationFactory.hpp"
#include "types/operations/binary_operations/BinaryOperation.hpp"
#include "types/operations/binary_operations/BinaryOperationFactory.hpp"
#include "types/operations/binary_operations/BinaryOperationID.hpp"

#include "glog/logging.h"

Expand Down Expand Up @@ -68,12 +67,12 @@ AggregationHandleSum::AggregationHandleSum(const Type &type)
// Make operators to do arithmetic:
// Add operator for summing argument values.
fast_operator_.reset(
BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd)
.makeUncheckedBinaryOperatorForTypes(sum_type, argument_type_));
OperationFactory::GetAddOperation(type_precision_id, argument_type_.getTypeID())
->makeUncheckedBinaryOperator(sum_type, argument_type_));
// Add operator for merging states.
merge_operator_.reset(
BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd)
.makeUncheckedBinaryOperatorForTypes(sum_type, sum_type));
OperationFactory::GetAddOperation(type_precision_id, type_precision_id)
->makeUncheckedBinaryOperator(sum_type, sum_type));

// Result is nullable, because SUM() over 0 values (or all NULL values) is
// NULL.
Expand Down
7 changes: 5 additions & 2 deletions expressions/aggregation/AggregationHandleSum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ class AggregationHandleSum : public AggregationConcreteHandle {

inline void iterateUnaryInl(AggregationStateSum *state,
const TypedValue &value) const {
DCHECK(value.isPlausibleInstanceOf(argument_type_.getSignature()));
// DCHECK(value.isPlausibleInstanceOf(argument_type_.getSignature()));
// TODO(refactor-type): fix signature.
if (value.isNull()) return;

SpinMutexLock lock(state->mutex_);
Expand All @@ -123,8 +124,10 @@ class AggregationHandleSum : public AggregationConcreteHandle {

inline void iterateUnaryInl(const TypedValue &value,
std::uint8_t *byte_ptr) const {
DCHECK(value.isPlausibleInstanceOf(argument_type_.getSignature()));
// DCHECK(value.isPlausibleInstanceOf(argument_type_.getSignature()));
// TODO(refactor-type): fix signature.
if (value.isNull()) return;

TypedValue *sum_ptr =
reinterpret_cast<TypedValue *>(byte_ptr + blank_state_.sum_offset_);
bool *null_ptr =
Expand Down
Loading