Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
anyval-util.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 "exprs/anyval-util.h"
16 #include "codegen/llvm-codegen.h"
17 
18 #include "common/object-pool.h"
19 
20 #include "common/names.h"
21 
22 using namespace impala_udf;
23 
24 namespace impala {
25 
27  return pool->Add(CreateAnyVal(type));
28 }
29 
31  switch(type.type) {
32  case TYPE_NULL: return new AnyVal;
33  case TYPE_BOOLEAN: return new BooleanVal;
34  case TYPE_TINYINT: return new TinyIntVal;
35  case TYPE_SMALLINT: return new SmallIntVal;
36  case TYPE_INT: return new IntVal;
37  case TYPE_BIGINT: return new BigIntVal;
38  case TYPE_FLOAT: return new FloatVal;
39  case TYPE_DOUBLE: return new DoubleVal;
40  case TYPE_STRING:
41  case TYPE_VARCHAR:
42  case TYPE_CHAR:
43  return new StringVal;
44  case TYPE_TIMESTAMP: return new TimestampVal;
45  case TYPE_DECIMAL: return new DecimalVal;
46  default:
47  DCHECK(false) << "Unsupported type: " << type;
48  return NULL;
49  }
50 }
51 
52 FunctionContext::TypeDesc AnyValUtil::ColumnTypeToTypeDesc(const ColumnType& type) {
54  switch (type.type) {
55  case TYPE_BOOLEAN:
57  break;
58  case TYPE_TINYINT:
60  break;
61  case TYPE_SMALLINT:
63  break;
64  case TYPE_INT:
66  break;
67  case TYPE_BIGINT:
69  break;
70  case TYPE_FLOAT:
72  break;
73  case TYPE_DOUBLE:
75  break;
76  case TYPE_TIMESTAMP:
78  break;
79  case TYPE_VARCHAR:
81  out.len = type.len;
82  break;
83  case TYPE_STRING:
85  break;
86  case TYPE_CHAR:
88  out.len = type.len;
89  break;
90  case TYPE_DECIMAL:
92  out.precision = type.precision;
93  out.scale = type.scale;
94  break;
95  default:
96  DCHECK(false) << "Unknown type: " << type;
97  }
98  return out;
99 }
100 
101 ColumnType AnyValUtil::TypeDescToColumnType(const FunctionContext::TypeDesc& type) {
102  switch (type.type) {
113  return ColumnType::CreateDecimalType(type.precision, type.scale);
115  return ColumnType::CreateCharType(type.len);
117  return ColumnType::CreateVarcharType(type.len);
118  default:
119  DCHECK(false) << "Unknown type: " << type.type;
120  return ColumnType(INVALID_TYPE);
121  }
122 }
123 
124 }
int precision
Only valid if type == TYPE_DECIMAL.
Definition: udf.h:75
int precision
Only set if type == TYPE_DECIMAL.
Definition: types.h:68
This object has a compatible storage format with boost::ptime.
Definition: udf.h:495
PrimitiveType type
Definition: types.h:60
ObjectPool pool
int len
Only set if type == TYPE_CHAR or type == TYPE_VARCHAR.
Definition: types.h:62
int len
Only valid if type == TYPE_FIXED_BUFFER || type == TYPE_VARCHAR.
Definition: udf.h:79
AnyVal * CreateAnyVal(const ColumnType &type)
Creates the corresponding AnyVal subclass for type. The object is owned by the caller.
Definition: anyval-util.cc:30