Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cast-functions.cc File Reference
#include "exprs/cast-functions.h"
#include <boost/lexical_cast.hpp>
#include "exprs/anyval-util.h"
#include "exprs/decimal-functions.h"
#include "runtime/timestamp-value.h"
#include "util/string-parser.h"
#include "string-functions.h"
#include "common/names.h"
Include dependency graph for cast-functions.cc:

Go to the source code of this file.

Macros

#define CAST_FUNCTION(from_type, to_type)
 
#define CAST_FROM_STRING(num_type, native_type, string_parser_fn)
 
#define CAST_TO_STRING(num_type)
 
#define CAST_FLOAT_TO_STRING(float_type, format)
 
#define CAST_FROM_TIMESTAMP(to_type)
 
#define CAST_FROM_SUBSECOND_TIMESTAMP(to_type)
 
#define CAST_TO_TIMESTAMP(from_type)
 

Functions

 CAST_TO_STRING (BooleanVal)
 
 CAST_TO_STRING (SmallIntVal)
 
 CAST_TO_STRING (IntVal)
 
 CAST_TO_STRING (BigIntVal)
 
 CAST_FLOAT_TO_STRING (FloatVal,"%.9g")
 
 CAST_FLOAT_TO_STRING (DoubleVal,"%.17g")
 
 CAST_FROM_TIMESTAMP (BooleanVal)
 
 CAST_FROM_TIMESTAMP (TinyIntVal)
 
 CAST_FROM_TIMESTAMP (SmallIntVal)
 
 CAST_FROM_TIMESTAMP (IntVal)
 
 CAST_FROM_TIMESTAMP (BigIntVal)
 
 CAST_FROM_SUBSECOND_TIMESTAMP (FloatVal)
 
 CAST_FROM_SUBSECOND_TIMESTAMP (DoubleVal)
 
 CAST_TO_TIMESTAMP (BooleanVal)
 
 CAST_TO_TIMESTAMP (TinyIntVal)
 
 CAST_TO_TIMESTAMP (SmallIntVal)
 
 CAST_TO_TIMESTAMP (IntVal)
 
 CAST_TO_TIMESTAMP (BigIntVal)
 
 CAST_TO_TIMESTAMP (FloatVal)
 
 CAST_TO_TIMESTAMP (DoubleVal)
 

Variables

const int MAX_FLOAT_CHARS = 24
 

Macro Definition Documentation

#define CAST_FLOAT_TO_STRING (   float_type,
  format 
)
Value:
StringVal CastFunctions::CastToStringVal(FunctionContext* ctx, const float_type& val) { \
if (val.is_null) return StringVal::null(); \
/* val.val could be -nan, return "nan" instead */ \
if (isnan(val.val)) return StringVal("nan"); \
/* Add 1 to MAX_FLOAT_CHARS since snprintf adds a trailing '\0' */ \
StringVal sv(ctx, MAX_FLOAT_CHARS + 1); \
sv.len = snprintf(reinterpret_cast<char*>(sv.ptr), sv.len, format, val.val); \
DCHECK_GT(sv.len, 0); \
DCHECK_LE(sv.len, MAX_FLOAT_CHARS); \
ColumnType return_type = AnyValUtil::TypeDescToColumnType(ctx->GetReturnType()); \
AnyValUtil::TruncateIfNecessary(return_type, &sv); \
return sv; \
}
Utilities for AnyVals.
Definition: anyval-util.h:32
const int MAX_FLOAT_CHARS

Definition at line 122 of file cast-functions.cc.

#define CAST_FROM_STRING (   num_type,
  native_type,
  string_parser_fn 
)
Value:
num_type CastFunctions::CastTo##num_type(FunctionContext* ctx, const StringVal& val) { \
if (val.is_null) return num_type::null(); \
StringParser::ParseResult result; \
num_type ret; \
ret.val = StringParser::string_parser_fn<native_type>( \
reinterpret_cast<char*>(val.ptr), val.len, &result); \
if (UNLIKELY(result != StringParser::PARSE_SUCCESS)) return num_type::null(); \
return ret; \
}
bool is_null
Definition: udf.h:359
#define UNLIKELY(expr)
Definition: compiler-util.h:33

Definition at line 90 of file cast-functions.cc.

