add nonreserved_word and tests
Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/cd3ef4b8 Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/cd3ef4b8 Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/cd3ef4b8 Branch: refs/heads/master Commit: cd3ef4b863916a472bde262e49a5a3021aa79bfa Parents: fc8873c Author: kakaxi3019 <[email protected]> Authored: Thu Jul 5 14:24:02 2018 +0800 Committer: kakaxi3019 <[email protected]> Committed: Thu Jul 5 14:24:02 2018 +0800 ---------------------------------------------------------------------- core/sql/exp/exp_function.cpp | 23 ++++++++++++++--------- core/sql/optimizer/SynthType.cpp | 4 +++- core/sql/parser/sqlparser.y | 6 ++++++ core/sql/regress/seabase/EXPECTED030 | 24 ++++++++++++++++++++++++ core/sql/regress/seabase/TEST030 | 3 +++ 5 files changed, 50 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafodion/blob/cd3ef4b8/core/sql/exp/exp_function.cpp ---------------------------------------------------------------------- diff --git a/core/sql/exp/exp_function.cpp b/core/sql/exp/exp_function.cpp index a5afbc8..ca51354 100644 --- a/core/sql/exp/exp_function.cpp +++ b/core/sql/exp/exp_function.cpp @@ -3056,22 +3056,27 @@ static Int64 lcl_interval(rec_datetime_field eField, Lng32 eCode, char *opdata, { short nValue; str_cpy_all((char *) &nValue, opdata, sizeof(nValue)); - if( nValue<=0 ) - return 0; return (nValue-1)/3+1; } if ( REC_DATE_EPOCH == eField ) { - size_t n = 0; + Int64 nVal = 0; if ( SQL_SMALL_SIZE==nLength ) - n = sizeof(short); + { + short value; + str_cpy_all((char *) &value, opdata, sizeof(value)); + nVal = value; + } else if ( SQL_INT_SIZE==nLength ) - n = sizeof(Lng32); + { + Lng32 value; + str_cpy_all((char *) &value, opdata, sizeof(value)); + nVal = value; + } else if ( SQL_LARGE_SIZE==nLength ) - n = sizeof(Int64); - - Int64 nVal = 0; - str_cpy_all((char *) &nVal, opdata, n); + { + str_cpy_all((char *) &nVal, opdata, sizeof(nVal)); + } if ( REC_INT_YEAR==eCode ) return nVal*DAYS_PER_YEAR*SECONDS_PER_DAY; http://git-wip-us.apache.org/repos/asf/trafodion/blob/cd3ef4b8/core/sql/optimizer/SynthType.cpp ---------------------------------------------------------------------- diff --git a/core/sql/optimizer/SynthType.cpp b/core/sql/optimizer/SynthType.cpp index c678aa8..eaf4b89 100644 --- a/core/sql/optimizer/SynthType.cpp +++ b/core/sql/optimizer/SynthType.cpp @@ -4509,7 +4509,9 @@ const NAType *Extract::synthesizeType() scale += dti.getFractionPrecision(); } NABoolean bNegValue = FALSE; - if ( getExtractField() >= REC_DATE_CENTURY && extractStartField <= REC_DATE_WOM ) + if (getExtractField() == REC_DATE_DECADE + || getExtractField() == REC_DATE_QUARTER + || getExtractField() == REC_DATE_EPOCH ) bNegValue = TRUE; const Int16 disAmbiguate = 0; // added for 64bit project return new HEAP http://git-wip-us.apache.org/repos/asf/trafodion/blob/cd3ef4b8/core/sql/parser/sqlparser.y ---------------------------------------------------------------------- diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y index 002d719..3999c37 100755 --- a/core/sql/parser/sqlparser.y +++ b/core/sql/parser/sqlparser.y @@ -33731,6 +33731,7 @@ nonreserved_word : TOK_ABORT | TOK_CATALOGS | TOK_CATALOG_NAME | TOK_CATCHUP // MV + | TOK_CENTURY | TOK_CHANGED | TOK_CHANGES // MV | TOK_CHARS @@ -33800,6 +33801,7 @@ nonreserved_word : TOK_ABORT | TOK_DCOMPRESS | TOK_DDL | TOK_DE // MV OZ_REFRESH + | TOK_DECADE | TOK_DEFINER | TOK_DEFINITION | TOK_DEFAULTS @@ -33816,6 +33818,8 @@ nonreserved_word : TOK_ABORT | TOK_DIVISION | TOK_DO | TOK_DOUBLE_IEEE + | TOK_DOW + | TOK_DOY | TOK_DROP_LIBRARY | TOK_DROP_MV | TOK_DROP_MV_GROUP @@ -33838,6 +33842,7 @@ nonreserved_word : TOK_ABORT | TOK_ENTERPRISE | TOK_ENTRY | TOK_ENTRIES + | TOK_EPOCH | TOK_ET | TOK_EUROPEAN | TOK_EXCEPTIONS @@ -34208,6 +34213,7 @@ nonreserved_word : TOK_ABORT | TOK_VSBB | TOK_WAITED | TOK_WAITEDIO + | TOK_WOM // New words added can be merged into sorted list above | TOK_INVOKE http://git-wip-us.apache.org/repos/asf/trafodion/blob/cd3ef4b8/core/sql/regress/seabase/EXPECTED030 ---------------------------------------------------------------------- diff --git a/core/sql/regress/seabase/EXPECTED030 b/core/sql/regress/seabase/EXPECTED030 index dc03a1e..ea32fdf 100644 --- a/core/sql/regress/seabase/EXPECTED030 +++ b/core/sql/regress/seabase/EXPECTED030 @@ -589,6 +589,30 @@ March 01, 2016, 10:11 3 --- 1 row(s) selected. +>>select extract(century from timestamp '2001-01-01 12:30:00') from (values(1)) as t(a); + +(EXPR) +------ + + 21 + +--- 1 row(s) selected. +>>select extract(decade from interval '9' year - interval '99' year) from (values(1)) as t(a); + +(EXPR) +------ + + -9 + +--- 1 row(s) selected. +>>select extract(quarter from interval '09' month) from (values(1)) as t(a); + +(EXPR) +------ + + 3 + +--- 1 row(s) selected. >> >>drop table if exists t030t1; http://git-wip-us.apache.org/repos/asf/trafodion/blob/cd3ef4b8/core/sql/regress/seabase/TEST030 ---------------------------------------------------------------------- diff --git a/core/sql/regress/seabase/TEST030 b/core/sql/regress/seabase/TEST030 index ef9af49..5a85c5c 100644 --- a/core/sql/regress/seabase/TEST030 +++ b/core/sql/regress/seabase/TEST030 @@ -103,6 +103,9 @@ select extract(epoch from timestamp '2000-12-30 20:38:40.12') from (values(1)) a select extract(dow from timestamp '2018-06-21 20:38:40') from (values(1)) as t(a); select extract(doy from timestamp '2018-06-21 20:38:40') from (values(1)) as t(a); select extract(wom from timestamp '2018-06-21 20:38:40') from (values(1)) as t(a); +select extract(century from timestamp '2001-01-01 12:30:00') from (values(1)) as t(a); +select extract(decade from interval '9' year - interval '99' year) from (values(1)) as t(a); +select extract(quarter from interval '09' month) from (values(1)) as t(a); drop table if exists t030t1; create table t030t1 (a date, b char(30), c varchar(30), d timestamp);
