quickstep-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shix...@apache.org
Subject incubator-quickstep git commit: Added unittest
Date Fri, 01 Jul 2016 20:12:40 GMT
Repository: incubator-quickstep
Updated Branches:
  refs/heads/SQL-window-aggregation e17b35477 -> 7242806e7


Added unittest


Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/7242806e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/7242806e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/7242806e

Branch: refs/heads/SQL-window-aggregation
Commit: 7242806e753e262bc5016c8ff05040f5dbd1c053
Parents: e17b354
Author: shixuan-fan <shixuan@apache.org>
Authored: Fri Jul 1 20:12:13 2016 +0000
Committer: shixuan-fan <shixuan@apache.org>
Committed: Fri Jul 1 20:12:13 2016 +0000

----------------------------------------------------------------------
 .../tests/execution_generator/Select.test       | 39 +++++++++
 storage/CMakeLists.txt                          | 12 +++
 ...WindowAggregationOperationState_unittest.cpp | 91 ++++++++++++++++++++
 3 files changed, 142 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/7242806e/query_optimizer/tests/execution_generator/Select.test
----------------------------------------------------------------------
diff --git a/query_optimizer/tests/execution_generator/Select.test b/query_optimizer/tests/execution_generator/Select.test
index 05f7108..16127cc 100644
--- a/query_optimizer/tests/execution_generator/Select.test
+++ b/query_optimizer/tests/execution_generator/Select.test
@@ -950,3 +950,42 @@ WHERE double_col < 0
 +--------------------+
 |                   5|
 +--------------------+
+==
+
+# Window Aggregation Test.
+# Currently this is not supported, an empty table will be returned.
+SELECT avg(int_col) OVER w FROM test
+WINDOW w AS
+(PARTITION BY char_col
+ ORDER BY long_col DESC NULLS LAST
+ ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW);
+--
++------------------------+
+|avg(int_col)            |
++------------------------+
++------------------------+
+==
+
+SELECT int_col, sum(float_col) OVER
+(PARTITION BY char_col, long_col
+ ORDER BY double_col DESC NULLS LAST, int_col ASC NULLS FIRST
+ RANGE BETWEEN 3 PRECEDING AND 3 FOLLOWING)
+FROM test;
+--
++-----------+------------------------+
+|int_col    |sum(float_col)          |
++-----------+------------------------+
++-----------+------------------------+
+==
+
+SELECT sum(avg(int_col) OVER w) FROM test
+WINDOW w AS
+(PARTITION BY char_col
+ ORDER BY long_col
+ ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW);
+--
++------------------------+
+|sum(avg(int_col))       |
++------------------------+
+|                    NULL|
++------------------------+

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/7242806e/storage/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/storage/CMakeLists.txt b/storage/CMakeLists.txt
index 47262a1..9df66e1 100644
--- a/storage/CMakeLists.txt
+++ b/storage/CMakeLists.txt
@@ -1667,6 +1667,18 @@ target_link_libraries(StorageManager_unittest
                       quickstep_storage_StorageBlockInfo
                       quickstep_storage_StorageManager
                       quickstep_utility_ShardedLockManager)
