You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by "MOONSakura0614 (via GitHub)" <gi...@apache.org> on 2024/09/06 08:46:58 UTC

[PR] [INLONG-11028][SDK] Transform SQL support UrlEncode & UrlDecode functions [inlong]

MOONSakura0614 opened a new pull request, #11031:
URL: https://github.com/apache/inlong/pull/11031

   …ions
   
   <!-- Prepare a Pull Request
   Change the title of pull request refer to the following example:
     [INLONG-XYZ][Component] Title of the pull request 
   -->
   
   <!-- Specify the issue this pull request going to fix.
   The following *XYZ* should be replaced by the actual [GitHub Issue](https://github.com/apache/inlong/issues) number)-->
   
   Fixes #11028
   
   ### Motivation
   Add 2 function class: UrlEncode & UrlDecode functions and their distinct unit tests.
   <!--Explain here the context, and why you're making that change. What is the problem you're trying to solve.-->
   
   ### Modifications
   
   <!--Describe the modifications you've done.-->
   
   ### Verifying this change
   
   *(Please pick either of the following options)*
   
   - [ ] This change is a trivial rework/code cleanup without any test coverage.
   
   - [x] This change is already covered by existing tests, such as:
     *(please describe tests)*
   
   - [ ] This change added tests and can be verified as follows:
   
     *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (yes / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
     - If a feature is not applicable for documentation, explain why?
     - If a feature is not documented yet in this PR, please create a follow-up issue for adding the documentation
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [INLONG-11028][SDK] Transform SQL support UrlEncode & UrlDecode functions [inlong]

Posted by "MOONSakura0614 (via GitHub)" <gi...@apache.org>.
MOONSakura0614 commented on code in PR #11031:
URL: https://github.com/apache/inlong/pull/11031#discussion_r1770535953


##########
inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlDecodeFunction.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.sdk.transform.process.function;
+
+import org.apache.inlong.sdk.transform.decode.SourceData;
+import org.apache.inlong.sdk.transform.process.Context;
+import org.apache.inlong.sdk.transform.process.operator.OperatorTools;
+import org.apache.inlong.sdk.transform.process.parser.ValueParser;
+
+import net.sf.jsqlparser.expression.Function;
+
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+
+/**
+ * UrlDecodeFunction
+ * description: Decodes a given string in ‘application/x-www-form-urlencoded’ format using the UTF-8 encoding scheme.
+ * If the input is NULL, or there is an issue with the decoding process(such as encountering an illegal escape pattern),
+ * or the encoding scheme is not supported, the function returns NULL.
+ */
+@TransformFunction(names = {"url_decode"})
+public class UrlDecodeFunction implements ValueParser {
+
+    private final ValueParser stringParser;
+
+    public UrlDecodeFunction(Function expr) {
+        stringParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0));
+    }
+
+    @Override
+    public Object parse(SourceData sourceData, int rowIndex, Context context) {
+        Object stringObj = stringParser.parse(sourceData, rowIndex, context);
+        if (stringObj == null) {
+            return null;
+        }
+        String string = OperatorTools.parseString(stringObj);
+        if (string == null) {
+            return null;
+        }
+
+        try {
+            return URLDecoder.decode(string, StandardCharsets.UTF_8.toString());

Review Comment:
   Thank you for your comment. I have specified the charset as `StandardCharsets.UTF_8.toString()` which effectively passes the UTF-8 charset. 
   
   If your concern is about the use of `.toString()`, I can change it to `StandardCharsets.UTF_8.name()` for clarity. Let me know your preference.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [INLONG-11028][SDK] Transform SQL support UrlEncode & UrlDecode functions [inlong]

Posted by "MOONSakura0614 (via GitHub)" <gi...@apache.org>.
MOONSakura0614 commented on PR #11031:
URL: https://github.com/apache/inlong/pull/11031#issuecomment-2406946967

   fixed. Thank you for pointing the bug.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [INLONG-11028][SDK] Transform SQL support UrlEncode & UrlDecode functions [inlong]

Posted by "luchunliang (via GitHub)" <gi...@apache.org>.
luchunliang commented on code in PR #11031:
URL: https://github.com/apache/inlong/pull/11031#discussion_r1753179080


##########
inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlDecodeFunction.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.sdk.transform.process.function;
+
+import org.apache.inlong.sdk.transform.decode.SourceData;
+import org.apache.inlong.sdk.transform.process.Context;
+import org.apache.inlong.sdk.transform.process.operator.OperatorTools;
+import org.apache.inlong.sdk.transform.process.parser.ValueParser;
+
+import net.sf.jsqlparser.expression.Function;
+
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+
+/**
+ * UrlDecodeFunction
+ * description: Decodes a given string in ‘application/x-www-form-urlencoded’ format using the UTF-8 encoding scheme.
+ * If the input is NULL, or there is an issue with the decoding process(such as encountering an illegal escape pattern),
+ * or the encoding scheme is not supported, the function returns NULL.
+ */
+@TransformFunction(names = {"url_decode"})
+public class UrlDecodeFunction implements ValueParser {
+
+    private final ValueParser stringParser;
+
+    public UrlDecodeFunction(Function expr) {
+        stringParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0));
+    }
+
+    @Override
+    public Object parse(SourceData sourceData, int rowIndex, Context context) {
+        Object stringObj = stringParser.parse(sourceData, rowIndex, context);
+        if (stringObj == null) {
+            return null;
+        }
+        String string = OperatorTools.parseString(stringObj);
+        if (string == null) {
+            return null;
+        }
+
+        try {
+            return URLDecoder.decode(string, StandardCharsets.UTF_8.toString());

Review Comment:
   Miss the parameter of charset.
   The default charset is UTF8.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [INLONG-11028][SDK] Transform SQL support UrlEncode & UrlDecode functions [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on PR #11031:
URL: https://github.com/apache/inlong/pull/11031#issuecomment-2406645686

    UT failed, PTAL 
    TestUrlEncodeFunction.testUrlEncodeFunction:55 expected:<result=[]> but was:<result=[null]>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [INLONG-11028][SDK] Transform SQL support UrlEncode & UrlDecode functions [inlong]

Posted by "MOONSakura0614 (via GitHub)" <gi...@apache.org>.
MOONSakura0614 commented on PR #11031:
URL: https://github.com/apache/inlong/pull/11031#issuecomment-2340099073

   @luchunliang @vernedeng @aloyszhang Sorry for demanding another review. I saw spotless process failed and recognized a useless import in a file so I redo the 'mvn spotless:apply' and re-commit.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [INLONG-11028][SDK] Transform SQL support UrlEncode & UrlDecode functions [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #11031:
URL: https://github.com/apache/inlong/pull/11031#discussion_r1750185615


##########
inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.sdk.transform.process.function;
+
+import org.apache.inlong.sdk.transform.decode.SourceData;
+import org.apache.inlong.sdk.transform.process.Context;
+import org.apache.inlong.sdk.transform.process.operator.OperatorTools;
+import org.apache.inlong.sdk.transform.process.parser.ValueParser;
+
+import net.sf.jsqlparser.expression.Function;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+
+/**
+ * UrlEncodeFunction
+ * description: Translates a string into ‘application/x-www-form-urlencoded’ format using the UTF-8 encoding scheme.
+ * If the input is NULL, or there is an issue with the encoding process,
+ * or the encoding scheme is not supported, will return NULL.
+ */
+@TransformFunction(names = {"url_encode"})
+public class UrlEncodeFunction implements ValueParser {
+
+    private final ValueParser stringParser;
+
+    public UrlEncodeFunction(Function expr) {
+        stringParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0));
+    }
+
+    @Override
+    public Object parse(SourceData sourceData, int rowIndex, Context context) {
+        Object stringObj = stringParser.parse(sourceData, rowIndex, context);
+        if (stringObj == null) {
+            return null;
+        }
+
+        String string = OperatorTools.parseString(stringObj);
+        if (string == null) {
+            return null;
+        }
+
+        try {
+            return URLEncoder.encode(string, StandardCharsets.UTF_8.toString());
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    public static void main(String[] args) throws UnsupportedEncodingException {
+        String string = "https://www.google.com/search?q=java url encode";
+        String s = "bat apache";
+        System.out.println(URLEncoder.encode(string, StandardCharsets.UTF_8.toString()));
+        System.out.println(URLEncoder.encode(s, StandardCharsets.UTF_8.toString()));
+    }

Review Comment:
   ```suggestion
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [INLONG-11028][SDK] Transform SQL support UrlEncode & UrlDecode functions [inlong]

Posted by "luchunliang (via GitHub)" <gi...@apache.org>.
luchunliang merged PR #11031:
URL: https://github.com/apache/inlong/pull/11031


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org