You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pig.apache.org by "Sabir Ayappalli (JIRA)" <ji...@apache.org> on 2012/08/16 07:53:38 UTC

[jira] [Created] (PIG-2880) Pig current releases lack a UDF charAt.This UDF returns the char value at the specified index.

Sabir Ayappalli created PIG-2880:
------------------------------------

             Summary: Pig current releases lack a UDF charAt.This UDF returns the char value at the specified index.
                 Key: PIG-2880
                 URL: https://issues.apache.org/jira/browse/PIG-2880
             Project: Pig
          Issue Type: New Feature
          Components: piggybank
    Affects Versions: 0.10.0
            Reporter: Sabir Ayappalli


Pig current releases lack a UDF charAt.This UDF returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (PIG-2880) Pig current releases lack a UDF charAt.This UDF returns the char value at the specified index.

Posted by "Dmitriy V. Ryaboy (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIG-2880?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13467054#comment-13467054 ] 

Dmitriy V. Ryaboy commented on PIG-2880:
----------------------------------------

Isn't this just a special case of substring?

If you do feel strongly that this is a useful udf, I would like to suggest a couple of improvements:

* use PrimitiveEvalFunc<String, String> instead of EvalFunc. It'll take care of null or empty inputs, etc, which the UDF you proposed will blow up on.

* why add an empty string to a char? String.valueOf is quite a bit more efficient.
                
> Pig current releases lack a UDF charAt.This UDF returns the char value at the specified index.
> ----------------------------------------------------------------------------------------------
>
>                 Key: PIG-2880
>                 URL: https://issues.apache.org/jira/browse/PIG-2880
>             Project: Pig
>          Issue Type: New Feature
>          Components: piggybank
>    Affects Versions: 0.10.0
>            Reporter: Sabir Ayappalli
>
> Pig current releases lack a UDF charAt.This UDF returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (PIG-2880) Pig current releases lack a UDF charAt.This UDF returns the char value at the specified index.

Posted by "Dmitriy V. Ryaboy (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIG-2880?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13468690#comment-13468690 ] 

Dmitriy V. Ryaboy commented on PIG-2880:
----------------------------------------

Ah, forgot about the second argument. In that case, just take care of nulls, wrong # or type of arguments, etc, in your code.

Also note you can provide the @OutputSchema annotation to tell Pig what to expect to come out of this UDF.
                
> Pig current releases lack a UDF charAt.This UDF returns the char value at the specified index.
> ----------------------------------------------------------------------------------------------
>
>                 Key: PIG-2880
>                 URL: https://issues.apache.org/jira/browse/PIG-2880
>             Project: Pig
>          Issue Type: New Feature
>          Components: piggybank
>    Affects Versions: 0.10.0
>            Reporter: Sabir Ayappalli
>
> Pig current releases lack a UDF charAt.This UDF returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (PIG-2880) Pig current releases lack a UDF charAt.This UDF returns the char value at the specified index.

Posted by "Sunitha Muralidharan (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIG-2880?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13468560#comment-13468560 ] 

Sunitha Muralidharan commented on PIG-2880:
-------------------------------------------

Hi..
Thanks for your response. This UDF will output a character at the specified index.
For this UDF, we need two inputs. first one will be the string and the second one will be an index position. So in such situation, can we use PrimitiveEvalFunc<String,String>?
                
> Pig current releases lack a UDF charAt.This UDF returns the char value at the specified index.
> ----------------------------------------------------------------------------------------------
>
>                 Key: PIG-2880
>                 URL: https://issues.apache.org/jira/browse/PIG-2880
>             Project: Pig
>          Issue Type: New Feature
>          Components: piggybank
>    Affects Versions: 0.10.0
>            Reporter: Sabir Ayappalli
>
> Pig current releases lack a UDF charAt.This UDF returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (PIG-2880) Pig current releases lack a UDF charAt.This UDF returns the char value at the specified index.

Posted by "Sunitha Muralidharan (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIG-2880?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13456943#comment-13456943 ] 

Sunitha Muralidharan commented on PIG-2880:
-------------------------------------------

Can we define a new UDF as follows

package pigudf;

import java.io.IOException;

import org.apache.pig.EvalFunc;
import org.apache.pig.data.Tuple;

public class CharAt extends EvalFunc<String> {

	@Override
	public String exec(Tuple input) throws IOException {
		String str=(String) input.get(0);//string input
		int index=(Integer) input.get(1);//index 
		
		return str.charAt(index)+"";
	}

}


                
> Pig current releases lack a UDF charAt.This UDF returns the char value at the specified index.
> ----------------------------------------------------------------------------------------------
>
>                 Key: PIG-2880
>                 URL: https://issues.apache.org/jira/browse/PIG-2880
>             Project: Pig
>          Issue Type: New Feature
>          Components: piggybank
>    Affects Versions: 0.10.0
>            Reporter: Sabir Ayappalli
>
> Pig current releases lack a UDF charAt.This UDF returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira