You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by li...@apache.org on 2018/02/23 09:45:22 UTC
[3/9] trafodion git commit: [TRAFODION-2157] fix various issues
[TRAFODION-2157] fix various issues
Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/3c6bce6e
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/3c6bce6e
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/3c6bce6e
Branch: refs/heads/master
Commit: 3c6bce6e10e8f319bcdeffa272ffc4ac31a74f48
Parents: 3555983
Author: Liu Ming <ov...@sina.com>
Authored: Wed Feb 14 21:51:10 2018 +0000
Committer: Liu Ming <ov...@sina.com>
Committed: Wed Feb 14 21:51:10 2018 +0000
----------------------------------------------------------------------
core/sql/common/OperTypeEnum.h | 1 +
core/sql/exp/exp_clause.cpp | 2 ++
core/sql/exp/exp_function.cpp | 36 ++++++++++++++++++++++++---------
core/sql/generator/GenItemFunc.cpp | 1 +
core/sql/optimizer/ItemExpr.cpp | 2 ++
core/sql/optimizer/SynthType.cpp | 29 ++++++++++++++++++++++----
core/sql/parser/sqlparser.y | 16 +++++++++++----
7 files changed, 70 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafodion/blob/3c6bce6e/core/sql/common/OperTypeEnum.h
----------------------------------------------------------------------
diff --git a/core/sql/common/OperTypeEnum.h b/core/sql/common/OperTypeEnum.h
index af1d2ba..293a372 100644
--- a/core/sql/common/OperTypeEnum.h
+++ b/core/sql/common/OperTypeEnum.h
@@ -474,6 +474,7 @@ enum OperatorTypeEnum {
ITM_UNIX_TIMESTAMP = 2179,
ITM_UUID_SHORT = 2180,
ITM_SLEEP = 2181,
+ ITM_UNIQUE_SHORT_ID = 2182,
// numeric functions
ITM_ABS = 2200,
http://git-wip-us.apache.org/repos/asf/trafodion/blob/3c6bce6e/core/sql/exp/exp_clause.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_clause.cpp b/core/sql/exp/exp_clause.cpp
index 0ad09d5..2a9278e 100644
--- a/core/sql/exp/exp_clause.cpp
+++ b/core/sql/exp/exp_clause.cpp
@@ -506,6 +506,7 @@ ex_clause::ex_clause(clause_type type,
setClassID(FUNC_QUERYID_EXTRACT);
break;
case ITM_UNIQUE_ID:
+ case ITM_UNIQUE_SHORT_ID:
setClassID(FUNC_UNIQUE_ID);
break;
case ITM_ROWNUM:
@@ -1507,6 +1508,7 @@ const char * getOperTypeEnumAsString(Int16 /*OperatorTypeEnum*/ ote)
case ITM_LAST_ITEM_OP: return "ITM_LAST_ITEM_OP";
case ITM_UNIQUE_ID: return "ITM_UNIQUE_ID";
+ case ITM_UNIQUE_SHORT_ID: return "ITM_UNIQUE_SHORT_ID";
case ITM_ROWNUM: return "ITM_ROWNUM";
case ITM_HBASE_COLUMN_LOOKUP: return "ITM_HBASE_COLUMN_LOOKUP";
case ITM_HBASE_COLUMNS_DISPLAY: return "ITM_HBASE_COLUMNS_DISPLAY";
http://git-wip-us.apache.org/repos/asf/trafodion/blob/3c6bce6e/core/sql/exp/exp_function.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_function.cpp b/core/sql/exp/exp_function.cpp
index 821e392..9e5e49e 100644
--- a/core/sql/exp/exp_function.cpp
+++ b/core/sql/exp/exp_function.cpp
@@ -50,6 +50,7 @@
#include <ctype.h>
#include <string.h>
#include <stdio.h>
+#include <uuid/uuid.h>
#include "NLSConversion.h"
#include "nawstring.h"
@@ -6799,21 +6800,38 @@ ex_expr::exp_return_type ExFunctionUniqueId::eval(char *op_data[],
Lng32 retcode = 0;
char * result = op_data[0];
+ if(getOperType() == ITM_UNIQUE_ID)
+ {
+ //it is hard to find a common header file for these length
+ //so hardcode 36 here
+ //if change, please check the SynthType.cpp for ITM_UNIQUE_ID part as well
+ //libuuid is global unique, even across computer node
+ //NOTE: libuuid is avialble on normal CentOS, other system like Ubuntu may need to check
+ //Trafodion only support RHEL and CentOS as for now
+ char str[36 + 1];
+ uuid_t uu;
+ uuid_generate( uu );
+ uuid_unparse(uu, str);
+ str_cpy_all(result, str, 36);
+ }
+ else //at present , it must be ITM_UUID_SHORT_ID
+ {
+ Int64 uniqueUID;
- Int64 uniqueUID;
-
- ComUID comUID;
- comUID.make_UID();
+ ComUID comUID;
+ comUID.make_UID();
#if defined( NA_LITTLE_ENDIAN )
- uniqueUID = reversebytes(comUID.get_value());
+ uniqueUID = reversebytes(comUID.get_value());
#else
- uniqueUID = comUID.get_value();
+ uniqueUID = comUID.get_value();
#endif
- str_cpy_all(result, (char*)&uniqueUID, sizeof(Int64));
- str_pad(&result[sizeof(Int64)], sizeof(Int64), '\0');
-
+ //it is safe, since the result is allocated 21 bytes in this case from synthtype,
+ //max in64 is 19 digits and one for sign, 21 is enough
+ sprintf(result,"%lu",uniqueUID);
+ }
+
return ex_expr::EXPR_OK;
}
http://git-wip-us.apache.org/repos/asf/trafodion/blob/3c6bce6e/core/sql/generator/GenItemFunc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenItemFunc.cpp b/core/sql/generator/GenItemFunc.cpp
index df3f674..86c1758 100644
--- a/core/sql/generator/GenItemFunc.cpp
+++ b/core/sql/generator/GenItemFunc.cpp
@@ -663,6 +663,7 @@ short BuiltinFunction::codeGen(Generator * generator)
break;
case ITM_UNIQUE_ID:
+ case ITM_UNIQUE_SHORT_ID:
{
function_clause =
new(generator->getSpace()) ExFunctionUniqueId(getOperatorType(),
http://git-wip-us.apache.org/repos/asf/trafodion/blob/3c6bce6e/core/sql/optimizer/ItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/ItemExpr.cpp b/core/sql/optimizer/ItemExpr.cpp
index 006639e..b58aa5e 100644
--- a/core/sql/optimizer/ItemExpr.cpp
+++ b/core/sql/optimizer/ItemExpr.cpp
@@ -7619,6 +7619,8 @@ const NAString BuiltinFunction::getText() const
return "pack";
case ITM_SAMPLE_VALUE:
return "sample_size";
+ case ITM_UNIQUE_SHORT_ID:
+ return "unique_short_id";
case ITM_UNIQUE_ID:
return "unique_id";
case ITM_HBASE_COLUMN_LOOKUP:
http://git-wip-us.apache.org/repos/asf/trafodion/blob/3c6bce6e/core/sql/optimizer/SynthType.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/SynthType.cpp b/core/sql/optimizer/SynthType.cpp
index fd7fd1f..c3dfc18 100644
--- a/core/sql/optimizer/SynthType.cpp
+++ b/core/sql/optimizer/SynthType.cpp
@@ -1122,9 +1122,23 @@ const NAType *BuiltinFunction::synthesizeType()
case ITM_SLEEP:
{
- ValueId vid1 = child(0)->getValueId();
- SQLInt c1( HEAP, TRUE , TRUE);
- vid1.coerceType(c1, NA_NUMERIC_TYPE);
+ const NAType &typ1 = child(0)->getValueId().getType();
+ if (typ1.getTypeQualifier() != NA_NUMERIC_TYPE)
+ {
+ *CmpCommon::diags() << DgSqlCode(-4045) << DgString0("SLEEP");
+ return NULL;
+ }
+ const NumericType &ntyp1 = (NumericType &) typ1;
+ if (NOT ntyp1.isExact() )
+ {
+ *CmpCommon::diags() << DgSqlCode(-4046) << DgString0(getTextUpper());
+ return NULL;
+ }
+ if (ntyp1.getScale() != 0 )
+ {
+ *CmpCommon::diags() << DgSqlCode(-4047) << DgString0(getTextUpper());
+ return NULL;
+ }
retType = new HEAP SQLInt(HEAP, TRUE, TRUE);
}
break;
@@ -1352,7 +1366,14 @@ const NAType *BuiltinFunction::synthesizeType()
case ITM_UNIQUE_ID:
{
- retType = new HEAP SQLChar(HEAP, 16, FALSE);
+ //please check the ExFunctionUniqueId::eval if the size is changed
+ retType = new HEAP SQLChar(HEAP, 36, FALSE);
+ }
+ break;
+ case ITM_UNIQUE_SHORT_ID:
+ {
+ //please check the ExFunctionUniqueId::eval if the size is changed
+ retType = new HEAP SQLChar(HEAP, 21, FALSE);
}
break;
http://git-wip-us.apache.org/repos/asf/trafodion/blob/3c6bce6e/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index 00672e8..336dfd6 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -8716,14 +8716,22 @@ datetime_value_function : TOK_CURDATE '(' ')'
$$ = new (PARSERHEAP()) Cast(ie, type);
}
| TOK_UUID '(' ')'
- | TOK_UUID_SHORT '(' ')'
{
ItemExpr * uniqueId = new (PARSERHEAP()) BuiltinFunction(ITM_UNIQUE_ID, PARSERHEAP());
- ItemExpr *conv = new (PARSERHEAP()) ConvertHex(ITM_CONVERTTOHEX, uniqueId);
+ //ItemExpr *conv = new (PARSERHEAP()) ConvertHex(ITM_CONVERTTOHEX, uniqueId);
+ NAType * type;
+ type = new (PARSERHEAP())
+ SQLVarChar(PARSERHEAP() , 36, FALSE);
+ $$ = new (PARSERHEAP()) Cast(uniqueId,type);
+ }
+ | TOK_UUID_SHORT '(' ')'
+ {
+ ItemExpr * uniqueId = new (PARSERHEAP()) BuiltinFunction(ITM_UNIQUE_SHORT_ID, PARSERHEAP());
+ //ItemExpr *conv = new (PARSERHEAP()) ConvertHex(ITM_CONVERTTOHEX, uniqueId);
NAType * type;
type = new (PARSERHEAP())
- SQLVarChar(PARSERHEAP() , 128 , FALSE);
- $$ = new (PARSERHEAP()) Cast(conv,type);
+ SQLVarChar(PARSERHEAP() , 36, FALSE);
+ $$ = new (PARSERHEAP()) Cast(uniqueId,type);
}
/* type item */