Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
raw-value-test.cc
Go to the documentation of this file.
1 // Copyright 2012 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 <sstream>
17 #include "runtime/raw-value.h"
18 
19 #include "common/names.h"
20 
21 using namespace impala;
22 
23 namespace impala {
24 
25 class RawValueTest : public testing::Test {
26 };
27 
28 TEST_F(RawValueTest, Compare) {
29  int64_t v1, v2;
30  v1 = -2128609280;
31  v2 = 9223372036854775807;
32  EXPECT_LT(RawValue::Compare(&v1, &v2, TYPE_BIGINT), 0);
33  EXPECT_GT(RawValue::Compare(&v2, &v1, TYPE_BIGINT), 0);
34 
35  int32_t i1, i2;
36  i1 = 2147483647;
37  i2 = -2147483640;
38  EXPECT_GT(RawValue::Compare(&i1, &i2, TYPE_INT), 0);
39  EXPECT_LT(RawValue::Compare(&i2, &i1, TYPE_INT), 0);
40 
41  int16_t s1, s2;
42  s1 = 32767;
43  s2 = -32767;
44  EXPECT_GT(RawValue::Compare(&s1, &s2, TYPE_SMALLINT), 0);
45  EXPECT_LT(RawValue::Compare(&s2, &s1, TYPE_SMALLINT), 0);
46 }
47 
48 TEST_F(RawValueTest, TypeChar) {
49  const int N = 5;
50  const char* v1 = "aaaaa";
51  const char* v2 = "aaaaab";
52  const char* v3 = "aaaab";
53 
54  EXPECT_EQ(RawValue::Compare(v1, v1, ColumnType::CreateCharType(N)), 0);
55  EXPECT_EQ(RawValue::Compare(v1, v2, ColumnType::CreateCharType(N)), 0);
56  EXPECT_LT(RawValue::Compare(v1, v3, ColumnType::CreateCharType(N)), 0);
57 
58  EXPECT_EQ(RawValue::Compare(v2, v1, ColumnType::CreateCharType(N)), 0);
59  EXPECT_EQ(RawValue::Compare(v2, v2, ColumnType::CreateCharType(N)), 0);
60  EXPECT_LT(RawValue::Compare(v2, v3, ColumnType::CreateCharType(N)), 0);
61 
62  EXPECT_GT(RawValue::Compare(v3, v1, ColumnType::CreateCharType(N)), 0);
63  EXPECT_GT(RawValue::Compare(v3, v2, ColumnType::CreateCharType(N)), 0);
64  EXPECT_EQ(RawValue::Compare(v3, v3, ColumnType::CreateCharType(N)), 0);
65 
66  // Try putting non-string data (multiple nulls, non-ascii) and make
67  // sure we can output it.
68  stringstream ss;
69  int val = 123;
70  RawValue::PrintValue(&val, ColumnType::CreateCharType(sizeof(int)), -1, &ss);
71  string s = ss.str();
72  EXPECT_EQ(s.size(), sizeof(int));
73  EXPECT_EQ(memcmp(&val, s.data(), sizeof(int)), 0);
74 }
75 
76 }
77 
78 int main(int argc, char **argv) {
79  google::InitGoogleLogging(argv[0]);
80  ::testing::InitGoogleTest(&argc, argv);
82  return RUN_ALL_TESTS();
83 }
static void PrintValue(const void *value, const ColumnType &type, int scale, std::stringstream *stream)
Definition: raw-value.h:224
TEST_F(InstructionCounterTest, Count)
static ColumnType CreateCharType(int len)
Definition: types.h:85
uint64_t Test(T *ht, const ProbeTuple *input, uint64_t num_tuples)
int main(int argc, char **argv)
static int Compare(const void *v1, const void *v2, const ColumnType &type)
Definition: raw-value.cc:109
static void Init()
Initialize CpuInfo.
Definition: cpu-info.cc:75