#define CAST_FROM_SUBSECOND_TIMESTAMP (   to_type)
Value:
to_type CastFunctions::CastTo##to_type( \
FunctionContext* ctx, const TimestampVal& val) { \
if (val.is_null) return to_type::null(); \
TimestampValue tv = TimestampValue::FromTimestampVal(val); \
if (!tv.HasDate()) return to_type::null(); \
return to_type(tv.ToSubsecondUnixTime()); \
}
This object has a compatible storage format with boost::ptime.
Definition: udf.h:495
bool is_null
Definition: udf.h:359

Definition at line 208 of file cast-functions.cc.

#define CAST_FROM_TIMESTAMP (   to_type)
Value:
to_type CastFunctions::CastTo##to_type( \
FunctionContext* ctx, const TimestampVal& val) { \
if (val.is_null) return to_type::null(); \
TimestampValue tv = TimestampValue::FromTimestampVal(val); \
if (!tv.HasDate()) return to_type::null(); \
return to_type(tv.ToUnixTime()); \
}
This object has a compatible storage format with boost::ptime.
Definition: udf.h:495
bool is_null
Definition: udf.h:359

Definition at line 193 of file cast-functions.cc.

#define CAST_FUNCTION (   from_type,
  to_type 
)
Value:
to_type CastFunctions::CastTo##to_type(FunctionContext* ctx, const from_type& val) { \
if (val.is_null) return to_type::null(); \
return to_type(val.val); \
}

Definition at line 35 of file cast-functions.cc.

#define CAST_TO_STRING (   num_type)
Value:
StringVal CastFunctions::CastToStringVal(FunctionContext* ctx, const num_type& val) { \
if (val.is_null) return StringVal::null(); \
ColumnType rtype = AnyValUtil::TypeDescToColumnType(ctx->GetReturnType()); \
StringVal sv = AnyValUtil::FromString(ctx, lexical_cast<string>(val.val)); \
AnyValUtil::TruncateIfNecessary(rtype, &sv); \
return sv; \
}
Utilities for AnyVals.
Definition: anyval-util.h:32

Definition at line 108 of file cast-functions.cc.

#define CAST_TO_TIMESTAMP (   from_type)
Value:
TimestampVal CastFunctions::CastToTimestampVal(FunctionContext* ctx, \
const from_type& val) { \
if (val.is_null) return TimestampVal::null(); \
TimestampValue timestamp_value(val.val); \
if (!timestamp_value.HasDate()) return TimestampVal::null(); \
TimestampVal result; \
timestamp_value.ToTimestampVal(&result); \
return result; \
}
This object has a compatible storage format with boost::ptime.
Definition: udf.h:495

Definition at line 220 of file cast-functions.cc.

Function Documentation

CAST_FLOAT_TO_STRING ( FloatVal  ,
"%.9g"   
)
CAST_FLOAT_TO_STRING ( DoubleVal  ,
"%.17g"   
)
CAST_FROM_SUBSECOND_TIMESTAMP ( FloatVal  )
CAST_FROM_SUBSECOND_TIMESTAMP ( DoubleVal  )
CAST_FROM_TIMESTAMP ( BooleanVal  )
CAST_FROM_TIMESTAMP ( TinyIntVal  )
CAST_FROM_TIMESTAMP ( SmallIntVal  )
CAST_FROM_TIMESTAMP ( IntVal  )
CAST_FROM_TIMESTAMP ( BigIntVal  )
CAST_TO_STRING ( BooleanVal  )
CAST_TO_STRING ( SmallIntVal  )
CAST_TO_STRING ( IntVal  )
CAST_TO_STRING ( BigIntVal  )
CAST_TO_TIMESTAMP ( BooleanVal  )
CAST_TO_TIMESTAMP ( TinyIntVal  )
CAST_TO_TIMESTAMP ( SmallIntVal  )
CAST_TO_TIMESTAMP ( IntVal  )
CAST_TO_TIMESTAMP ( BigIntVal  )
CAST_TO_TIMESTAMP ( FloatVal  )
CAST_TO_TIMESTAMP ( DoubleVal  )

Variable Documentation

const int MAX_FLOAT_CHARS = 24

Definition at line 33 of file cast-functions.cc.