Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ExprTest.java
Go to the documentation of this file.
1 // Copyright 2013 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.analysis;
16 
17 import static org.junit.Assert.fail;
18 
19 import org.junit.Test;
20 
23 
24 
25 public class ExprTest {
26  // Test creation of LiteralExprs from Strings, e.g., for partitioning keys.
27  @Test
28  public void TestLiteralExpr() {
38 
39  // INVALID_TYPE should always fail
41 
42  // Invalid casts
52 
53  // Date types not implemented
54  testLiteralExprNegative("2010-01-01", Type.DATE);
55  testLiteralExprNegative("2010-01-01", Type.DATETIME);
56  testLiteralExprNegative("2010-01-01", Type.TIMESTAMP);
57  }
58 
59  private void testLiteralExprPositive(String value, Type type) {
60  LiteralExpr expr = null;
61  try {
62  expr = LiteralExpr.create(value, type);
63  } catch (Exception e) {
64  fail("\nFailed to create LiteralExpr of type: " + type.toString() + " from: " + value
65  + " due to " + e.getMessage() + "\n");
66  }
67  if (expr == null) {
68  fail("\nFailed to create LiteralExpr\n");
69  }
70  }
71 
72  private void testLiteralExprNegative(String value, Type type) {
73  boolean failure = false;
74  LiteralExpr expr = null;
75  try {
76  expr = LiteralExpr.create(value, type);
77  } catch (Exception e) {
78  failure = true;
79  }
80  if (expr == null) {
81  failure = true;
82  }
83  if (!failure) {
84  fail("\nUnexpectedly succeeded to create LiteralExpr of type: "
85  + type.toString() + " from: " + value + "\n");
86  }
87  }
88 }
static final ScalarType BIGINT
Definition: Type.java:50
static final ScalarType DATE
Definition: Type.java:56
static final ScalarType STRING
Definition: Type.java:53
static final ScalarType BOOLEAN
Definition: Type.java:46
static final ScalarType SMALLINT
Definition: Type.java:48
static final ScalarType FLOAT
Definition: Type.java:51
void testLiteralExprPositive(String value, Type type)
Definition: ExprTest.java:59
static final ScalarType DOUBLE
Definition: Type.java:52
static final ScalarType TINYINT
Definition: Type.java:47
static final ScalarType INT
Definition: Type.java:49
uint64_t Test(T *ht, const ProbeTuple *input, uint64_t num_tuples)
void testLiteralExprNegative(String value, Type type)
Definition: ExprTest.java:72
static final ScalarType DATETIME
Definition: Type.java:57
static final ScalarType INVALID
Definition: Type.java:44
static final ScalarType TIMESTAMP
Definition: Type.java:55