You are viewing a plain text version of this content. The canonical link for it is here.
Posted to codereview@trafodion.apache.org by anoopsharma00 <gi...@git.apache.org> on 2016/03/08 18:05:21 UTC

[GitHub] incubator-trafodion pull request: JIRA TRAFODION-1873

GitHub user anoopsharma00 opened a pull request:

    https://github.com/apache/incubator-trafodion/pull/371

    JIRA TRAFODION-1873

    Externalize support for to_date and to_char.
    Code cleanup and bug fixes.
    New test cases.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/anoopsharma00/incubator-trafodion ansharma_functions_br

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-trafodion/pull/371.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #371
    
----
commit 7526b83d21b8f7404a7f1527a83c23eaa8a178d3
Author: Cloud User <ce...@ansharma-2.novalocal>
Date:   2016-03-07T22:05:20Z

    datetime functions: commit #1

commit 5c1e4ba0a9fea95709dc39099ab0e67006afccb7
Author: Cloud User <ce...@ansharma-2.novalocal>
Date:   2016-03-07T22:06:12Z

    Merge remote branch 'origin/master' into ansharma_functions_br

commit ccb3e4441db6389a170651f0b4c2ce39b39e23f2
Author: Cloud User <ce...@ansharma-2.novalocal>
Date:   2016-03-08T14:43:20Z

    Merge remote branch 'origin/master' into ansharma_functions_br

commit 5fc9ce5fd412ca3ecac0fe149f863121c9dcb8f7
Author: Cloud User <ce...@ansharma-2.novalocal>
Date:   2016-03-08T16:57:50Z

    JIRA TRAFODION-1873 Support for to_date, to_char functions
    
    Support for to_date, to_char functions.
    Code cleanup and simplification.
    Bug fixes.
    New test regress/seabase/TEST030.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-trafodion pull request: JIRA TRAFODION-1873

