trafodion-codereview mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traflm <...@git.apache.org>
Subject [GitHub] incubator-trafodion pull request #703: [TRAFODION-2208] function support: lo...
Date Thu, 15 Sep 2016 09:52:50 GMT
Github user traflm commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/703#discussion_r78925918
  
    --- Diff: core/sql/exp/exp_function.cpp ---
    @@ -7724,5 +7753,354 @@ Lng32 ExFunctionExtractColumns::unpack (void * base, void * reallocator)
        if (extractColList_.unpack(base)) return -1;
        return unpackClause(base, reallocator);
     }
    +
    +//helper function, convert a string into IPV4 , if valid, it can support leading and
padding space
    +static Lng32 string2ipv4(char *srcData, Lng32 slen, unsigned int *inet_addr)
    +{
    +   Int16 i = 0, j = 0 , p=0, leadingspace=0;
    +   char buf[16]; 
    +   Int16 dot=0;
    +
    +   if(slen < MIN_IPV4_STRING_LEN ) 
    +     return 0;
    +
    +   unsigned char *ipv4_bytes= (unsigned char *)inet_addr;
    +
    +   if(srcData[0] == ' ')
    +   { 
    +     leadingspace++;
    +     for(i=1; i< slen; i++)
    +     {
    +       if(srcData[i] == ' ') leadingspace++;
    +       else break; 
    +     }
    +   }
    +   
    +      
    +   for(i=leadingspace , j = 0; i < slen ; i++)
    +   {
    +      if(srcData[i] == '.')
    +      {
    +         buf[j]=0;
    +         p = str_atoi(buf, j);
    +         if( p < 0 || p > 255 || j == 0) 
    +         {
    +           return 0;
    +         }
    +         else
    +         {
    +           if(ipv4_bytes)
    +             ipv4_bytes[dot] = (unsigned char)p;
    +         }
    +         j = 0;
    +         dot++;
    +         if(dot > 3) return 0;
    +      }
    +      else if(srcData[i] == ' ')
    +      {
    +        break; //space is terminator
    +      }
    +      else
    +      {
    +        if(isdigit(srcData[i]) == 0) 
    +         {
    +           return 0;
    +         }
    +        else
    +         buf[j] = srcData[i];
    +        j++;
    +      }
    +   } 
    +   Int16 stoppos=i;
    +
    +   // the last part
    +   buf[j]=0;  //null terminator
    +
    +   for(i = 0; i < j; i ++) //check for invalid character
    +   {
    +     if(isdigit(buf[i]) == 0)
    +     {
    +       return 0;
    +     }
    +   }
    +   p = str_atoi(buf, j);
    +   if( p < 0 || p > 255 || j == 0) // check for invalid number
    +   {
    +     return 0;
    +   }
    +   else
    +   {
    +     if(ipv4_bytes)
    +       ipv4_bytes[dot] = (unsigned char)p;
    +   }
    +
    +   //if terminated by space
    +   if( stoppos < slen -1)
    +   {
    +     for(j = stoppos ; j < slen; j++)
    +     {
    +       if(srcData[j] != ' ') return 0;
    +     }
    +   }
    +
    +   if(dot != 3) 
    +     return 0;
    +   else
    +     return 1;
    +  
    +}
    +
    +ex_expr::exp_return_type ExFunctionInetAton::eval(char * op_data[],
    +                                                        CollHeap *heap,
    +                                                        ComDiagsArea **diags)
    +{
    +   char * srcData = op_data[1];
    +   char * resultData = op_data[0];
    +
    +  Attributes *resultAttr   = getOperand(0);
    +  Attributes *srcAttr   = getOperand(1);
    +
    +  Lng32 slen = srcAttr->getLength(op_data[-MAX_OPERANDS+1]);
    +  Lng32 rlen = resultAttr->getLength();
    +
    +  unsigned int addr;
    +  int ret=string2ipv4(srcData, slen, &addr);
    +  if(ret)
    +  {
    +       *(unsigned int *)op_data[0]=addr;
    +       return ex_expr::EXPR_OK;
    +  } 
    +  else
    +  {
    +      ExRaiseSqlError(heap, diags, EXE_INVALID_CHARACTER);
    +      *(*diags) << DgString0("IP format") << DgString1("INET_ATON FUNCTION");

    +      return ex_expr::EXPR_ERROR;
    +  }
    +}
    +
    +
    +ex_expr::exp_return_type ExFunctionInetNtoa::eval(char * op_data[],
    +                                                        CollHeap *heap,
    +                                                        ComDiagsArea **diags)
    +{
    +   char buf[16]; //big enough
    +   unsigned long addr =  *(unsigned long*)op_data[1];
    +   char * resultData = op_data[0];
    +   Attributes *resultAttr = getOperand(0);
    +   const unsigned char *ipv4_bytes= (const unsigned char *) &addr;
    +
    +   if( ipv4_bytes[0] > 255 || 
    +       ipv4_bytes[1] > 255 ||
    +       ipv4_bytes[2] > 255 ||
    +       ipv4_bytes[3] > 255 ||
    --- End diff --
    
    yes... I will remove them


---
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.
---

Mime
View raw message