Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
parquet-version-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 <stdlib.h>
16 #include <stdio.h>
17 #include <iostream>
18 #include <limits.h>
19 #include <gtest/gtest.h>
21 
22 #include "common/names.h"
23 
24 namespace impala {
25 
26 void CheckVersionParse(const string& s, const string& expected_application,
27  int expected_major, int expected_minor, int expected_patch,
28  bool expected_is_internal) {
30  EXPECT_EQ(v.application, expected_application) << "String: " << s;
31  EXPECT_EQ(v.version.major, expected_major) << "String: " << s;
32  EXPECT_EQ(v.version.minor, expected_minor) << "String: " << s;
33  EXPECT_EQ(v.version.patch, expected_patch) << "String: " << s;
34  EXPECT_EQ(v.is_impala_internal, expected_is_internal);
35 }
36 
37 TEST(ParquetVersionTest, Parsing) {
38  CheckVersionParse("impala version 1.0", "impala", 1, 0, 0, false);
39  CheckVersionParse("impala VERSION 1.0", "impala", 1, 0, 0, false);
40  CheckVersionParse("impala VERSION 1.0 ignored", "impala", 1, 0, 0, false);
41  CheckVersionParse("parquet-mr version 2.0", "parquet-mr", 2, 0, 0, false);
42 
43  CheckVersionParse("impala version 1.2", "impala", 1, 2, 0, false);
44  CheckVersionParse("impala version 1.2.3", "impala", 1, 2, 3, false);
45  CheckVersionParse("impala version 1.2.3-cdh4.5", "impala", 1, 2, 3, false);
46  CheckVersionParse("impala version 1.2.3.cdh4.5", "impala", 1, 2, 3, false);
47  CheckVersionParse("impala version 1.2-cdh4.5", "impala", 1, 2, 0, false);
48  CheckVersionParse("impala version 1.2.cdh4.5", "impala", 1, 2, 0, false);
49  CheckVersionParse("impala version 1.2 (build xyz)", "impala", 1, 2, 0, false);
50  CheckVersionParse("impala version cdh4.5", "impala", 0, 0, 0, false);
51 
52  // Test internal versions
53  CheckVersionParse("impala version 1.0-internal", "impala", 1, 0, 0, true);
54  CheckVersionParse("impala version 1.23-internal", "impala", 1, 23, 0, true);
55  CheckVersionParse("impala version 2-inTERnal", "impala", 2, 0, 0, true);
56  CheckVersionParse("mr version 1-internal", "mr", 1, 0, 0, false);
57 
58  // Test some malformed strings.
59  CheckVersionParse("parquet-mr 2.0", "parquet-mr", 0, 0, 0, false);
60  CheckVersionParse("impala ve 2.0", "impala", 0, 0, 0, false);
61  CheckVersionParse("", "", 0, 0, 0, false);
62 }
63 
64 TEST(ParquetVersionTest, Comparisons) {
65  HdfsParquetScanner::FileVersion v("foo version 1.2.3");
66  EXPECT_TRUE(v.VersionEq(1, 2, 3));
67  EXPECT_FALSE(v.VersionEq(1, 2, 4));
68  EXPECT_TRUE(v.VersionLt(3, 2, 1));
69  EXPECT_TRUE(v.VersionLt(1, 2, 4));
70  EXPECT_TRUE(v.VersionLt(2, 0, 0));
71  EXPECT_FALSE(v.VersionLt(0, 0, 0));
72  EXPECT_FALSE(v.VersionLt(1, 2, 3));
73  EXPECT_FALSE(v.VersionLt(1, 2, 2));
74  EXPECT_FALSE(v.VersionLt(0, 4, 4));
75 }
76 
77 }
78 
79 int main(int argc, char **argv) {
81  ::testing::InitGoogleTest(&argc, argv);
82  return RUN_ALL_TESTS();
83 }
bool VersionEq(int major, int minor, int patch) const
Returns true if version is equal to <major>.<minor>.<patch>
TEST(AtomicTest, Basic)
Definition: atomic-test.cc:28
void CheckVersionParse(const string &s, const string &expected_application, int expected_major, int expected_minor, int expected_patch, bool expected_is_internal)
std::string application
Application that wrote the file. e.g. "IMPALA".
struct impala::HdfsParquetScanner::FileVersion::@7 version
static void Init()
Initialize CpuInfo.
Definition: cpu-info.cc:75
bool is_impala_internal
If true, this file was generated by an Impala internal release.
int main(int argc, char **argv)
bool VersionLt(int major, int minor=0, int patch=0) const
Returns true if version is strictly less than <major>.<minor>.<patch>