Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
incr-stats-util-test.cc
Go to the documentation of this file.
1 // Copyright 2014 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <gtest/gtest.h>
16 #include <string>
17 #include <limits>
18 #include <cmath>
19 
20 #include "common/logging.h"
22 
23 #include "common/names.h"
24 
25 using namespace impala;
26 
27 extern string EncodeNdv(const string& ndv, bool* is_encoded);
28 extern string DecodeNdv(const string& ndv, bool is_encoded);
29 
30 static const int HLL_LEN = pow(2, AggregateFunctions::HLL_PRECISION);
31 
32 TEST(RleTest, TestEmptyRle) {
33  string test(HLL_LEN, 0);
34 
35  bool is_encoded;
36  const string& encoded = EncodeNdv(test, &is_encoded);
37  ASSERT_EQ(8, encoded.size());
38  ASSERT_TRUE(is_encoded);
39 
40  const string& decoded = DecodeNdv(encoded, is_encoded);
41  ASSERT_EQ(HLL_LEN, decoded.size());
42  ASSERT_EQ(test, decoded);
43 }
44 
45 TEST(RleTest, TestNoEncode) {
46  string test;
47  for (int i = 0; i < HLL_LEN; ++i) {
48  test += (i % 2 == 0) ? 'A' : 'B';
49  }
50 
51  bool is_encoded;
52  const string& encoded = EncodeNdv(test, &is_encoded);
53  ASSERT_FALSE(is_encoded);
54  ASSERT_EQ(encoded, test);
55 
56  ASSERT_EQ(DecodeNdv(encoded, is_encoded), test);
57 }
58 
59 TEST(RleTest, TestEncode) {
60  string test;
61  for (int i = 0; i < HLL_LEN; ++i) {
62  test += (i < 512) ? 'A' : 'B';
63  }
64 
65  bool is_encoded;
66  const string& encoded = EncodeNdv(test, &is_encoded);
67  ASSERT_EQ(8, encoded.size());
68  ASSERT_TRUE(is_encoded);
69  ASSERT_EQ(DecodeNdv(encoded, is_encoded), test);
70 }
71 
72 
73 int main(int argc, char** argv) {
74  //InitCommonRuntime(argc, argv, true);
75  ::testing::InitGoogleTest(&argc, argv);
76  return RUN_ALL_TESTS();
77 }
int main(int argc, char **argv)
string DecodeNdv(const string &ndv, bool is_encoded)
TEST(AtomicTest, Basic)
Definition: atomic-test.cc:28
static const int HLL_LEN
string EncodeNdv(const string &ndv, bool *is_encoded)