You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by sh...@apache.org on 2016/07/12 04:53:23 UTC
incubator-quickstep git commit: Fixed SegFault
Repository: incubator-quickstep
Updated Branches:
refs/heads/SQL-window-aggregation d5f535ee9 -> 897ffc6db
Fixed SegFault
Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/897ffc6d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/897ffc6d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/897ffc6d
Branch: refs/heads/SQL-window-aggregation
Commit: 897ffc6db0e177caf73131b39c80d6d077087c8e
Parents: d5f535e
Author: shixuan-fan <sh...@apache.org>
Authored: Tue Jul 12 04:54:20 2016 +0000
Committer: shixuan-fan <sh...@apache.org>
Committed: Tue Jul 12 04:54:20 2016 +0000
----------------------------------------------------------------------
expressions/window_aggregation/CMakeLists.txt | 32 ++++++++--
.../WindowAggregationHandle.hpp | 2 +-
.../WindowAggregationHandleAvg.cpp | 67 +++++++++++++-------
.../WindowAggregationHandleAvg.hpp | 2 +-
storage/WindowAggregationOperationState.cpp | 2 +
5 files changed, 74 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/897ffc6d/expressions/window_aggregation/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/CMakeLists.txt b/expressions/window_aggregation/CMakeLists.txt
index fa4eae9..5e46d08 100644
--- a/expressions/window_aggregation/CMakeLists.txt
+++ b/expressions/window_aggregation/CMakeLists.txt
@@ -44,23 +44,21 @@ add_library(quickstep_expressions_windowaggregation_WindowAggregationID
# Link dependencies:
target_link_libraries(quickstep_expressions_windowaggregation_WindowAggregateFunction
glog
+ quickstep_catalog_CatalogTypedefs
quickstep_expressions_windowaggregation_WindowAggregateFunction_proto
quickstep_expressions_windowaggregation_WindowAggregationID
- quickstep_utility_Macros)
-target_link_libraries(quickstep_expressions_windowaggregation_WindowAggregationHandle
- glog
- quickstep_catalog_CatalogTypedefs
- quickstep_storage_HashTableBase
- quickstep_types_TypedValue
+ quickstep_storage_StorageBlockInfo
quickstep_utility_Macros)
target_link_libraries(quickstep_expressions_windowaggregation_WindowAggregateFunction_proto
${PROTOBUF_LIBRARY})
target_link_libraries(quickstep_expressions_windowaggregation_WindowAggregateFunctionFactory
+ glog
quickstep_expressions_windowaggregation_WindowAggregateFunctionAvg
quickstep_expressions_windowaggregation_WindowAggregateFunction_proto
quickstep_expressions_windowaggregation_WindowAggregationID
quickstep_utility_Macros)
target_link_libraries(quickstep_expressions_windowaggregation_WindowAggregateFunctionAvg
+ glog
quickstep_expressions_windowaggregation_WindowAggregateFunction
quickstep_expressions_windowaggregation_WindowAggregationHandleAvg
quickstep_expressions_windowaggregation_WindowAggregationID
@@ -71,15 +69,35 @@ target_link_libraries(quickstep_expressions_windowaggregation_WindowAggregateFun
quickstep_types_operations_binaryoperations_BinaryOperationFactory
quickstep_types_operations_binaryoperations_BinaryOperationID
quickstep_utility_Macros)
+target_link_libraries(quickstep_expressions_windowaggregation_WindowAggregationHandle
+ glog
+ quickstep_catalog_CatalogRelationSchema
+ quickstep_catalog_CatalogTypedefs
+ quickstep_storage_StorageBlockInfo
+ quickstep_types_TypedValue
+ quickstep_utility_Macros)
target_link_libraries(quickstep_expressions_windowaggregation_WindowAggregationHandleAvg
+ glog
quickstep_catalog_CatalogTypedefs
+ quickstep_expressions_scalar_Scalar
+ quickstep_expressions_scalar_ScalarAttribute
quickstep_expressions_windowaggregation_WindowAggregationHandle
+ quickstep_storage_InsertDestinationInterface
+ quickstep_storage_StorageBlock
+ quickstep_storage_StorageManager
+ quickstep_storage_SubBlocksReference
+ quickstep_storage_TupleStorageSubBlock
+ quickstep_storage_ValueAccessor
+ quickstep_storage_ValueAccessorUtil
quickstep_types_Type
quickstep_types_TypeFactory
quickstep_types_TypeID
quickstep_types_TypedValue
- quickstep_types_containers_ColumnVector
+ quickstep_types_containers_ColumnVectorsValueAccessor
quickstep_types_operations_binaryoperations_BinaryOperation
quickstep_types_operations_binaryoperations_BinaryOperationFactory
quickstep_types_operations_binaryoperations_BinaryOperationID
+ quickstep_types_operations_comparisons_Comparison
+ quickstep_types_operations_comparisons_ComparisonFactory
+ quickstep_types_operations_comparisons_ComparisonID
quickstep_utility_Macros)
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/897ffc6d/expressions/window_aggregation/WindowAggregationHandle.hpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/WindowAggregationHandle.hpp b/expressions/window_aggregation/WindowAggregationHandle.hpp
index 6b7988a..4307007 100644
--- a/expressions/window_aggregation/WindowAggregationHandle.hpp
+++ b/expressions/window_aggregation/WindowAggregationHandle.hpp
@@ -105,7 +105,7 @@ class WindowAggregationHandle {
const std::int64_t num_following,
StorageManager *storage_manager) = 0;
- virtual std::vector<ValueAccessor*>&& finalize(StorageManager *storage_manager) = 0;
+ virtual std::vector<ValueAccessor*> finalize(StorageManager *storage_manager) = 0;
protected:
/**
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/897ffc6d/expressions/window_aggregation/WindowAggregationHandleAvg.cpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/WindowAggregationHandleAvg.cpp b/expressions/window_aggregation/WindowAggregationHandleAvg.cpp
index e6e2894..49523fb 100644
--- a/expressions/window_aggregation/WindowAggregationHandleAvg.cpp
+++ b/expressions/window_aggregation/WindowAggregationHandleAvg.cpp
@@ -121,13 +121,13 @@ void WindowAggregationHandleAvg::calculate(const std::vector<std::unique_ptr<con
tuple_accessors.push_back(tuple_accessor);
// Get argument accessor.
- ColumnVectorsValueAccessor argument_accessor;
+ ColumnVectorsValueAccessor *argument_accessor = new ColumnVectorsValueAccessor();
SubBlocksReference sub_block_ref(tuple_block,
block->getIndices(),
block->getIndicesConsistent());
- argument_accessor.addColumn(
+ argument_accessor->addColumn(
arguments.front()->getAllValues(tuple_accessor, &sub_block_ref));
- argument_accessors.push_back(&argument_accessor);
+ argument_accessors.push_back(argument_accessor);
}
// Create a window for each tuple and calculate the window aggregate.
@@ -137,8 +137,8 @@ void WindowAggregationHandleAvg::calculate(const std::vector<std::unique_ptr<con
ValueAccessor *tuple_accessor = tuple_accessors[current_block_index];
ColumnVectorsValueAccessor* argument_accessor =
argument_accessors[current_block_index];
- NativeColumnVector window_aggregates_for_block(*result_type_,
- argument_accessor->getNumTuples());
+ NativeColumnVector* window_aggregates_for_block =
+ new NativeColumnVector(*result_type_, argument_accessor->getNumTuples());
InvokeOnAnyValueAccessor (
tuple_accessor,
@@ -154,15 +154,15 @@ void WindowAggregationHandleAvg::calculate(const std::vector<std::unique_ptr<con
is_row,
num_preceding,
num_following);
- window_aggregates_for_block.appendTypedValue(window_aggregate);
+ window_aggregates_for_block->appendTypedValue(window_aggregate);
}
});
- window_aggregates_.push_back(&window_aggregates_for_block);
+ window_aggregates_.push_back(window_aggregates_for_block);
}
}
-std::vector<ValueAccessor*>&& WindowAggregationHandleAvg::finalize(
+std::vector<ValueAccessor*> WindowAggregationHandleAvg::finalize(
StorageManager *storage_manager) {
std::vector<ValueAccessor*> accessors;
@@ -170,25 +170,30 @@ std::vector<ValueAccessor*>&& WindowAggregationHandleAvg::finalize(
// attribute.
for (std::size_t block_idx = 0; block_idx < block_ids_.size(); ++block_idx) {
// Get the block information.
- BlockReference block = storage_manager->getBlock(block_idx, relation_);
+ BlockReference block = storage_manager->getBlock(block_ids_[block_idx],
+ relation_);
const TupleStorageSubBlock &tuple_block = block->getTupleStorageSubBlock();
ValueAccessor *block_accessor = tuple_block.createValueAccessor();
SubBlocksReference sub_block_ref(tuple_block,
block->getIndices(),
block->getIndicesConsistent());
- ColumnVectorsValueAccessor accessor;
+ ColumnVectorsValueAccessor* accessor = new ColumnVectorsValueAccessor();
+ // Add all attributes in the original relation.
for (CatalogRelationSchema::const_iterator attr_it = relation_.begin();
attr_it != relation_.end();
++attr_it) {
ScalarAttribute scalar_attr(*attr_it);
- accessor.addColumn(scalar_attr.getAllValues(block_accessor, &sub_block_ref));
+ accessor->addColumn(scalar_attr.getAllValues(block_accessor, &sub_block_ref));
}
- accessors.push_back(&accessor);
+ // Add the window aggregate attribute
+ accessor->addColumn(window_aggregates_[block_idx]);
+
+ accessors.push_back(accessor);
}
- return std::move(accessors);
+ return accessors;
}
TypedValue WindowAggregationHandleAvg::calculateOneWindow(
@@ -203,8 +208,14 @@ TypedValue WindowAggregationHandleAvg::calculateOneWindow(
ValueAccessor *tuple_accessor = tuple_accessors[current_block_index];
ColumnVectorsValueAccessor *argument_accessor = argument_accessors[current_block_index];
TypedValue sum = sum_type_->makeZeroValue();
+ TypedValue current_value = argument_accessor->getTypedValue(0);
+ // If current value is null, return null.
+ if (current_value.isNull()) {
+ return TypedValue(result_type_->getTypeID());
+ }
+
sum = fast_add_operator_->
- applyToTypedValues(sum, argument_accessor->getTypedValue(0));
+ applyToTypedValues(sum, current_value);
std::uint64_t count = 1;
// Get the partition key for the current row.
@@ -230,10 +241,10 @@ TypedValue WindowAggregationHandleAvg::calculateOneWindow(
// changed to "while".
if (preceding_tuple_id < 0) {
// First tuple of the first block, no more preceding blocks.
- preceding_block_index--;
- if (preceding_block_index < 0) {
+ if (preceding_block_index == 0) {
break;
}
+ preceding_block_index--;
tuple_accessor = tuple_accessors[preceding_block_index];
argument_accessor = argument_accessors[preceding_block_index];
@@ -252,9 +263,15 @@ TypedValue WindowAggregationHandleAvg::calculateOneWindow(
// Actually count the element and do the calculation.
count_preceding++;
- sum = fast_add_operator_->applyToTypedValues(
- sum,
- argument_accessor->getTypedValueAtAbsolutePosition(0, preceding_tuple_id));
+ TypedValue preceding_value =
+ argument_accessor->getTypedValueAtAbsolutePosition(0, preceding_tuple_id);
+
+ // If a null value is in the window, return a null value.
+ if (preceding_value.isNull()) {
+ return TypedValue(result_type_->getTypeID());
+ }
+
+ sum = fast_add_operator_->applyToTypedValues(sum, preceding_value);
}
count += count_preceding;
@@ -294,9 +311,15 @@ TypedValue WindowAggregationHandleAvg::calculateOneWindow(
// Actually count the element and do the calculation.
count_following++;
- sum = fast_add_operator_->applyToTypedValues(
- sum,
- argument_accessor->getTypedValueAtAbsolutePosition(0, following_tuple_id));
+ TypedValue following_value =
+ argument_accessor->getTypedValueAtAbsolutePosition(0, following_tuple_id);
+
+ // If a null value is in the window, return a null value.
+ if (following_value.isNull()) {
+ return TypedValue(result_type_->getTypeID());
+ }
+
+ sum = fast_add_operator_->applyToTypedValues(sum, following_value);
}
count += count_following;
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/897ffc6d/expressions/window_aggregation/WindowAggregationHandleAvg.hpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/WindowAggregationHandleAvg.hpp b/expressions/window_aggregation/WindowAggregationHandleAvg.hpp
index e0ec766..adb33e0 100644
--- a/expressions/window_aggregation/WindowAggregationHandleAvg.hpp
+++ b/expressions/window_aggregation/WindowAggregationHandleAvg.hpp
@@ -62,7 +62,7 @@ class WindowAggregationHandleAvg : public WindowAggregationHandle {
const std::int64_t num_following,
StorageManager *storage_manager);
- std::vector<ValueAccessor*>&& finalize(StorageManager *storage_manager);
+ std::vector<ValueAccessor*> finalize(StorageManager *storage_manager);
private:
friend class WindowAggregateFunctionAvg;
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/897ffc6d/storage/WindowAggregationOperationState.cpp
----------------------------------------------------------------------
diff --git a/storage/WindowAggregationOperationState.cpp b/storage/WindowAggregationOperationState.cpp
index 9029bd4..b3de423 100644
--- a/storage/WindowAggregationOperationState.cpp
+++ b/storage/WindowAggregationOperationState.cpp
@@ -202,8 +202,10 @@ void WindowAggregationOperationState::windowAggregateBlocks(
num_preceding_,
num_following_,
storage_manager_);
+
std::vector<ValueAccessor*> output_accessors(
window_aggregation_handle_->finalize(storage_manager_));
+
for (ValueAccessor* output_accessor : output_accessors) {
output_destination->bulkInsertTuples(output_accessor);
}