Repository: trafodion Updated Branches: refs/heads/master ee2cff973 -> 995e8a090
[TRAFODION-2335] support some functions as column default, part1 commit Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/6b800c34 Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/6b800c34 Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/6b800c34 Branch: refs/heads/master Commit: 6b800c34a4f9cb4386223067ff7c3801bdbec002 Parents: 75c7b39 Author: Liu Ming <ovis_p...@sina.com> Authored: Wed Mar 14 09:07:42 2018 +0000 Committer: Liu Ming <ovis_p...@sina.com> Committed: Wed Mar 14 09:07:42 2018 +0000 ---------------------------------------------------------------------- core/sql/common/ComSmallDefs.h | 12 ++++++++ core/sql/exp/exp_attrs.cpp | 2 ++ core/sql/exp/exp_attrs.h | 2 +- core/sql/generator/GenExpGenerator.cpp | 14 +++++++++ core/sql/optimizer/BindRelExpr.cpp | 4 ++- core/sql/optimizer/ColStatDesc.cpp | 4 +++ core/sql/optimizer/ValueDesc.cpp | 2 +- core/sql/parser/ElemDDLCol.cpp | 41 +++++++++++++++++++++++++-- core/sql/parser/ElemDDLColDef.h | 17 +++++++++++ core/sql/parser/ElemDDLColDefault.h | 17 +++++++++++ core/sql/parser/sqlparser.y | 29 +++++++++++++++---- core/sql/regress/seabase/TEST020 | 17 +++++++++++ core/sql/sqlcomp/CmpDescribe.cpp | 6 +++- core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp | 25 +++++++++++++++- core/sql/sqlcomp/CmpSeabaseDDLtable.cpp | 15 ++++++++++ core/sql/sqlcomp/CmpSeabaseDDLutil.cpp | 6 ++++ 16 files changed, 200 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafodion/blob/6b800c34/core/sql/common/ComSmallDefs.h ---------------------------------------------------------------------- diff --git a/core/sql/common/ComSmallDefs.h b/core/sql/common/ComSmallDefs.h index b6baf11..b1dd91a 100644 --- a/core/sql/common/ComSmallDefs.h +++ b/core/sql/common/ComSmallDefs.h @@ -609,47 +609,59 @@ enum ComColumnClass { COM_UNKNOWN_CLASS #define COM_ALTERED_USER_COLUMN_LIT "C " enum ComColumnDefaultClass { COM_CURRENT_DEFAULT + , COM_CURRENT_UT_DEFAULT , COM_NO_DEFAULT , COM_NULL_DEFAULT , COM_USER_DEFINED_DEFAULT , COM_USER_FUNCTION_DEFAULT + , COM_UUID_DEFAULT , COM_IDENTITY_GENERATED_BY_DEFAULT , COM_IDENTITY_GENERATED_ALWAYS , COM_ALWAYS_COMPUTE_COMPUTED_COLUMN_DEFAULT , COM_ALWAYS_DEFAULT_COMPUTED_COLUMN_DEFAULT + , COM_FUNCTION_DEFINED_DEFAULT }; #define COM_CURRENT_DEFAULT_LIT "CD" +#define COM_CURRENT_UT_DEFAULT_LIT "UT" +#define COM_FUNCTION_DEFINED_DEFAULT_LIT "FD" #define COM_NO_DEFAULT_LIT " " #define COM_NULL_DEFAULT_LIT "ND" #define COM_USER_DEFINED_DEFAULT_LIT "UD" #define COM_USER_FUNCTION_DEFAULT_LIT "UF" +#define COM_UUID_DEFAULT_LIT "UI" #define COM_IDENTITY_GENERATED_BY_DEFAULT_LIT "ID" #define COM_IDENTITY_GENERATED_ALWAYS_LIT "IA" #define COM_ALWAYS_COMPUTE_COMPUTED_COLUMN_DEFAULT_LIT "AC" #define COM_ALWAYS_DEFAULT_COMPUTED_COLUMN_DEFAULT_LIT "AD" enum ComParamDefaultClass { COM_CURRENT_PARAM_DEFAULT = COM_CURRENT_DEFAULT + , COM_CURRENT_UT_PARAM_DEFAULT = COM_CURRENT_UT_DEFAULT , COM_NO_PARAM_DEFAULT = COM_NO_DEFAULT , COM_NULL_PARAM_DEFAULT = COM_NULL_DEFAULT , COM_USER_DEFINED_PARAM_DEFAULT = COM_USER_DEFINED_DEFAULT , COM_USER_FUNCTION_PARAM_DEFAULT = COM_USER_FUNCTION_DEFAULT + , COM_UUID_PARAM_DEAULT = COM_UUID_DEFAULT // IDENTITY GENERATED BY DEFAULT not applicable // IDENTITY GENERATED ALWAYS not applicable , COM_ALWAYS_COMPUTE_COMPUTED_PARAM_DEFAULT // for future internal use only = COM_ALWAYS_COMPUTE_COMPUTED_COLUMN_DEFAULT , COM_ALWAYS_DEFAULT_COMPUTED_PARAM_DEFAULT // for future internal use only = COM_ALWAYS_DEFAULT_COMPUTED_COLUMN_DEFAULT + , COM_FUNCTION_DEFINED_PARAM_DEFAULT + = COM_FUNCTION_DEFINED_DEFAULT }; #define COM_NO_PARAM_DEFAULT_LIT " " #define COM_CURRENT_PARAM_DEFAULT_LIT "CD" +#define COM_CURRENT_UT_PARAM_DEFAULT_LIT "UT" #define COM_NULL_PARAM_DEFAULT_LIT "ND" #define COM_USER_DEFINED_PARAM_DEFAULT_LIT "UD" #define COM_USER_FUNCTION_PARAM_DEFAULT_LIT "UF" #define COM_ALWAYS_COMPUTE_COMPUTED_PARAM_DEFAULT_LIT "AC" #define COM_ALWAYS_DEFAULT_COMPUTED_PARAM_DEFAULT_LIT "AD" +#define COM_FUNCTION_DEFINED_PARAM_DEFAULT_LIT "FD" // Represents the kind of string value stored in TEXT table. Note // that changing existing values will require an UPGRADE of the http://git-wip-us.apache.org/repos/asf/trafodion/blob/6b800c34/core/sql/exp/exp_attrs.cpp ---------------------------------------------------------------------- diff --git a/core/sql/exp/exp_attrs.cpp b/core/sql/exp/exp_attrs.cpp index 8ded216..cc2a91d 100644 --- a/core/sql/exp/exp_attrs.cpp +++ b/core/sql/exp/exp_attrs.cpp @@ -482,6 +482,8 @@ NABoolean SimpleType::operator==(const Attributes& other) const : (scale_ == otherAttr.scale_)) && ((thisAttr.getDefaultClass() == DEFAULT_NULL || thisAttr.getDefaultClass() == NO_DEFAULT || + thisAttr.getDefaultClass() == DEFAULT_UUID || + thisAttr.getDefaultClass() == DEFAULT_CURRENT_UT || thisAttr.getDefaultClass() == DEFAULT_CURRENT) || (thisAttr.getDefaultValue() && otherAttr.getDefaultValue() && (str_cmp(thisAttr.getDefaultValue(), http://git-wip-us.apache.org/repos/asf/trafodion/blob/6b800c34/core/sql/exp/exp_attrs.h ---------------------------------------------------------------------- diff --git a/core/sql/exp/exp_attrs.h b/core/sql/exp/exp_attrs.h index 32a818d..745374b 100644 --- a/core/sql/exp/exp_attrs.h +++ b/core/sql/exp/exp_attrs.h @@ -102,7 +102,7 @@ public: enum DefaultClass { NO_DEFAULT, DEFAULT_NULL, DEFAULT_CURRENT, - DEFAULT_USER, DEFAULT_USER_FUNCTION, DEFAULT_IDENTITY, + DEFAULT_USER, DEFAULT_USER_FUNCTION, DEFAULT_IDENTITY,DEFAULT_CURRENT_UT, DEFAULT_UUID, DEFAULT_FUNCTION, INVALID_DEFAULT }; http://git-wip-us.apache.org/repos/asf/trafodion/blob/6b800c34/core/sql/generator/GenExpGenerator.cpp ---------------------------------------------------------------------- diff --git a/core/sql/generator/GenExpGenerator.cpp b/core/sql/generator/GenExpGenerator.cpp index 2fcc85d..7084147 100644 --- a/core/sql/generator/GenExpGenerator.cpp +++ b/core/sql/generator/GenExpGenerator.cpp @@ -423,6 +423,12 @@ Attributes::DefaultClass ExpGenerator::getDefaultClass(const NAColumn * col) { case COM_CURRENT_DEFAULT: dc = Attributes::DEFAULT_CURRENT; break; + case COM_CURRENT_UT_DEFAULT: + dc = Attributes::DEFAULT_CURRENT_UT; break; + case COM_UUID_DEFAULT: + dc = Attributes::DEFAULT_UUID; break; + case COM_FUNCTION_DEFINED_DEFAULT: + dc = Attributes::DEFAULT_FUNCTION; break; case COM_NO_DEFAULT: case COM_ALWAYS_COMPUTE_COMPUTED_COLUMN_DEFAULT: case COM_ALWAYS_DEFAULT_COMPUTED_COLUMN_DEFAULT: @@ -482,6 +488,11 @@ short ExpGenerator::addDefaultValue(NAColumn * col, Attributes * attr, // For new rows compiler will produce a node with CURRENT exp castStr = new(wHeap()) NAString("CAST(TIMESTAMP '0001-01-01:12:00:00.000000' AS ", wHeap()); break; + case Attributes::DEFAULT_CURRENT_UT: + // This value is for the old rows before the alter table with add column + // For new rows compiler will produce a node with CURRENT exp + castStr = new(wHeap()) NAString("CAST( 0 AS ", wHeap()); + break; case Attributes::DEFAULT_NULL: if (attr->getNullFlag()) { @@ -528,6 +539,9 @@ short ExpGenerator::addDefaultValue(NAColumn * col, Attributes * attr, // IDENTITY column, it is Ok. to cast it to zero. castStr = new(wHeap()) NAString("CAST(0 AS ", wHeap()); break; + case Attributes::DEFAULT_FUNCTION: + castStr = new(wHeap()) NAString("CAST( \' \' AS ", wHeap()); + break; case Attributes::NO_DEFAULT: default: http://git-wip-us.apache.org/repos/asf/trafodion/blob/6b800c34/core/sql/optimizer/BindRelExpr.cpp ---------------------------------------------------------------------- diff --git a/core/sql/optimizer/BindRelExpr.cpp b/core/sql/optimizer/BindRelExpr.cpp index 7beaf9e..f8543e9 100644 --- a/core/sql/optimizer/BindRelExpr.cpp +++ b/core/sql/optimizer/BindRelExpr.cpp @@ -10398,7 +10398,6 @@ RelExpr *Insert::bindNode(BindWA *bindWA) ULng32 savedParserFlags = Get_SqlParser_Flags (0xFFFFFFFF); Set_SqlParser_Flags(INTERNAL_QUERY_FROM_EXEUTIL); Set_SqlParser_Flags(ALLOW_VOLATILE_SCHEMA_IN_TABLE_NAME); - defaultValueExpr = parser.getItemExprTree(defaultValueStr); CMPASSERT(defaultValueExpr); @@ -10454,6 +10453,9 @@ RelExpr *Insert::bindNode(BindWA *bindWA) Assign(target.getItemExpr(), defaultValueExpr, FALSE /*Not user Specified */); if ((nacol->getDefaultClass() != COM_CURRENT_DEFAULT) && + (nacol->getDefaultClass() != COM_CURRENT_UT_DEFAULT) && + (nacol->getDefaultClass() != COM_FUNCTION_DEFINED_DEFAULT) && + (nacol->getDefaultClass() != COM_UUID_DEFAULT) && (nacol->getDefaultClass() != COM_USER_FUNCTION_DEFAULT)) assign->setToBeSkipped(TRUE); assign->bindNode(bindWA); http://git-wip-us.apache.org/repos/asf/trafodion/blob/6b800c34/core/sql/optimizer/ColStatDesc.cpp ---------------------------------------------------------------------- diff --git a/core/sql/optimizer/ColStatDesc.cpp b/core/sql/optimizer/ColStatDesc.cpp index 8623526..2f256b1 100644 --- a/core/sql/optimizer/ColStatDesc.cpp +++ b/core/sql/optimizer/ColStatDesc.cpp @@ -1708,6 +1708,8 @@ ColStatDesc::selForRelativeRange (const OperatorTypeEnum op, OR (operand->getOperatorType() == ITM_CACHE_PARAM) OR (operand->getOperatorType() == ITM_CURRENT_USER) OR (operand->getOperatorType() == ITM_CURRENT_TIMESTAMP) + OR (operand->getOperatorType() == ITM_UNIQUE_ID) + OR (operand->getOperatorType() == ITM_UNIX_TIMESTAMP) OR (operand->getOperatorType() == ITM_SESSION_USER) OR (operand->getOperatorType() == ITM_GET_TRIGGERS_STATUS) OR (operand->getOperatorType() == ITM_UNIQUE_EXECUTE_ID)) @@ -8580,6 +8582,8 @@ ColStatDescList::getColStatsPtrForVEGGroup(const ValueIdSet& VEGGroup) const case ITM_CURRENT_USER: case ITM_SESSION_USER: case ITM_CURRENT_TIMESTAMP: + case ITM_UNIX_TIMESTAMP: + case ITM_UNIQUE_ID: case ITM_GET_TRIGGERS_STATUS: case ITM_UNIQUE_EXECUTE_ID: continue; http://git-wip-us.apache.org/repos/asf/trafodion/blob/6b800c34/core/sql/optimizer/ValueDesc.cpp ---------------------------------------------------------------------- diff --git a/core/sql/optimizer/ValueDesc.cpp b/core/sql/optimizer/ValueDesc.cpp index 605118b..16e1fcc 100644 --- a/core/sql/optimizer/ValueDesc.cpp +++ b/core/sql/optimizer/ValueDesc.cpp @@ -549,7 +549,7 @@ NABoolean ValueId::isColumnWithNonNullNonCurrentDefault() const{ default: break; } - if (nac && nac->getDefaultValue() && nac->getDefaultClass()!=COM_NULL_DEFAULT && nac->getDefaultClass()!=COM_CURRENT_DEFAULT) + if (nac && nac->getDefaultValue() && nac->getDefaultClass()!=COM_NULL_DEFAULT && nac->getDefaultClass()!=COM_CURRENT_DEFAULT && nac->getDefaultClass()!=COM_CURRENT_UT_DEFAULT) return TRUE; else return FALSE; http://git-wip-us.apache.org/repos/asf/trafodion/blob/6b800c34/core/sql/parser/ElemDDLCol.cpp ---------------------------------------------------------------------- diff --git a/core/sql/parser/ElemDDLCol.cpp b/core/sql/parser/ElemDDLCol.cpp index a18c317..3229f74 100644 --- a/core/sql/parser/ElemDDLCol.cpp +++ b/core/sql/parser/ElemDDLCol.cpp @@ -313,7 +313,7 @@ ElemDDLColDef::setDefaultAttribute(ElemDDLNode * pColDefaultNode) case ElemDDLColDefault::COL_DEFAULT: { defaultClauseStatus_ = DEFAULT_CLAUSE_SPEC; - + if (pColDefault->getSGOptions()) { isIdentityColumn = TRUE; @@ -524,6 +524,39 @@ ElemDDLColDef::setDefaultAttribute(ElemDDLNode * pColDefaultNode) } } break; + case ElemDDLColDefault::COL_FUNCTION_DEFAULT: + { + defaultClauseStatus_ = DEFAULT_CLAUSE_SPEC; + defaultExprString_= pColDefault->getDefaultExprString(); + + ComASSERT(pColDefault->getDefaultValueExpr() NEQ NULL); + pDefault_ = pColDefault->getDefaultValueExpr(); + + ItemExpr *itr = pDefault_; + NABoolean valid = TRUE; + //Only support to_char(cast (currenttimestamp )) + if( pDefault_->getOperatorType() != ITM_DATEFORMAT) + valid = FALSE; + else + { + //next should be CAST + itr = pDefault_->child(0)->castToItemExpr(); + if(itr->getOperatorType() != ITM_CAST) + valid = FALSE; + else + { + itr = itr->child(0)->castToItemExpr(); + if(itr->getOperatorType() != ITM_CURRENT_TIMESTAMP) + valid = FALSE; + } + } + if( valid == FALSE ) + { + *SqlParser_Diags << DgSqlCode(-1084) + << DgColumnName(ToAnsiIdentifier(getColumnName())); + } + } + break; case ElemDDLColDefault::COL_COMPUTED_DEFAULT: { defaultClauseStatus_ = DEFAULT_CLAUSE_SPEC; @@ -734,7 +767,7 @@ ElemDDLColDef::setColumnAttribute(ElemDDLNode * pColAttr) if(TRUE == isColDefaultSpec_) { // Duplicate DEFAULT attrs in column definition. - *SqlParser_Diags << DgSqlCode(-3052) + *SqlParser_Diags << DgSqlCode(-3052) << DgString0("DEFAULT") << DgColumnName(ToAnsiIdentifier(getColumnName())); } @@ -1046,6 +1079,7 @@ ElemDDLColDefault::displayLabel1() const switch (getColumnDefaultType()) { case COL_DEFAULT : + case COL_FUNCTION_DEFAULT : return NAString("Type: Default"); case COL_NO_DEFAULT : return NAString("Type: No Default"); @@ -1058,7 +1092,8 @@ ElemDDLColDefault::displayLabel1() const const NAString ElemDDLColDefault::displayLabel2() const { - if (getColumnDefaultType() EQU COL_DEFAULT) + if ((getColumnDefaultType() EQU COL_DEFAULT) + || getColumnDefaultType() EQU COL_FUNCTION_DEFAULT) { return (NAString("Default value: ") + getDefaultValueExpr()->getText()); http://git-wip-us.apache.org/repos/asf/trafodion/blob/6b800c34/core/sql/parser/ElemDDLColDef.h ---------------------------------------------------------------------- diff --git a/core/sql/parser/ElemDDLColDef.h b/core/sql/parser/ElemDDLColDef.h index 2f275d0..25dd0a3 100644 --- a/core/sql/parser/ElemDDLColDef.h +++ b/core/sql/parser/ElemDDLColDef.h @@ -127,12 +127,14 @@ public: // 3. The DEFAULT clause appears. inline ItemExpr * getDefaultValueExpr() const; + inline Int32 getErrorCode() const; // returns the default value specified in the DEFAULT // clause; returns the NULL pointer value if NO DEFAULT // clause appears or the DEFAULT clause does not appear. inline const NAString & getComputedDefaultExpr() const; + inline const NAString & getDefaultExprString() const; inline const NAString & getHeading() const; inline const NABoolean getIsConstraintNotNullSpecified() const; inline const NABoolean getIsConstraintPKSpecified() const; @@ -239,6 +241,7 @@ private: NABoolean isNewAdjustedDefaultConstValueNode_; ItemExpr * pDefault_; // points to a ConstValue parse node NAString computedDefaultExpr_; + NAString defaultExprString_; ElemDDLSGOptions * pSGOptions_; NAString * pSGLocation_; @@ -309,6 +312,8 @@ private: NABoolean seabaseSerialized_; NABoolean isColDefaultSpec_; + + Int32 errCode_; }; // class ElemDDLColDef // ----------------------------------------------------------------------- @@ -403,6 +408,12 @@ ElemDDLColDef::getDefaultValueExpr() const return pDefault_; } +inline Int32 +ElemDDLColDef::getErrorCode() const +{ + return errCode_; +} + inline const NAString & ElemDDLColDef::getComputedDefaultExpr() const { @@ -410,6 +421,12 @@ ElemDDLColDef::getComputedDefaultExpr() const } inline const NAString & +ElemDDLColDef::getDefaultExprString() const +{ + return defaultExprString_; +} + +inline const NAString & ElemDDLColDef::getHeading() const { return heading_; http://git-wip-us.apache.org/repos/asf/trafodion/blob/6b800c34/core/sql/parser/ElemDDLColDefault.h ---------------------------------------------------------------------- diff --git a/core/sql/parser/ElemDDLColDefault.h b/core/sql/parser/ElemDDLColDefault.h index 3ba4074..e435400 100644 --- a/core/sql/parser/ElemDDLColDefault.h +++ b/core/sql/parser/ElemDDLColDefault.h @@ -63,6 +63,7 @@ public: enum colDefaultTypeEnum { COL_NO_DEFAULT, COL_DEFAULT, + COL_FUNCTION_DEFAULT, COL_COMPUTED_DEFAULT }; // default constructor @@ -74,6 +75,7 @@ public: columnDefaultType_(columnDefaultType), defaultValueExpr_(defaultValueExpr), sgOptions_(sgOptions), + defaultExprString_(""), sgLocation_(NULL) {} @@ -93,6 +95,7 @@ public: inline colDefaultTypeEnum getColumnDefaultType() const; inline ItemExpr * getDefaultValueExpr() const; + inline const NAString &getDefaultExprString() const; // returns the pointer to the (only) child parse node // pointing to an ItemExpr node representing the @@ -105,6 +108,7 @@ public: // mutator virtual void setChild(Lng32 index, ExprNode * pChildNode); inline void setDefaultValueExpr(ItemExpr * pDefaultValueExpr); + inline void setDefaultExprString(NAString &str); inline void setSGOptions(ElemDDLSGOptions * pSGOptions); inline void setSGLocation(NAString *pLocation); inline void setComputedDefaultExpr(const NAString &computedDefaultExpr); @@ -126,6 +130,7 @@ private: ItemExpr * defaultValueExpr_; NAString computedDefaultExpr_; + NAString defaultExprString_; ElemDDLSGOptions * sgOptions_; NAString * sgLocation_; @@ -160,6 +165,12 @@ ElemDDLColDefault::setDefaultValueExpr(ItemExpr * pDefaultValueExpr) } inline void +ElemDDLColDefault::setDefaultExprString(NAString &str) +{ + defaultExprString_ = str; +} + +inline void ElemDDLColDefault::setSGOptions(ElemDDLSGOptions * pSGOptions) { sgOptions_ = pSGOptions; @@ -194,4 +205,10 @@ ElemDDLColDefault::getComputedDefaultExpr() const { return computedDefaultExpr_; } + +inline const NAString & +ElemDDLColDefault::getDefaultExprString() const +{ + return defaultExprString_; +} #endif // ELEMDDLCOLDEFAULT_H http://git-wip-us.apache.org/repos/asf/trafodion/blob/6b800c34/core/sql/parser/sqlparser.y ---------------------------------------------------------------------- diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y index 69df367..dedd03f 100755 --- a/core/sql/parser/sqlparser.y +++ b/core/sql/parser/sqlparser.y @@ -2589,6 +2589,8 @@ static void enableMakeQuotedStringISO88591Mechanism() %type <pElemDDL> datatype_option %type <item> datetime_value_function %type <item> datetime_misc_function +%type <item> datetime_misc_function_used_as_default +%type <item> sequence_as_default %type <stringval> format_attributes %type <pElemDDL> optional_constraint_attributes %type <pElemDDL> constraint_attributes @@ -8245,6 +8247,8 @@ value_function : | datetime_misc_function + | datetime_misc_function_used_as_default + | datetime_value_function | math_function @@ -8735,6 +8739,14 @@ datetime_value_function : TOK_CURDATE '(' ')' } /* type item */ +datetime_misc_function_used_as_default: TOK_TO_CHAR '(' value_expression ',' character_string_literal ')' + { + + $$ = new (PARSERHEAP()) + DateFormat($3, *$5, DateFormat::FORMAT_TO_CHAR); + } + +/* type item */ datetime_misc_function : TOK_CONVERTTIMESTAMP '(' value_expression ')' { $$ = new (PARSERHEAP()) @@ -8851,11 +8863,6 @@ datetime_misc_function : TOK_CONVERTTIMESTAMP '(' value_expression ')' $$ = new (PARSERHEAP()) Cast ($3, dt); } - | TOK_TO_CHAR '(' value_expression ',' character_string_literal ')' - { - $$ = new (PARSERHEAP()) - DateFormat($3, *$5, DateFormat::FORMAT_TO_CHAR); - } | TOK_TO_CHAR '(' value_expression ')' { $$ = new (PARSERHEAP()) DateFormat @@ -25800,6 +25807,18 @@ col_def_default_clause_argument : literal_negatable $1 /*datetime_value_function*/); } + | datetime_misc_function_used_as_default + { + $$ = new (PARSERHEAP()) + ElemDDLColDefault( + ElemDDLColDefault::COL_FUNCTION_DEFAULT); + ItemExpr * firstItem = $1; + NAString unparsed(PARSERHEAP()); + firstItem->unparse(unparsed); // expression as ascii string + + ((ElemDDLColDefault *)$$)->setDefaultExprString(unparsed); + ((ElemDDLColDefault *)$$)->setDefaultValueExpr($1); + } | builtin_function_user { $$ = new (PARSERHEAP()) http://git-wip-us.apache.org/repos/asf/trafodion/blob/6b800c34/core/sql/regress/seabase/TEST020 ---------------------------------------------------------------------- diff --git a/core/sql/regress/seabase/TEST020 b/core/sql/regress/seabase/TEST020 index 6f68b54..d435747 100755 --- a/core/sql/regress/seabase/TEST020 +++ b/core/sql/regress/seabase/TEST020 @@ -41,6 +41,7 @@ obey TEST020(test_10_030916_9668); obey TEST020(test_LP_1360493); obey TEST020(trafodion_1700_and_1847); obey TEST020(trafodion_2247); +obey TEST020(trafodion_2335); log; obey TEST020(clean_up); exit; @@ -93,6 +94,7 @@ drop table test020t41 cascade; drop table test020t42 cascade; drop table test020t43 cascade; drop table test020t44; +drop table test020t45; ?section tests create table test020t1 (c1 int not null primary key, @@ -929,3 +931,18 @@ cqd traf_upsert_mode 'merge'; upsert into test020t44 (a,c) values ('AAAA', 2); select * from test020t44; +?section 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 ); +insert into test020t45(e) values(1),(2),(3); +select * from test020t45; +--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 ); http://git-wip-us.apache.org/repos/asf/trafodion/blob/6b800c34/core/sql/sqlcomp/CmpDescribe.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpDescribe.cpp b/core/sql/sqlcomp/CmpDescribe.cpp index 26b9b3c..5a08a91 100644 --- a/core/sql/sqlcomp/CmpDescribe.cpp +++ b/core/sql/sqlcomp/CmpDescribe.cpp @@ -2641,9 +2641,13 @@ short cmpDisplayColumn(const NAColumn *nac, defVal = "DEFAULT NULL"; else if (nac->getDefaultClass() == COM_CURRENT_DEFAULT) defVal = "DEFAULT CURRENT"; + else if (nac->getDefaultClass() == COM_CURRENT_UT_DEFAULT) + defVal = "DEFAULT CURRENT UNIXTIME"; else if (nac->getDefaultClass() == COM_USER_FUNCTION_DEFAULT) defVal = "DEFAULT USER"; - else if (nac->getDefaultClass() == COM_USER_DEFINED_DEFAULT) + else if (nac->getDefaultClass() == COM_UUID_DEFAULT) + defVal = "DEFAULT UUID"; + else if (nac->getDefaultClass() == COM_USER_DEFINED_DEFAULT || nac->getDefaultClass() == COM_FUNCTION_DEFINED_DEFAULT) { defVal = "DEFAULT "; http://git-wip-us.apache.org/repos/asf/trafodion/blob/6b800c34/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp index e767cec..3e602e8 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp @@ -3168,8 +3168,13 @@ short CmpSeabaseDDL::getColInfo(ElemDDLColDef * colNode, defaultClass = COM_IDENTITY_GENERATED_BY_DEFAULT; } else if (ie == NULL) - if (colNode->getComputedDefaultExpr().isNull()) + if (colNode->getComputedDefaultExpr().isNull() && colNode->getDefaultExprString().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; @@ -3190,6 +3195,24 @@ short CmpSeabaseDDL::getColInfo(ElemDDLColDef * colNode, { defaultClass = COM_CURRENT_DEFAULT; } + else if (ie->getOperatorType() == ITM_UNIX_TIMESTAMP) + { + defaultClass = COM_CURRENT_UT_DEFAULT; + } + else if ((ie->getOperatorType() == ITM_CAST) && + (ie->getChild(0)->castToItemExpr()->getOperatorType() == ITM_UNIX_TIMESTAMP)) + { + defaultClass = COM_CURRENT_UT_DEFAULT; + } + else if (ie->getOperatorType() == ITM_UNIQUE_ID) + { + defaultClass = COM_UUID_DEFAULT; + } + else if ((ie->getOperatorType() == ITM_CAST) && + (ie->getChild(0)->castToItemExpr()->getOperatorType() == ITM_UNIQUE_ID)) + { + defaultClass = COM_UUID_DEFAULT; + } else if ((ie->getOperatorType() == ITM_USER) || (ie->getOperatorType() == ITM_CURRENT_USER) || (ie->getOperatorType() == ITM_SESSION_USER)) http://git-wip-us.apache.org/repos/asf/trafodion/blob/6b800c34/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp index 248deef..6aa6760 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp @@ -5424,6 +5424,8 @@ void CmpSeabaseDDL::alterSeabaseTableAddColumn( if ((pDefVal) && (pDefVal->origOpType() != ITM_CURRENT_USER) && (pDefVal->origOpType() != ITM_CURRENT_TIMESTAMP) && + (pDefVal->origOpType() != ITM_UNIX_TIMESTAMP) && + (pDefVal->origOpType() != ITM_UNIQUE_ID) && (pDefVal->origOpType() != ITM_CAST)) { if (pDefVal->isNull()) @@ -11356,6 +11358,11 @@ Lng32 CmpSeabaseDDL::getSeabaseColumnInfo(ExeCliInterface *cliInterface, tableIsSalted = TRUE; } } + else if (colInfo.defaultClass == COM_FUNCTION_DEFINED_DEFAULT) + { + oi->get(14, data, len); + tempDefVal = data ; + } else if (colInfo.defaultClass == COM_NULL_DEFAULT) { tempDefVal = "NULL"; @@ -11368,6 +11375,14 @@ Lng32 CmpSeabaseDDL::getSeabaseColumnInfo(ExeCliInterface *cliInterface, { tempDefVal = "CURRENT_TIMESTAMP"; } + else if (colInfo.defaultClass == COM_CURRENT_UT_DEFAULT) + { + tempDefVal = "UNIX_TIMESTAMP()"; + } + else if (colInfo.defaultClass == COM_UUID_DEFAULT) + { + tempDefVal = "UUID()"; + } else if ((colInfo.defaultClass == COM_IDENTITY_GENERATED_BY_DEFAULT) || (colInfo.defaultClass == COM_IDENTITY_GENERATED_ALWAYS)) { http://git-wip-us.apache.org/repos/asf/trafodion/blob/6b800c34/core/sql/sqlcomp/CmpSeabaseDDLutil.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLutil.cpp b/core/sql/sqlcomp/CmpSeabaseDDLutil.cpp index 4b1fd68..c208424 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLutil.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLutil.cpp @@ -315,6 +315,9 @@ const literalAndEnumStruct ColumnDefaultClassXlateArray [] = {COM_USER_DEFINED_DEFAULT, COM_USER_DEFINED_DEFAULT_LIT}, {COM_USER_FUNCTION_DEFAULT, COM_USER_FUNCTION_DEFAULT_LIT}, {COM_CURRENT_DEFAULT, COM_CURRENT_DEFAULT_LIT}, + {COM_CURRENT_UT_DEFAULT, COM_CURRENT_UT_DEFAULT_LIT}, + {COM_UUID_DEFAULT, COM_UUID_DEFAULT_LIT}, + {COM_FUNCTION_DEFINED_DEFAULT, COM_FUNCTION_DEFINED_DEFAULT_LIT}, {COM_IDENTITY_GENERATED_BY_DEFAULT, COM_IDENTITY_GENERATED_BY_DEFAULT_LIT}, {COM_IDENTITY_GENERATED_ALWAYS, COM_IDENTITY_GENERATED_ALWAYS_LIT}, {COM_ALWAYS_COMPUTE_COMPUTED_COLUMN_DEFAULT, COM_ALWAYS_COMPUTE_COMPUTED_COLUMN_DEFAULT_LIT}, @@ -330,6 +333,9 @@ const literalAndEnumStruct ParamDefaultClassXlateArray [] = { {COM_NO_PARAM_DEFAULT, COM_NO_PARAM_DEFAULT_LIT}, // the default {COM_CURRENT_PARAM_DEFAULT, COM_CURRENT_PARAM_DEFAULT_LIT}, // e.g. DEFAULT CURRENT DATE + {COM_CURRENT_UT_PARAM_DEFAULT, COM_CURRENT_UT_PARAM_DEFAULT_LIT}, // e.g. DEFAULT CURRENT DATE + {COM_UUID_PARAM_DEFAULT, COM_UUID_PARAM_DEFAULT_LIT}, // e.g. DEFAULT CURRENT DATE + {COM_FUNCTION_DEFINED_PARAM_DEFAULT, COM_FUNCTION_DEFINED_PARAM_DEFAULT_LIT}, // e.g. DEFAULT CURRENT DATE {COM_NULL_PARAM_DEFAULT, COM_NULL_PARAM_DEFAULT_LIT}, // i.e. DEFAULT NULL {COM_USER_DEFINED_PARAM_DEFAULT, COM_USER_DEFINED_PARAM_DEFAULT_LIT}, // e.g. DEFAULT 'a-string-literal' {COM_USER_FUNCTION_PARAM_DEFAULT, COM_USER_FUNCTION_PARAM_DEFAULT_LIT}, // e.g. DEFAULT CURRENT USER