IMP-267 Add version() function.

This commit is contained in:
Michael Ubell
2012-10-04 18:14:51 -07:00
committed by Henry Robinson
parent a9ff7323f2
commit 48c454d319
7 changed files with 46 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ add_library(Exprs
timestamp-functions.cc
timestamp-literal.cc
timezone_db.cc
utility-functions.cc
)
target_link_libraries(Exprs

View File

@@ -26,6 +26,7 @@
#include "codegen/llvm-codegen.h"
#include "util/cpu-info.h"
#include "util/disk-info.h"
#include "util/debug-util.h"
using namespace llvm;
using namespace std;
@@ -1118,6 +1119,8 @@ TEST_F(ExprTest, StringFunctions) {
// First param contains comma.
TestValue("find_in_set('abc,def', 'abc,ad,,ade,cde,')", TYPE_INT, 0);
TestStringValue("version()", GetVersionString());
// TODO: tests with NULL arguments, currently we can't parse them
// inside function calls.
// e.g. TestValue("length(NULL)", TYPE_INT, NULL);

View File

@@ -245,6 +245,7 @@ class Expr {
friend class StringFunctions;
friend class TimestampFunctions;
friend class ConditionalFunctions;
friend class UtilityFunctions;
friend class CaseExpr;
friend class InPredicate;
friend class FunctionCall;

View File

@@ -0,0 +1,19 @@
// Copyright (c) 2011 Cloudera, Inc. All rights reserved.
#include "exprs/utility-functions.h"
#include "exprs/function-call.h"
#include "exprs/expr.h"
#include "util/debug-util.h"
#include "runtime/tuple-row.h"
using namespace std;
namespace impala {
void* UtilityFunctions::Version(Expr* e, TupleRow* row) {
DCHECK_EQ(e->GetNumChildren(), 0);
e->result_.SetStringVal(GetVersionString());
return &e->result_.string_val;
}
}

View File

@@ -0,0 +1,20 @@
// Copyright (c) 2011 Cloudera, Inc. All rights reserved.
#ifndef IMPALA_EXPRS_UTILITY_FUNCTIONS_H
#define IMPALA_EXPRS_UTILITY_FUNCTIONS_H
namespace impala {
class Expr;
class OpcodeRegistry;
class TupleRow;
class UtilityFunctions {
public:
// Implementation of the version() function. Returns the version string.
static void* Version(Expr* e, TupleRow* row);
};
}
#endif

View File

@@ -67,6 +67,7 @@ cc_registry_preamble = '\
#include "exprs/string-functions.h"\n\
#include "exprs/timestamp-functions.h"\n\
#include "exprs/conditional-functions.h"\n\
#include "exprs/utility-functions.h"\n\
#include "opcode/functions.h"\n\
\n\
namespace impala { \n\

View File

@@ -106,6 +106,7 @@ functions = [
'StringFunctions::ParseUrl', ['parse_url']],
['String_Parse_Url', 'STRING', ['STRING', 'STRING', 'STRING'], \
'StringFunctions::ParseUrlKey', ['parse_url']],
['Utility_Version', 'STRING', [], 'UtilityFunctions::Version', ['version']],
# Timestamp Functions
['Unix_Timestamp', 'INT', ['TIMESTAMP'], \