Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
HdfsPartitionTest.java
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 package com.cloudera.impala.catalog;
16 
17 import static org.junit.Assert.assertTrue;
18 
19 import java.math.BigDecimal;
20 import java.util.List;
21 import java.lang.*;
22 
23 import com.cloudera.impala.analysis.*;
24 import com.google.common.collect.Lists;
25 import org.junit.Test;
26 
27 import static com.cloudera.impala.catalog.HdfsPartition.comparePartitionKeyValues;
28 
29 public class HdfsPartitionTest {
30 
31  private List<LiteralExpr> valuesNull_= Lists.newArrayList();
32  private List<LiteralExpr> valuesDecimal_ = Lists.newArrayList();
33  private List<LiteralExpr> valuesDecimal1_ = Lists.newArrayList();
34  private List<LiteralExpr> valuesDecimal2_ = Lists.newArrayList();
35  private List<LiteralExpr> valuesMixed_= Lists.newArrayList();
36  private List<LiteralExpr> valuesMixed1_ = Lists.newArrayList();
37  private List<LiteralExpr> valuesMixed2_ = Lists.newArrayList();
38 
39  public HdfsPartitionTest() {
40  valuesNull_.add(NullLiteral.create(Type.BIGINT));
41 
42  valuesDecimal_.add(new NumericLiteral(BigDecimal.valueOf(1)));
43  valuesDecimal1_.add(new NumericLiteral(BigDecimal.valueOf(3)));
44  valuesDecimal2_.add(new NumericLiteral(BigDecimal.valueOf(5)));
45 
46  valuesMixed_.add(new NumericLiteral(BigDecimal.valueOf(3)));
47  valuesMixed_.add(NullLiteral.create(Type.BIGINT));
48 
49  valuesMixed1_.add(new NumericLiteral(BigDecimal.valueOf(1)));
50  valuesMixed1_.add(NullLiteral.create(Type.STRING));
51  valuesMixed1_.add(new BoolLiteral(true));
52 
53  valuesMixed2_.add(new NumericLiteral(BigDecimal.valueOf(1)));
54  valuesMixed2_.add(new StringLiteral("Large"));
55  valuesMixed2_.add(new BoolLiteral(false));
56  }
57 
58  @Test
59  public void testCompare() {
60  List< List<LiteralExpr> > allLists = Lists.newArrayList();
61  allLists.add(valuesNull_);
62  allLists.add(valuesDecimal_);
63  allLists.add(valuesDecimal1_);
64  allLists.add(valuesDecimal2_);
65  allLists.add(valuesMixed_);
66  allLists.add(valuesMixed1_);
67  allLists.add(valuesMixed2_);
68 
69  for (List<LiteralExpr> l1: allLists) {
70  verifyReflexive(l1);
71  for (List<LiteralExpr> l2: allLists) {
72  verifySymmetric(l1, l2);
73  for (List<LiteralExpr> l3: allLists) {
74  verifyTransitive(l1, l2, l3);
75  }
76  }
77  }
78 
79  List<LiteralExpr> valuesTest = Lists.newArrayList();
80  valuesTest.add(new NumericLiteral(BigDecimal.valueOf(3)));
82  valuesTest.add(NullLiteral.create(Type.BIGINT));
84  }
85 
86  private void verifySymmetric(List<LiteralExpr> o1, List<LiteralExpr> o2) {
87  // sgn(compare(x, y)) == -sgn(compare(y, x)),
88  // compare(x, y) == 0, then compare(y, x) == 0
89  assertTrue(Integer.signum(comparePartitionKeyValues(o1, o2)) ==
90  -Integer.signum(comparePartitionKeyValues(o2, o1)));
91  }
92  private void verifyTransitive(List<LiteralExpr> o1, List<LiteralExpr> o2,
93  List<LiteralExpr> o3) {
94  // ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0
95  if ((comparePartitionKeyValues(o1, o2) > 0) &&
96  (comparePartitionKeyValues(o2, o3) > 0)) {
97  assertTrue(comparePartitionKeyValues(o1, o3) > 0);
98  }
99  }
100  private void verifyReflexive(List<LiteralExpr> o1) {
101  // (compare(x, x)==0) is always true
102  assertTrue(comparePartitionKeyValues(o1, o1) == 0);
103  }
104  private void verifyAntiSymmetric(List<LiteralExpr> o1, List<LiteralExpr> o2,
105  List<LiteralExpr> o3) {
106  // compare(x, y)==0 implies that sgn(compare(x, z))==sgn(compare(y, z)) for all z.
107  if (comparePartitionKeyValues(o1, o2) == 0) {
108  assertTrue(Integer.signum(comparePartitionKeyValues(o1, o3)) ==
109  Integer.signum(comparePartitionKeyValues(o2, o3)));
110  }
111  }
112 }
static final ScalarType BIGINT
Definition: Type.java:50
static final ScalarType STRING
Definition: Type.java:53
void verifyAntiSymmetric(List< LiteralExpr > o1, List< LiteralExpr > o2, List< LiteralExpr > o3)
uint64_t Test(T *ht, const ProbeTuple *input, uint64_t num_tuples)
void verifyTransitive(List< LiteralExpr > o1, List< LiteralExpr > o2, List< LiteralExpr > o3)
void verifySymmetric(List< LiteralExpr > o1, List< LiteralExpr > o2)