Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TypesUtilTest.java
Go to the documentation of this file.
1 // Copyright (c) 2012 Cloudera, Inc. All rights reserved.
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.analysis;
16 
17 import static org.junit.Assert.assertTrue;
18 
19 import org.junit.Test;
20 
24 
25 // TODO: move other types related tests into this class to break up the large
26 // AnalyzerTest files.
27 public class TypesUtilTest extends AnalyzerTest {
28 
29  private void verifyDecimalType(Type t1, Type t2) {
30  assertTrue(t1.getPrimitiveType() == PrimitiveType.DECIMAL);
31  assertTrue(t2.getPrimitiveType() == PrimitiveType.DECIMAL);
32  assertTrue(t1.equals(t2));
33  }
34 
35  @Test
36  // Tests to verify that we can compute the correct type for assignment.
44  ScalarType.createDecimalType(10, 2), ScalarType.createDecimalType(12, 2)),
45  ScalarType.createDecimalType(12, 2));
48  ScalarType.createDecimalType(10, 5), ScalarType.createDecimalType(12, 3)),
49  ScalarType.createDecimalType(14, 5));
52  ScalarType.createDecimalType(12, 2), ScalarType.createDecimalType(10, 2)),
53  ScalarType.createDecimalType(12, 2));
56  ScalarType.createDecimalType(12, 3), ScalarType.createDecimalType(10, 5)),
57  ScalarType.createDecimalType(14, 5));
60  ScalarType.createDecimalType(16, 5)),
61  ScalarType.createDecimalType(16, 5));
62 
63  // Decimal(10, 0) && Decimal(10, 0) --> Decimal(10, 0)
66  ScalarType.createDecimalType(), ScalarType.createDecimalType()),
67  ScalarType.createDecimalType());
68 
69  // decimal(10, 2) && decimal(12, 2) -> decimal(12, 2)
72  ScalarType.createDecimalType(10, 2), ScalarType.createDecimalType(12, 2)),
73  ScalarType.createDecimalType(12, 2));
74 
75 
76  // decimal (38, 38) && decimal(3, 0) -> decimal(38 , 38)
77  // In this case, since we only support 38 digits, there is no type (we'd
78  // need 41 digits). Return the best we can do.
81  ScalarType.createDecimalType(38, 38), ScalarType.createDecimalType(3)),
82  ScalarType.createDecimalType(38, 38));
83 
84  // Decimal(5,0) with Decimal(*,*) should be Decimal(5,0)
93  }
94 }
PrimitiveType getPrimitiveType()
Definition: Type.java:188
static ScalarType getDecimalAssignmentCompatibleType(ScalarType t1, ScalarType t2)
Definition: TypesUtil.java:70
static final ScalarType DEFAULT_DECIMAL
Definition: Type.java:58
PrimitiveType
Definition: types.h:27
uint64_t Test(T *ht, const ProbeTuple *input, uint64_t num_tuples)
static final ScalarType DECIMAL
Definition: Type.java:61