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/04/06 23:09:13 UTC
[2/6] trafodion git commit: update the regression test and various
fixes
update the regression test and various fixes
Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/5f58cd95
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/5f58cd95
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/5f58cd95
Branch: refs/heads/master
Commit: 5f58cd95aa72f4cbe944aa8d0aeb11eb0202f524
Parents: 6b800c3
Author: Liu Ming <ov...@sina.com>
Authored: Sun Mar 18 09:19:35 2018 +0000
Committer: Liu Ming <ov...@sina.com>
Committed: Sun Mar 18 09:19:35 2018 +0000
----------------------------------------------------------------------
core/sql/optimizer/BindItemExpr.cpp | 1 +
core/sql/optimizer/ItemFunc.h | 6 ++++++
core/sql/parser/ElemDDLColDefault.h | 4 ++--
core/sql/parser/sqlparser.y | 25 +++++++++++++++------
core/sql/regress/seabase/EXPECTED020 | 31 +++++++++++++++++++++++++++
core/sql/regress/seabase/TEST020 | 2 +-
core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp | 12 +++++------
7 files changed, 66 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafodion/blob/5f58cd95/core/sql/optimizer/BindItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/BindItemExpr.cpp b/core/sql/optimizer/BindItemExpr.cpp
index 3c81218..2541ab9 100644
--- a/core/sql/optimizer/BindItemExpr.cpp
+++ b/core/sql/optimizer/BindItemExpr.cpp
@@ -4166,6 +4166,7 @@ DateFormat::DateFormat(ItemExpr *val1Ptr, const NAString &formatStr,
wasDateformat_(wasDateformat),
formatType_(formatType),
frmt_(-1),
+ origString_(""),
dateFormat_(DATE_FORMAT_NONE)
{
allowsSQLnullArg() = FALSE;
http://git-wip-us.apache.org/repos/asf/trafodion/blob/5f58cd95/core/sql/optimizer/ItemFunc.h
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/ItemFunc.h b/core/sql/optimizer/ItemFunc.h
index 6c0c779..ee5dcdc 100644
--- a/core/sql/optimizer/ItemFunc.h
+++ b/core/sql/optimizer/ItemFunc.h
@@ -1918,6 +1918,9 @@ public:
ItemExpr * bindNode(BindWA * bindWA);
+ void setOriginalString(NAString &s) {origString_ = s; }
+ const NAString & getOriginalString() const { return origString_; }
+
// a virtual function for type propagating the node
virtual const NAType * synthesizeType();
@@ -1954,6 +1957,9 @@ private:
// actual datetime format (defined in class ExpDatetime in exp_datetime.h)
Lng32 frmt_;
+
+ //original string
+ NAString origString_;
}; // class DateFormat
class DayOfWeek : public CacheableBuiltinFunction
http://git-wip-us.apache.org/repos/asf/trafodion/blob/5f58cd95/core/sql/parser/ElemDDLColDefault.h
----------------------------------------------------------------------
diff --git a/core/sql/parser/ElemDDLColDefault.h b/core/sql/parser/ElemDDLColDefault.h
index e435400..0415e6b 100644
--- a/core/sql/parser/ElemDDLColDefault.h
+++ b/core/sql/parser/ElemDDLColDefault.h
@@ -108,7 +108,7 @@ public:
// mutator
virtual void setChild(Lng32 index, ExprNode * pChildNode);
inline void setDefaultValueExpr(ItemExpr * pDefaultValueExpr);
- inline void setDefaultExprString(NAString &str);
+ inline void setDefaultExprString(const NAString &str);
inline void setSGOptions(ElemDDLSGOptions * pSGOptions);
inline void setSGLocation(NAString *pLocation);
inline void setComputedDefaultExpr(const NAString &computedDefaultExpr);
@@ -165,7 +165,7 @@ ElemDDLColDefault::setDefaultValueExpr(ItemExpr * pDefaultValueExpr)
}
inline void
-ElemDDLColDefault::setDefaultExprString(NAString &str)
+ElemDDLColDefault::setDefaultExprString(const NAString &str)
{
defaultExprString_ = str;
}
http://git-wip-us.apache.org/repos/asf/trafodion/blob/5f58cd95/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index dedd03f..c351181 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -8741,9 +8741,25 @@ datetime_value_function : TOK_CURDATE '(' ')'
/* type item */
datetime_misc_function_used_as_default: TOK_TO_CHAR '(' value_expression ',' character_string_literal ')'
{
-
- $$ = new (PARSERHEAP())
+ NAString * ves= unicodeToChar
+ (ToTokvalPlusYYText(&$3)->yytext,
+ ToTokvalPlusYYText(&$3)->yyleng,
+ (CharInfo::CharSet) (
+ ComGetNameInterfaceCharSet() // CharInfo::UTF8
+ ),
+ PARSERHEAP());
+ //save the original text
+ NAString fullstr;
+ fullstr += "TO_CHAR(";
+ //Column Reference will not be able to convert to NAString
+ //And it is not be allowed bo become default value, so no need to save original text
+ if( ves != NULL)
+ {
+ fullstr += *ves + ", '" + *$5 + "')";
+ }
+ $$ = new (PARSERHEAP())
DateFormat($3, *$5, DateFormat::FORMAT_TO_CHAR);
+ ((DateFormat *)$$)->setOriginalString(fullstr);
}
/* type item */
@@ -25812,11 +25828,8 @@ col_def_default_clause_argument : literal_negatable
$$ = new (PARSERHEAP())
ElemDDLColDefault(
ElemDDLColDefault::COL_FUNCTION_DEFAULT);
- ItemExpr * firstItem = $1;
- NAString unparsed(PARSERHEAP());
- firstItem->unparse(unparsed); // expression as ascii string
- ((ElemDDLColDefault *)$$)->setDefaultExprString(unparsed);
+ ((ElemDDLColDefault *)$$)->setDefaultExprString( (const NAString &)((DateFormat*)$1)->getOriginalString());
((ElemDDLColDefault *)$$)->setDefaultValueExpr($1);
}
| builtin_function_user
http://git-wip-us.apache.org/repos/asf/trafodion/blob/5f58cd95/core/sql/regress/seabase/EXPECTED020
----------------------------------------------------------------------
diff --git a/core/sql/regress/seabase/EXPECTED020 b/core/sql/regress/seabase/EXPECTED020
index 15771ce..3396b6d 100644
--- a/core/sql/regress/seabase/EXPECTED020
+++ b/core/sql/regress/seabase/EXPECTED020
@@ -3945,4 +3945,35 @@ AAAA ? 2
--- 1 row(s) selected.
>>
+>>obey TEST020(trafodion_2335);
+>>--create seqence test020_seq;
+>>create table test020t45(a largeint not null default unix_timestamp(),
++> b char(36) not null default uuid(),
++> c varchar(10) default to_char(sysdate,'YYYYMMDD'),
++> --support sequence as default in next check-in
++> --d int not null default testi020_seq.nextval,
++> e int );
+
+--- SQL operation complete.
+>>insert into test020t45(e) values(1),(2),(3);
+
+--- 3 row(s) inserted.
+>>select count(*) from test020t45 where c = to_char(sysdate,'YYYYMMDD');
+
+(EXPR)
+--------------------
+
+ 3
+
+--- 1 row(s) selected.
+>>--negative tests
+>>--the function is not variable-free, so should fail
+>>create table test020t45(a largeint not null default unix_timestamp(),
++> b varchar(10) default to_char(test020t45.c,'YYYYMMDD'),
++> e int );
+
+*** ERROR[1084] An invalid default value was specified for column B.
+
+*** ERROR[8822] The statement was not prepared.
+
>>log;
http://git-wip-us.apache.org/repos/asf/trafodion/blob/5f58cd95/core/sql/regress/seabase/TEST020
----------------------------------------------------------------------
diff --git a/core/sql/regress/seabase/TEST020 b/core/sql/regress/seabase/TEST020
index d435747..80681ae 100755
--- a/core/sql/regress/seabase/TEST020
+++ b/core/sql/regress/seabase/TEST020
@@ -940,7 +940,7 @@ create table test020t45(a largeint not null default unix_timestamp(),
--d int not null default testi020_seq.nextval,
e int );
insert into test020t45(e) values(1),(2),(3);
-select * from test020t45;
+select count(*) from test020t45 where c = to_char(sysdate,'YYYYMMDD');
--negative tests
--the function is not variable-free, so should fail
create table test020t45(a largeint not null default unix_timestamp(),
http://git-wip-us.apache.org/repos/asf/trafodion/blob/5f58cd95/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
index 3e602e8..dc9b108 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
@@ -3168,13 +3168,8 @@ short CmpSeabaseDDL::getColInfo(ElemDDLColDef * colNode,
defaultClass = COM_IDENTITY_GENERATED_BY_DEFAULT;
}
else if (ie == NULL)
- if (colNode->getComputedDefaultExpr().isNull() && colNode->getDefaultExprString().isNull())
+ if (colNode->getComputedDefaultExpr().isNull())
defaultClass = COM_NO_DEFAULT;
- else if(!colNode->getDefaultExprString().isNull())
- {
- defaultClass = COM_FUNCTION_DEFINED_DEFAULT;
- defVal = colNode->getDefaultExprString();
- }
else
{
defaultClass = COM_ALWAYS_COMPUTE_COMPUTED_COLUMN_DEFAULT;
@@ -3186,6 +3181,11 @@ short CmpSeabaseDDL::getColInfo(ElemDDLColDef * colNode,
else
CMPASSERT(0);
}
+ else if (!colNode->getDefaultExprString().isNull())
+ {
+ defaultClass = COM_FUNCTION_DEFINED_DEFAULT;
+ defVal = colNode->getDefaultExprString();
+ }
else if (ie->getOperatorType() == ITM_CURRENT_TIMESTAMP)
{
defaultClass = COM_CURRENT_DEFAULT;