Posted by DaveBirdsall <gi...@git.apache.org>.
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/371#discussion_r55446935
  
    --- Diff: core/sql/exp/exp_datetime.cpp ---
    @@ -2410,773 +2550,363 @@ ExpDatetime::convAsciiToDate(char *srcData,
       };
     
       switch (srcFormat) {
    -  case DATETIME_FORMAT_DEFAULT:
    -  case DATETIME_FORMAT_DEFAULT2:
    -  case DATETIME_FORMAT_TS3:
    +  case DATETIME_FORMAT_DEFAULT: // YYYY-MM-DD
         {
    -      // this is default format: yyyy-mm-dd. first, the year
    -      for (year = 0, i = 0; i < 4 && isDigit8859_1(*srcData); i++, srcData++)
    -#pragma nowarn(1506)   // warning elimination 
    -        year = year * 10 + *srcData - '0';
    -#pragma warn(1506)  // warning elimination 
    +      // the year
    +      if (convSrcDataToDst(4, srcData, 2, dstData, "-", heap, diagsArea))
    +        return -1;
     
    -      if (i < 4 || *srcData != '-') {
    -        // string contains non-digit or invalid delimiter
    -        //
    -        if (i < 4)
    -          ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_STRING_ERROR);
    -        ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    +      // the month
    +      if (convSrcDataToDst(2, srcData, 1, &dstData[2], "-", heap, diagsArea))
    +        return -1;
    +
    +      // the day
    +      if (convSrcDataToDst(2, srcData, 1, &dstData[3], NULL, heap, diagsArea))
    +        return -1;
    +    }; 
    +    break;
    +
    +  case DATETIME_FORMAT_DEFAULT2: // YYYY-MM
    +    {
    +      // the year
    +      if (convSrcDataToDst(4, srcData, 2, dstData, "-", heap, diagsArea))
             return -1;
    -      }
    -      str_cpy_all(dstData, (char *)&year, sizeof(year));
    -      srcData++;  // move on to the next field
     
           // the month
    -      if (isDigit8859_1(*srcData) && isDigit8859_1(*(srcData+1))) {
    -#pragma nowarn(1506)   // warning elimination 
    -        dstData[2] = char (*srcData - '0') * 10 + (*(srcData+1) - '0');
    -#pragma warn(1506)  // warning elimination 
    -      } else {
    -        // string contains non-digit charecter(s)
    -        //
    -        ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_STRING_ERROR);
    -        ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    +      if (convSrcDataToDst(2, srcData, 1, &dstData[2], NULL, heap, diagsArea))
    +        return -1;
    +
    +      // the day
    +      // day is not specified, fill in as '1' (first day of month).
    +      dstData[3] = 1;
    +    }; 
    +    break;
    +
    +  case DATETIME_FORMAT_TS3: // YYYY-MM-DD HH24:MI:SS
    +    {
    +      // the year
    +      if (convSrcDataToDst(4, srcData, 2, dstData, "-", heap, diagsArea))
             return -1;
    -      }
     
    -      srcData += 2;
    +      // the month
    +      if (convSrcDataToDst(2, srcData, 1, &dstData[2], "-", heap, diagsArea))
    +        return -1;
     
           // the day
    -      if (srcFormat == DATETIME_FORMAT_DEFAULT2)
    -	{
    -	  // day is not specified, fill in as '1' (first day of month).
    -	  dstData[3] = 1;
    -	}
    -      else
    -	{
    -	  if (*srcData != '-') {
    -	    // string contains invalid delimiter
    -	    //
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    -	    return -1;
    -	  }
    -	  srcData++;  // move on to the next field
    -	  
    -	  if (isDigit8859_1(*srcData) && isDigit8859_1(*(srcData+1))) {
    -#pragma nowarn(1506)   // warning elimination 
    -	    dstData[3] = char (*srcData - '0') * 10 + (*(srcData+1) - '0');
    -#pragma warn(1506)  // warning elimination 
    -	  } else {
    -	    // string contains non-digit charecter(s)
    -	    //
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_STRING_ERROR);
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    -	    return -1;
    -	  }
    -	  srcData += 2;
    -	}
    +      if (convSrcDataToDst(2, srcData, 1, &dstData[3], " ", heap, diagsArea))
    +        return -1;
    +      
    +      // the hour
    +      if (convSrcDataToDst(2, srcData, 1, &dstData[4], ":", heap, diagsArea))
    +        return -1;
     
    -      if (srcFormat == DATETIME_FORMAT_TS3)
    -	{
    -	  if (*srcData != ' ') {
    -	    // string contains invalid delimiter
    -	    //
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    -	    return -1;
    -	  }
    -	  srcData++;  // move on to the next field
    +      // the minute
    +      if (convSrcDataToDst(2, srcData, 1, &dstData[5], ":", heap, diagsArea))
    +        return -1;
     
    -	  // the hour
    -	  if (isDigit8859_1(*srcData) && isDigit8859_1(*(srcData+1))) {
    -#pragma nowarn(1506)   // warning elimination 
    -	    dstData[4] = char (*srcData - '0') * 10 + (*(srcData+1) - '0');
    -#pragma warn(1506)  // warning elimination 
    -	  } else {
    -	    // string contains non-digit charecter(s)
    -	    //
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_STRING_ERROR);
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    -	    return -1;
    -	  }
    -	  
    -	  srcData += 2;
    +      // the second
    +      if (convSrcDataToDst(2, srcData, 1, &dstData[6], NULL, heap, diagsArea))
    +        return -1;
     
    -	  if (*srcData != ':') {
    -	    // string contains invalid delimiter
    -	    //
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    -	    return -1;
    -	  }
    -	  srcData++;  // move on to the next field
    -	  
    -	  // the minute
    -	  if (isDigit8859_1(*srcData) && isDigit8859_1(*(srcData+1))) {
    -#pragma nowarn(1506)   // warning elimination 
    -	    dstData[5] = char (*srcData - '0') * 10 + (*(srcData+1) - '0');
    -#pragma warn(1506)  // warning elimination 
    -	  } else {
    -	    // string contains non-digit charecter(s)
    -	    //
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_STRING_ERROR);
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    -	    return -1;
    -	  }
    -	  
    -	  srcData += 2;
    -	  if (*srcData != ':') {
    -	    // string contains invalid delimiter
    -	    //
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    -	    return -1;
    -	  }
    -	  srcData++;  // move on to the next field
    -	  
    -	  // the second
    -	  if (isDigit8859_1(*srcData) && isDigit8859_1(*(srcData+1))) {
    -#pragma nowarn(1506)   // warning elimination 
    -	    dstData[6] = char (*srcData - '0') * 10 + (*(srcData+1) - '0');
    -#pragma warn(1506)  // warning elimination 
    -	  } else {
    -	    // string contains non-digit charecter(s)
    -	    //
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_STRING_ERROR);
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    -	    return -1;
    -	  }
    -	  
    -	  srcData += 2;
    -	  
    -	  dstData[7]  = 0;
    -	  dstData[8]  = 0;
    -	  dstData[9]  = 0;
    -	  dstData[10] = 0;
    -	}
    -    };  // case DEFAULT format
    +      dstData[7]  = 0;
    +      dstData[8]  = 0;
    +      dstData[9]  = 0;
    +      dstData[10] = 0;
    +    };  
         break;
     
    -  case DATETIME_FORMAT_USA:
    +  case DATETIME_FORMAT_USA:   // MM/DD/YYYY AM|PM
       case DATETIME_FORMAT_USA2:  // MM/DD/YYYY
       case DATETIME_FORMAT_USA6:  // MM/DD/YY
       case DATETIME_FORMAT_USA7:  // MM-DD-YYYY
    -  case DATETIME_FORMAT_TS6:   // MMDDYYYY HH24:MI:SS
    -  case DATETIME_FORMAT_TS7:   // MM/DD/YYYY HH24:MI:SS
         {
    -      // this is USA format: mm/dd/yyyy. first, the month
    -      if (isDigit8859_1(*srcData) && isDigit8859_1(*(srcData+1))) {
    -#pragma nowarn(1506)   // warning elimination 
    -        dstData[2] = char (*srcData - '0') * 10 + (*(srcData+1) - '0');
    -#pragma warn(1506)  // warning elimination 
    -      } else {
    -        // string contains non-digit charecter(s)
    -        //
    -        ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_STRING_ERROR);
    -        ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    -        return -1;
    -      }
    +      char sep = (srcFormat == DATETIME_FORMAT_USA7 ? '-' : '/');
     
    -      char delim = (srcFormat == DATETIME_FORMAT_USA7 ? '-' 
    -		    : (srcFormat == DATETIME_FORMAT_TS6 ? 0 : '/'));
    -      srcData += 2;  // move on to the delimiter field
    -      if (delim != 0)
    -	{
    -	  if (*srcData != delim) {
    -	    // string contains invalid delimiter
    -	    //
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    -	    return -1;
    -	  }
    -	  srcData++;  // move on to the next field
    -	}
    +      // the month
    +      if (convSrcDataToDst(2, srcData, 1, &dstData[2], &sep, heap,diagsArea))
    +        return -1;
     
           // the day
    -      if (isDigit8859_1(*srcData) && isDigit8859_1(*(srcData+1))) {
    -#pragma nowarn(1506)   // warning elimination 
    -        dstData[3] = char (*srcData - '0') * 10 + (*(srcData+1) - '0');
    -#pragma warn(1506)  // warning elimination 
    -      } else {
    -        // string contains non-digit charecter(s)
    -        //
    -        ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_STRING_ERROR);
    -        ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    +      if (convSrcDataToDst(2, srcData, 1, &dstData[3], &sep, heap, diagsArea))
             return -1;
    -      }
     
    -      srcData += 2;  // move on to the delimiter field
    +      // the year
    +      Int32 numOfYdigits = (srcFormat == DATETIME_FORMAT_USA6 ? 2 : 4);
    +      if (convSrcDataToDst(numOfYdigits, srcData, 2, dstData, NULL, heap, diagsArea))
    +        return -1;
    +    }; 
    +    break;
     
    -      if (delim != 0)
    -	{
    -	  if (*srcData != delim) {
    -	    // string contains invalid delimiter
    -	    //
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    -	    return -1;
    -	  }
    -	  srcData++;  // move on to the next field
    -	}
    +  case DATETIME_FORMAT_TS6:   // MMDDYYYY HH24:MI:SS
    +  case DATETIME_FORMAT_TS7:   // MM/DD/YYYY HH24:MI:SS
    +    {
    +      char sep = '/';
    +      char * septr = (srcFormat == DATETIME_FORMAT_TS7 ? &sep : NULL);
    +
    +      // the month
    +      if (convSrcDataToDst(2, srcData, 1, &dstData[2], septr, heap, diagsArea))
    +        return -1;
     
    +      // the day
    +      if (convSrcDataToDst(2, srcData, 1, &dstData[3], septr, heap, diagsArea))
    +        return -1;
    +      
           // the year
    -      Int32 numOfYdigits = (srcFormat == DATETIME_FORMAT_USA6 ? 2 : 4);
    -      for (year = 0, i = 0; i < numOfYdigits && isDigit8859_1(*srcData); i++, srcData++)
    -#pragma nowarn(1506)   // warning elimination 
    -        year = year * 10 + *srcData - '0';
    -#pragma warn(1506)  // warning elimination 
    +      if (convSrcDataToDst(4, srcData, 2, dstData, " ", heap, diagsArea))
    +        return -1;
     
    -      if (i < numOfYdigits) {
    -        // string contains non-digit
    -        //
    -        ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_STRING_ERROR);
    -        ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    +      // the hour
    +      if (convSrcDataToDst(2, srcData, 1, &dstData[4], ":", heap, diagsArea))
             return -1;
    -      }
     
    -      str_cpy_all(dstData, (char *)&year, sizeof(year));
    -      if ((srcFormat == DATETIME_FORMAT_TS6) ||
    -	  (srcFormat == DATETIME_FORMAT_TS7))
    -	{
    -	  if (*srcData != ' ') {
    -	    // string contains invalid delimiter
    -	    //
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    -	    return -1;
    -	  }
    -	  srcData++;  // move on to the next field
    +      // the minute
    +      if (convSrcDataToDst(2, srcData, 1, &dstData[5], ":", heap, diagsArea))
    +        return -1;
     
    -	  // the hour
    -	  if (isDigit8859_1(*srcData) && isDigit8859_1(*(srcData+1))) {
    -#pragma nowarn(1506)   // warning elimination 
    -	    dstData[4] = char (*srcData - '0') * 10 + (*(srcData+1) - '0');
    -#pragma warn(1506)  // warning elimination 
    -	  } else {
    -	    // string contains non-digit charecter(s)
    -	    //
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_STRING_ERROR);
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    -	    return -1;
    -	  }
    -	  
    -	  srcData += 2;
    +      // the second
    +      if (convSrcDataToDst(2, srcData, 1, &dstData[6], NULL, heap, diagsArea))
    +        return -1;
     
    -	  if (*srcData != ':') {
    -	    // string contains invalid delimiter
    -	    //
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    -	    return -1;
    -	  }
    -	  srcData++;  // move on to the next field
    -	  
    -	  // the minute
    -	  if (isDigit8859_1(*srcData) && isDigit8859_1(*(srcData+1))) {
    -#pragma nowarn(1506)   // warning elimination 
    -	    dstData[5] = char (*srcData - '0') * 10 + (*(srcData+1) - '0');
    -#pragma warn(1506)  // warning elimination 
    -	  } else {
    -	    // string contains non-digit charecter(s)
    -	    //
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_STRING_ERROR);
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    -	    return -1;
    -	  }
    -	  
    -	  srcData += 2;
    -	  if (*srcData != ':') {
    -	    // string contains invalid delimiter
    -	    //
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    -	    return -1;
    -	  }
    -	  srcData++;  // move on to the next field
    -	  
    -	  // the second
    -	  if (isDigit8859_1(*srcData) && isDigit8859_1(*(srcData+1))) {
    -#pragma nowarn(1506)   // warning elimination 
    -	    dstData[6] = char (*srcData - '0') * 10 + (*(srcData+1) - '0');
    -#pragma warn(1506)  // warning elimination 
    -	  } else {
    -	    // string contains non-digit charecter(s)
    -	    //
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_STRING_ERROR);
    -	    ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    -	    return -1;
    -	  }
    -	  
    -	  srcData += 2;
    -	  
    -	  dstData[7]  = 0;
    -	  dstData[8]  = 0;
    -	  dstData[9]  = 0;
    -	  dstData[10] = 0;
    -	}
    -    };  // case USA format
    +      dstData[7]  = 0;
    +      dstData[8]  = 0;
    +      dstData[9]  = 0;
    +      dstData[10] = 0;
    +     };
         break;
     
    -  case DATETIME_FORMAT_USA3:
    -  case DATETIME_FORMAT_USA4:
    -  case DATETIME_FORMAT_USA5:
    -  case DATETIME_FORMAT_USA8:
    +  case DATETIME_FORMAT_USA3: // YYYY/MM/DD
    +  case DATETIME_FORMAT_USA4: // YYYYMMDD
    +  case DATETIME_FORMAT_USA5: // YY/MM/DD
         {
    -      // this is USA format: See exp_datetime.h for details.
    +      // the year
    +      Lng32 numYearDigits = (srcFormat == DATETIME_FORMAT_USA5 ? 2 : 4);
    +      char sep = '/';
    +      char * septr = (srcFormat == DATETIME_FORMAT_USA4 ? NULL : &sep);
     
           // the year
    -      Lng32 numYearDigits = 4;
    -      if (srcFormat == DATETIME_FORMAT_USA5)
    -	numYearDigits = 2;
    -      for (year = 0, i = 0; 
    -	   i < numYearDigits && isDigit8859_1(*srcData); i++, srcData++)
    -#pragma nowarn(1506)   // warning elimination 
    -        year = year * 10 + *srcData - '0';
    -#pragma warn(1506)  // warning elimination 
    +      if (convSrcDataToDst(numYearDigits, srcData, 2, dstData, septr, heap, diagsArea))
    +        return -1;
    --- End diff --
    
    Do we need to add 2000 to (short)dstData when it is a YY format (as opposed to a YYYY format)?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-trafodion pull request: JIRA TRAFODION-1873

Posted by DaveBirdsall <gi...@git.apache.org>.
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/371#discussion_r55447498
  
    --- Diff: core/sql/exp/exp_datetime.h ---
    @@ -49,67 +49,65 @@
     class SQLEXP_LIB_FUNC  ExpDatetime : public SimpleType {
     
     public:
    -  enum asciiFormats 
    +  // these enums must be in the same order as the datetimeFormat[] array 
    +  // (defined in exp_datetime.cpp).
    +  enum DatetimeFormats 
       { 
    -    DATETIME_FORMAT_DEFAULT  = 0,  // YYYY-MM-DD
    -    DATETIME_FORMAT_USA      = 1,  // MM/DD/YYYY AM|PM
    -    DATETIME_FORMAT_EUROPEAN = 2,  // DD.MM.YYYY
    -    DATETIME_FORMAT_DEFAULT2,      // YYYY-MM
    -    DATETIME_FORMAT_USA2,          // MM/DD/YYYY
    -    DATETIME_FORMAT_USA3,          // YYYY/MM/DD
    -    DATETIME_FORMAT_USA4,          // YYYYMMDD
    -    DATETIME_FORMAT_USA5,          // YY/MM/DD
    -    DATETIME_FORMAT_USA6,          // MM/DD/YY
    -    DATETIME_FORMAT_USA7,          // MM-DD-YYYY
    -    DATETIME_FORMAT_USA8,          // YYYYMM
    -    DATETIME_FORMAT_EUROPEAN2,     // DD-MM-YYYY
    -    DATETIME_FORMAT_EUROPEAN3,     // DD-MON-YYYY
    -    DATETIME_FORMAT_EUROPEAN4,     // DDMONYYYY
    -    DATETIME_FORMAT_TIME1,         // 99:99:99:99
    -    DATETIME_FORMAT_TIME2,         // -99:99:99:99
    -    DATETIME_FORMAT_TS1,           // YYYYMMDDHH24MISS
    -    DATETIME_FORMAT_TS2,           // DD.MM.YYYY:HH24:MI:SS
    -    DATETIME_FORMAT_TS3,           // YYYY-MM-DD HH24:MI:SS
    -    DATETIME_FORMAT_TS4,           // HH24:MI:SS
    -    DATETIME_FORMAT_TS5,           // YYYYMMDD:HH24:MI:SS
    -    DATETIME_FORMAT_TS6,           // MMDDYYYY HH24:MI:SS
    -    DATETIME_FORMAT_TS7,           // MM/DD/YYYY HH24:MI:SS
    -    DATETIME_FORMAT_TS8,           // DD-MON-YYYY HH:MI:SS
    -    DATETIME_FORMAT_DATE_STR,      // format in str
    -    DATETIME_FORMAT_TIME_STR,      // format in str
    +    DATETIME_FORMAT_MIN       =  0,
    +    DATETIME_FORMAT_MIN_DATE  =  DATETIME_FORMAT_MIN,
    +    DATETIME_FORMAT_DEFAULT   =  DATETIME_FORMAT_MIN_DATE, // YYYY-MM-DD
    +    DATETIME_FORMAT_USA,        // MM/DD/YYYY AM|PM
    +    DATETIME_FORMAT_EUROPEAN,   // DD.MM.YYYY
    +    DATETIME_FORMAT_DEFAULT2,   // YYYY-MM
    +    DATETIME_FORMAT_USA2,       // MM/DD/YYYY
    +    DATETIME_FORMAT_USA3,       // YYYY/MM/DD
    +    DATETIME_FORMAT_USA4,       // YYYYMMDD
    +    DATETIME_FORMAT_USA5,       // YY/MM/DD
    +    DATETIME_FORMAT_USA6,       // MM/DD/YY
    +    DATETIME_FORMAT_USA7,       // MM-DD-YYYY
    +    DATETIME_FORMAT_USA8,       // YYYYMM
    +    DATETIME_FORMAT_EUROPEAN2,  // DD-MM-YYYY
    +    DATETIME_FORMAT_EUROPEAN3,  // DD-MON-YYYY
    +    DATETIME_FORMAT_EUROPEAN4,  // DDMONYYYY
    +    DATETIME_FORMAT_MAX_DATE  = DATETIME_FORMAT_EUROPEAN4,
    +
    +    DATETIME_FORMAT_MIN_TIME,
    +    DATETIME_FORMAT_TS4       = DATETIME_FORMAT_MIN_TIME, // HH24:MI:SS
    +    DATETIME_FORMAT_MAX_TIME  = DATETIME_FORMAT_TS4,
    +
    +    DATETIME_FORMAT_MIN_TS,
    +    DATETIME_FORMAT_TS1       = DATETIME_FORMAT_MIN_TS, // YYYYMMDDHH24MISS
    +    DATETIME_FORMAT_TS2,     // DD.MM.YYYY:HH24:MI:SS
    +    DATETIME_FORMAT_TS3,     // YYYY-MM-DD HH24:MI:SS
    +    DATETIME_FORMAT_TS5,     // YYYYMMDD:HH24:MI:SS
    +    DATETIME_FORMAT_TS6,     // MMDDYYYY HH24:MI:SS
    +    DATETIME_FORMAT_TS7,     // MM/DD/YYYY HH24:MI:SS
    +    DATETIME_FORMAT_TS8,     // DD-MON-YYYY HH:MI:SS
    +    DATETIME_FORMAT_TS9,     // MONTH DD, YYYY, HH:MI AM|PM
    +    DATETIME_FORMAT_MAX_TS    = DATETIME_FORMAT_TS9,
    +
    +    DATETIME_FORMAT_MAX       = DATETIME_FORMAT_MAX_TS,
    +
    +    DATETIME_FORMAT_MIN_NUM = DATETIME_FORMAT_MAX,
    +    DATETIME_FORMAT_NUM1,     // 99:99:99:99
    +    DATETIME_FORMAT_NUM2,     // -99:99:99:99
    +    DATETIME_FORMAT_MAX_NUM = DATETIME_FORMAT_NUM2,
    +
    +    DATETIME_FORMAT_DATE_STR, // format in str
    +    DATETIME_FORMAT_TIME_STR, // format in str
         DATETIME_FORMAT_NONE,
    -    DATETIME_FORMAT_ERROR
    +    DATETIME_FORMAT_ERROR     = -1
       };
    -  enum asciiFormtLen {
    -    DATETIME_FORMAT_DEFAULT_LEN   = 10,  // YYYY-MM-DD
    -    DATETIME_FORMAT_USA_LEN       = 10,  // MM/DD/YYYY AM|PM
    -    DATETIME_FORMAT_EUROPEAN_LEN  = 10,  // DD.MM.YYYY
    -    DATETIME_FORMAT_DEFAULT2_LEN  =  7,  // YYYY-MM
    -    DATETIME_FORMAT_USA2_LEN      = 10,  // MM/DD/YYYY
    -    DATETIME_FORMAT_USA3_LEN      = 10,  // YYYY/MM/DD
    -    DATETIME_FORMAT_USA4_LEN      =  8,  // YYYYMMDD
    -    DATETIME_FORMAT_USA5_LEN      =  8,  // YY/MM/DD
    -    DATETIME_FORMAT_USA6_LEN      =  8,  // MM/DD/YY
    -    DATETIME_FORMAT_USA7_LEN      = 10,  // MM-DD-YYYY
    -    DATETIME_FORMAT_USA8_LEN      =  6,  // YYYYMM
    -    DATETIME_FORMAT_EUROPEAN2_LEN = 10,  // DD-MM-YYYY
    -    DATETIME_FORMAT_EUROPEAN3_LEN = 11,  // DD-MON-YYYY
    -    DATETIME_FORMAT_EUROPEAN4_LEN =  9,  // DDMONYYYY
    -    DATETIME_FORMAT_TIME1_LEN     = 11,  // 99:99:99:99
    -    DATETIME_FORMAT_TIME2_LEN     = 12,  // -99:99:99:99
    -    DATETIME_FORMAT_TS1_LEN       = 14,  // YYYYMMDDHH24MISS
    -    DATETIME_FORMAT_TS2_LEN       = 19,  // DD.MM.YYYY:HH24:MI:SS
    -    DATETIME_FORMAT_TS3_LEN       = 19,  // YYYY-MM-DD HH24:MI:SS
    -    DATETIME_FORMAT_TS4_LEN       =  8,  // HH24:MI:SS
    -    DATETIME_FORMAT_TS5_LEN       = 17,  // YYYYMMDD:HH24:MI:SS
    -    DATETIME_FORMAT_TS6_LEN       = 17,  // MMDDYYYY HH24:MI:SS
    -    DATETIME_FORMAT_TS7_LEN       = 19,  // MM/DD/YYYY HH24:MI:SS
    -    DATETIME_FORMAT_TS8_LEN       = 20,  // DD-MON-YYYY HH:MI:SS
    -    DATETIME_FORMAT_DATE_STR_LEN  = -1,  // format in str
    -    DATETIME_FORMAT_TIME_STR_LEN  = -1,  // format in str
    -    DATETIME_FORMAT_NONE_LEN      = -1,
    -    DATETIME_FORMAT_ERROR_LEN     = -1
    +
    +  struct DatetimeFormatInfo
    +  {
    +    Lng32 format;       // defined by enum DatetimeFormats
    --- End diff --
    
    Could define this as DatetimeFormats format;


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-trafodion pull request: JIRA TRAFODION-1873

Posted by DaveBirdsall <gi...@git.apache.org>.
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/371#discussion_r55446526
  
    --- Diff: core/sql/exp/exp_datetime.cpp ---
    @@ -2337,6 +2430,50 @@ convertStrToMonth(char * value, char *result)
       return FALSE;
     }
     
    +static short convSrcDataToDst(Lng32 numSrcBytes, char* &srcData, 
    +                               Lng32 numTgtBytes, char *dstData,
    +                               const char * nextByte,
    +                               CollHeap * heap, ComDiagsArea** diagsArea)
    +{
    +  Lng32 src = 0;
    +  Lng32 val = 0;
    +  for (val = 0, src = 0; src < numSrcBytes && isDigit8859_1(*srcData); 
    +       src++, srcData++)
    +    val = val * 10 + (*srcData - '0');
    --- End diff --
    
    Never mind... looks like we depend on the caller to limit numSrcBytes so that overflows don't occur.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-trafodion pull request: JIRA TRAFODION-1873

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-trafodion/pull/371


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-trafodion pull request: JIRA TRAFODION-1873

Posted by DaveBirdsall <gi...@git.apache.org>.
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/371#discussion_r55446102
  
    --- Diff: core/sql/exp/exp_datetime.cpp ---
    @@ -2337,6 +2430,50 @@ convertStrToMonth(char * value, char *result)
       return FALSE;
     }
     
    +static short convSrcDataToDst(Lng32 numSrcBytes, char* &srcData, 
    +                               Lng32 numTgtBytes, char *dstData,
    +                               const char * nextByte,
    +                               CollHeap * heap, ComDiagsArea** diagsArea)
    +{
    +  Lng32 src = 0;
    +  Lng32 val = 0;
    +  for (val = 0, src = 0; src < numSrcBytes && isDigit8859_1(*srcData); 
    +       src++, srcData++)
    +    val = val * 10 + (*srcData - '0');
    --- End diff --
    
    Could overflow, which gives us a value modulo 32. Is this OK?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-trafodion pull request: JIRA TRAFODION-1873

Posted by DaveBirdsall <gi...@git.apache.org>.
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/371#discussion_r55395195
  
    --- Diff: core/sql/exp/exp_datetime.cpp ---
    @@ -91,6 +91,50 @@ copyDatetimeFields(rec_datetime_field startField,
                        char *dstData,
                        NABoolean *roundedDownFlag);
     
    +//////////////////////////////////////////////
    +// Defined in exp_datetime.h
    +//
    +//  struct DatetimeFormatInfo
    +//  {
    +//    Lng32 format;
    --- End diff --
    
    Could change the datatype here to an enum, with a slight improvement in type saftey


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-trafodion pull request: JIRA TRAFODION-1873

Posted by DaveBirdsall <gi...@git.apache.org>.
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/371#discussion_r55446152
  
    --- Diff: core/sql/exp/exp_datetime.cpp ---
    @@ -2337,6 +2430,50 @@ convertStrToMonth(char * value, char *result)
       return FALSE;
     }
     
    +static short convSrcDataToDst(Lng32 numSrcBytes, char* &srcData, 
    +                               Lng32 numTgtBytes, char *dstData,
    +                               const char * nextByte,
    +                               CollHeap * heap, ComDiagsArea** diagsArea)
    +{
    +  Lng32 src = 0;
    +  Lng32 val = 0;
    +  for (val = 0, src = 0; src < numSrcBytes && isDigit8859_1(*srcData); 
    +       src++, srcData++)
    +    val = val * 10 + (*srcData - '0');
    +  
    +  if (src < numSrcBytes) 
    +    {
    +      // string contains non-digit
    +      //
    +      ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    +      return -1;
    +    }
    +
    +  if (numTgtBytes == sizeof(Lng32))
    +    *(Lng32*)dstData = val;
    +  else if (numTgtBytes == sizeof(short))
    +    *(short*)dstData = val;
    +  else if (numTgtBytes == sizeof(char))
    +    *(char*)dstData = val;
    +  else 
    --- End diff --
    
    Do we know there won't be overflows on the assignments above? (Do we care?)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-trafodion pull request: JIRA TRAFODION-1873

Posted by DaveBirdsall <gi...@git.apache.org>.
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/371#discussion_r55447961
  
    --- Diff: core/sql/exp/exp_datetime.h ---
    @@ -323,11 +319,81 @@ static
       NA_EIDPROC virtual short getClassSize() { return (short)sizeof(*this); }
       // ---------------------------------------------------------------------
     
    +  static const char * getDatetimeFormatStr(Lng32 frmt)
    +  {
    +    return datetimeFormat[frmt].str;
    +  }
    +
    +  static const Lng32 getDatetimeFormat(const char * formatStr)
    +  {
    +    for (Lng32 i = DATETIME_FORMAT_MIN; i <= DATETIME_FORMAT_MAX; i++)
    +      {
    +        if (strcmp(formatStr, datetimeFormat[i].str) == 0)
    +          {
    +            if (datetimeFormat[i].format != i)
    +              return -1;
    --- End diff --
    
    I take it this is a guard against ExpDatetime::datetimeFormat being screwed up?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-trafodion pull request: JIRA TRAFODION-1873

Posted by DaveBirdsall <gi...@git.apache.org>.
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/371#discussion_r55446597
  
    --- Diff: core/sql/exp/exp_datetime.cpp ---
    @@ -2337,6 +2430,50 @@ convertStrToMonth(char * value, char *result)
       return FALSE;
     }
     
    +static short convSrcDataToDst(Lng32 numSrcBytes, char* &srcData, 
    +                               Lng32 numTgtBytes, char *dstData,
    +                               const char * nextByte,
    +                               CollHeap * heap, ComDiagsArea** diagsArea)
    +{
    +  Lng32 src = 0;
    +  Lng32 val = 0;
    +  for (val = 0, src = 0; src < numSrcBytes && isDigit8859_1(*srcData); 
    +       src++, srcData++)
    +    val = val * 10 + (*srcData - '0');
    +  
    +  if (src < numSrcBytes) 
    +    {
    +      // string contains non-digit
    +      //
    +      ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_DATETIME_ERROR);
    +      return -1;
    +    }
    +
    +  if (numTgtBytes == sizeof(Lng32))
    +    *(Lng32*)dstData = val;
    +  else if (numTgtBytes == sizeof(short))
    +    *(short*)dstData = val;
    +  else if (numTgtBytes == sizeof(char))
    +    *(char*)dstData = val;
    +  else 
    --- End diff --
    
    Never mind. Looks like we depend on the caller to make sure conditions are such that overflows will not occur.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---