+
+add_executable(WindowAggregationOperationState_unittest
+               "${CMAKE_CURRENT_SOURCE_DIR}/tests/WindowAggregationOperationState_unittest.cpp")
+target_link_libraries(WindowAggregationOperationState_unittest
+                      gtest
+                      gtest_main
+                      quickstep_catalog_CatalogDatabase
+                      quickstep_catalog_CatalogRelation
+                      quickstep_catalog_CatalogTypedefs
+                      quickstep_storage_WindowAggregationOperationState
+                      quickstep_storage_WindowAggregationOperationState_proto
+                      ${LIBS})
 if (QUICKSTEP_HAVE_LIBNUMA)
   target_link_libraries(StorageManager_unittest
                         ${LIBNUMA_LIBRARY})

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/7242806e/storage/tests/WindowAggregationOperationState_unittest.cpp
----------------------------------------------------------------------
diff --git a/storage/tests/WindowAggregationOperationState_unittest.cpp b/storage/tests/WindowAggregationOperationState_unittest.cpp
new file mode 100644
index 0000000..81ce47d
--- /dev/null
+++ b/storage/tests/WindowAggregationOperationState_unittest.cpp
@@ -0,0 +1,91 @@
+/**
+ *   Copyright 2011-2015 Quickstep Technologies LLC.
+ *   Copyright 2015-2016 Pivotal Software, Inc.
+ *   Copyright 2016, Quickstep Research Group, Computer Sciences Department,
+ *     University of Wisconsin—Madison.
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ **/
+
+#include <cstddef>
+#include <memory>
+
+#include "catalog/CatalogDatabase.hpp"
+#include "catalog/CatalogRelation.hpp"
+#include "catalog/CatalogTypedefs.hpp"
+#include "expressions/aggregation/AggregateFunction.pb.h"
+#include "storage/WindowAggregationOperationState.hpp"
+#include "storage/WindowAggregationOperationState.pb.h"
+
+#include "gtest/gtest.h"
+
+using std::unique_ptr;
+
+namespace quickstep {
+
+class WindowAggregationOperationStateProtoTest : public ::testing::Test {
+ protected:
+  static const relation_id kInvalidTableId = 100;
+  static const std::int64_t kInvalidNum = -10;
+  static const std::int64_t kValidNum = 10;
+
+  virtual void SetUp() {
+    database_.reset(new CatalogDatabase(nullptr, "db"));
+    rel_id_ = database_->addRelation(new CatalogRelation(nullptr, "rel"));
+  }
+
+  unique_ptr<CatalogDatabase> database_;
+  relation_id rel_id_;
+};
+
+TEST_F(WindowAggregationOperationStateProtoTest, UninitializationTest) {
+  serialization::WindowAggregationOperationState proto;
+  EXPECT_FALSE(WindowAggregationOperationState::ProtoIsValid(proto, *database_.get()));
+}
+
+TEST_F(WindowAggregationOperationStateProtoTest, InvalidRelationIdTest) {
+  serialization::WindowAggregationOperationState proto;
+  proto.set_relation_id(kInvalidTableId);
+  proto.mutable_function()->set_aggregation_id(serialization::AggregateFunction::AVG);
+  proto.set_is_row(true);
+  proto.set_num_preceding(kValidNum);
+  proto.set_num_following(kValidNum);
+  EXPECT_FALSE(WindowAggregationOperationState::ProtoIsValid(proto, *database_.get()));
+}
+
+TEST_F(WindowAggregationOperationStateProtoTest, InvalidNumTest) {
+  serialization::WindowAggregationOperationState proto;
+  proto.set_relation_id(rel_id_);
+  proto.mutable_function()->set_aggregation_id(serialization::AggregateFunction::AVG);
+  proto.set_is_row(true);
+  proto.set_num_preceding(kInvalidNum);
+  proto.set_num_following(kValidNum);
+  EXPECT_FALSE(WindowAggregationOperationState::ProtoIsValid(proto, *database_.get()));
+
+  proto.set_num_preceding(kValidNum);
+  proto.set_num_following(kInvalidNum);
+  EXPECT_FALSE(WindowAggregationOperationState::ProtoIsValid(proto, *database_.get()));
+}
+
+TEST_F(WindowAggregationOperationStateProtoTest, ValidTest) {
+  serialization::WindowAggregationOperationState proto;
+  proto.set_relation_id(rel_id_);
+  proto.mutable_function()->set_aggregation_id(serialization::AggregateFunction::AVG);
+  proto.set_is_row(true);
+  proto.set_num_preceding(kValidNum);
+  proto.set_num_following(kValidNum);
+  EXPECT_TRUE(WindowAggregationOperationState::ProtoIsValid(proto, *database_.get()));
+}
+
+}  // namespace quickstep
+


Mime
View raw message