You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "jiaan.geng (Jira)" <ji...@apache.org> on 2019/09/23 07:00:00 UTC

[jira] [Comment Edited] (SPARK-28121) String Functions: decode/encode can not accept 'escape' and 'hex' as charset

    [ https://issues.apache.org/jira/browse/SPARK-28121?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16935586#comment-16935586 ] 

jiaan.geng edited comment on SPARK-28121 at 9/23/19 6:59 AM:
-------------------------------------------------------------

[~smilegator]

I write a test TransformTest as follows:
{code:java}
public class TransformTest {  
    public static void main(String[] args) {  
        String s = "1234567890";  
        byte[] bytes = s.getBytes();   
        System.out.println("16进制:"  + binary(bytes, 16)); 
        System.exit(0);  
    }  
      
    public static String binary(byte[] bytes, int radix){  
        return new BigInteger(1, bytes).toString(radix);// 这里的1代表正数  
    }  
} 

// the result is 31323334353637383930{code}
The java code transform string to hex. the result is the same as the uncode function of Postgresql.

 


was (Author: beliefer):
I write a test TransformTest as follows:
{code:java}
public class TransformTest {  
    public static void main(String[] args) {  
        String s = "1234567890";  
        byte[] bytes = s.getBytes();   
        System.out.println("16进制:"  + binary(bytes, 16)); 
        System.exit(0);  
    }  
      
    public static String binary(byte[] bytes, int radix){  
        return new BigInteger(1, bytes).toString(radix);// 这里的1代表正数  
    }  
} 

// the result is 31323334353637383930{code}
The java code transform string to hex. the result is the same as the uncode function of Postgresql.

 

> String Functions: decode/encode can not accept 'escape' and 'hex' as charset
> ----------------------------------------------------------------------------
>
>                 Key: SPARK-28121
>                 URL: https://issues.apache.org/jira/browse/SPARK-28121
>             Project: Spark
>          Issue Type: Sub-task
>          Components: SQL
>    Affects Versions: 3.0.0
>            Reporter: Yuming Wang
>            Priority: Major
>
> {noformat}
> postgres=# select decode('1234567890','escape');
> decode
> ------------------------
> \x31323334353637383930
> (1 row)
> {noformat}
> {noformat}
> spark-sql> select decode('1234567890','escape');
> 19/06/20 01:57:33 ERROR SparkSQLDriver: Failed in [select decode('1234567890','escape')]
> java.io.UnsupportedEncodingException: escape
> 	at java.lang.StringCoding.decode(StringCoding.java:190)
> 	at java.lang.String.<init>(String.java:426)
> 	at java.lang.String.<init>(String.java:491)
> ...
> spark-sql> select decode('ff','hex');
> 19/08/16 21:44:55 ERROR SparkSQLDriver: Failed in [select decode('ff','hex')]
> java.io.UnsupportedEncodingException: hex
> 	at java.lang.StringCoding.decode(StringCoding.java:190)
> 	at java.lang.String.<init>(String.java:426)
> 	at java.lang.String.<init>(String.java:491)
> {noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org