Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TColumnValueUtil.java
Go to the documentation of this file.
1 // Copyright 2014 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.util;
16 
17 import com.cloudera.impala.thrift.TColumnValue;
18 
22 public class TColumnValueUtil {
26  public static double getNumericVal(TColumnValue val) {
27  if (val.isSetByte_val()) {
28  return (double) val.byte_val;
29  } else if (val.isSetShort_val()) {
30  return (double) val.short_val;
31  } else if (val.isSetInt_val()) {
32  return (double) val.int_val;
33  } else if (val.isSetLong_val()) {
34  return (double) val.long_val;
35  } else if (val.isSetDouble_val()) {
36  return (double) val.double_val;
37  } else if (val.isSetString_val()) {
38  // we always return decimals as strings, even with as_ascii=false
39  // in Expr::GetValue()
40  try {
41  return Double.valueOf(val.string_val);
42  } catch (NumberFormatException e) {
43  return 0;
44  }
45  }
46  return 0;
47  }
48 }
static double getNumericVal(TColumnValue val)