Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PrimitiveType.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 java.util.List;
18 
19 import com.cloudera.impala.thrift.TPrimitiveType;
20 import com.google.common.collect.Lists;
21 
22 public enum PrimitiveType {
23  INVALID_TYPE("INVALID_TYPE", -1, TPrimitiveType.INVALID_TYPE),
24  // NULL_TYPE - used only in LiteralPredicate and NullLiteral to make NULLs compatible
25  // with all other types.
26  NULL_TYPE("NULL_TYPE", 1, TPrimitiveType.NULL_TYPE),
27  BOOLEAN("BOOLEAN", 1, TPrimitiveType.BOOLEAN),
28  TINYINT("TINYINT", 1, TPrimitiveType.TINYINT),
29  SMALLINT("SMALLINT", 2, TPrimitiveType.SMALLINT),
30  INT("INT", 4, TPrimitiveType.INT),
31  BIGINT("BIGINT", 8, TPrimitiveType.BIGINT),
32  FLOAT("FLOAT", 4, TPrimitiveType.FLOAT),
33  DOUBLE("DOUBLE", 8, TPrimitiveType.DOUBLE),
34  DATE("DATE", 4, TPrimitiveType.DATE),
35  DATETIME("DATETIME", 8, TPrimitiveType.DATETIME),
36  // The timestamp structure is 12 bytes, Aligning to 8 bytes makes it 16.
37  TIMESTAMP("TIMESTAMP", 16, TPrimitiveType.TIMESTAMP),
38  // 8-byte pointer and 4-byte length indicator (12 bytes total).
39  // Aligning to 8 bytes so 16 total.
40  STRING("STRING", 16, TPrimitiveType.STRING),
41  VARCHAR("VARCHAR", 16, TPrimitiveType.VARCHAR),
42 
43  // Unsupported scalar type.
44  BINARY("BINARY", -1, TPrimitiveType.BINARY),
45 
46  // For decimal at the highest precision, the BE uses 16 bytes.
47  DECIMAL("DECIMAL", 16, TPrimitiveType.DECIMAL),
48 
49  // Fixed length char array.
50  CHAR("CHAR", -1, TPrimitiveType.CHAR);
51 
52  private final String description_;
53  private final int slotSize_; // size of tuple slot for this type
54  private final TPrimitiveType thriftType_;
55 
56  private PrimitiveType(String description, int slotSize, TPrimitiveType thriftType) {
57  description_ = description;
58  slotSize_ = slotSize;
59  thriftType_ = thriftType;
60  }
61 
62  @Override
63  public String toString() {
64  return description_;
65  }
66 
67  public static PrimitiveType fromThrift(TPrimitiveType t) {
68  switch (t) {
69  case INVALID_TYPE: return INVALID_TYPE;
70  case NULL_TYPE: return NULL_TYPE;
71  case BOOLEAN: return BOOLEAN;
72  case TINYINT: return TINYINT;
73  case SMALLINT: return SMALLINT;
74  case INT: return INT;
75  case BIGINT: return BIGINT;
76  case FLOAT: return FLOAT;
77  case DOUBLE: return DOUBLE;
78  case STRING: return STRING;
79  case VARCHAR: return VARCHAR;
80  case TIMESTAMP: return TIMESTAMP;
81  case CHAR: return CHAR;
82  case DECIMAL: return DECIMAL;
83  case BINARY: return BINARY;
84  }
85  return INVALID_TYPE;
86  }
87 
88  public TPrimitiveType toThrift() { return thriftType_; }
89 
90  public static List<TPrimitiveType> toThrift(PrimitiveType[] types) {
91  List<TPrimitiveType> result = Lists.newArrayList();
92  for (PrimitiveType t: types) {
93  result.add(t.toThrift());
94  }
95  return result;
96  }
97 
98  public int getSlotSize() { return slotSize_; }
99  public static int getMaxSlotSize() { return DECIMAL.slotSize_; }
100 }
static PrimitiveType fromThrift(TPrimitiveType t)
PrimitiveType(String description, int slotSize, TPrimitiveType thriftType)
static List< TPrimitiveType > toThrift(PrimitiveType[] types)