You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by sunjincheng121 <gi...@git.apache.org> on 2017/06/15 06:33:51 UTC
[GitHub] flink pull request #4128: [FLINK-6893][table]Add BIN supported in SQL
GitHub user sunjincheng121 opened a pull request:
https://github.com/apache/flink/pull/4128
[FLINK-6893][table]Add BIN supported in SQL
In this PR. have Add BIN supported in SQL,e.g.:
```
BIN(12) -> "1100"
BIN(10)-> "1010"
```
- [x] General
- The pull request references the related JIRA issue ("[FLINK-6893][table]Add BIN supported in SQL")
- The pull request addresses only one issue
- Each commit in the PR has a meaningful commit message (including the JIRA id)
- [ ] Documentation
- Documentation has been added for new functionality
- Old documentation affected by the pull request has been updated
- JavaDoc for public methods has been added
- [x] Tests & Build
- Functionality added by the pull request is covered by tests
- `mvn clean verify` has been executed successfully locally or a Travis build has passed
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/sunjincheng121/flink FLINK-6893-PR
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/flink/pull/4128.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 #4128
----
commit 410ab83a6c7e9e6c5346299ad8e694f918333536
Author: sunjincheng121 <su...@gmail.com>
Date: 2017-06-15T06:30:25Z
[FLINK-6893][table]Add BIN supported in SQL
----
---
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] flink pull request #4128: [FLINK-6893][table]Add BIN supported in SQL
Posted by wuchong <gi...@git.apache.org>.
Github user wuchong commented on a diff in the pull request:
https://github.com/apache/flink/pull/4128#discussion_r127868400
--- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/sql/ScalarSqlFunctions.scala ---
@@ -33,6 +33,14 @@ object ScalarSqlFunctions {
OperandTypes.NILADIC,
SqlFunctionCategory.NUMERIC)
+ val BIN = new SqlFunction(
+ "BIN",
+ SqlKind.OTHER_FUNCTION,
+ ReturnTypes.explicit(SqlTypeName.VARCHAR),
+ null,
+ OperandTypes.NUMERIC,
--- End diff --
I don't think BIN accepts all NUMERIC operands. I think it only accepts BIGINT, TINYINT, SMALLINT,INTEGER. And not support other decimal numeric.
---
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] flink issue #4128: [FLINK-6893][table]Add BIN supported in SQL
Posted by sunjincheng121 <gi...@git.apache.org>.
Github user sunjincheng121 commented on the issue:
https://github.com/apache/flink/pull/4128
@thedrow Thanks a lot ...
Best, Jincheng
---
[GitHub] flink pull request #4128: [FLINK-6893][table]Add BIN supported in SQL
Posted by haohui <gi...@git.apache.org>.
Github user haohui commented on a diff in the pull request:
https://github.com/apache/flink/pull/4128#discussion_r140702758
--- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/sql/ScalarSqlFunctions.scala ---
@@ -33,6 +33,14 @@ object ScalarSqlFunctions {
OperandTypes.NILADIC,
SqlFunctionCategory.NUMERIC)
+ val BIN = new SqlFunction(
+ "BIN",
+ SqlKind.OTHER_FUNCTION,
+ ReturnTypes.explicit(SqlTypeName.VARCHAR),
+ null,
+ OperandTypes.NUMERIC,
--- End diff --
You can construct a checker easily using `OperandTypes.or()` in Calcite.
---
[GitHub] flink issue #4128: [FLINK-6893][table]Add BIN supported in SQL
Posted by sunjincheng121 <gi...@git.apache.org>.
Github user sunjincheng121 commented on the issue:
https://github.com/apache/flink/pull/4128
I'll Rebase code and add doc after FLINK-6960 & FLINK-6925 merged.
---
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] flink issue #4128: [FLINK-6893][table]Add BIN supported in SQL
Posted by sunjincheng121 <gi...@git.apache.org>.
Github user sunjincheng121 commented on the issue:
https://github.com/apache/flink/pull/4128
I had rebase code and add the document.
---
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] flink pull request #4128: [FLINK-6893][table]Add BIN supported in SQL
Posted by haohui <gi...@git.apache.org>.
Github user haohui commented on a diff in the pull request:
https://github.com/apache/flink/pull/4128#discussion_r140702856
--- Diff: docs/dev/table/sql.md ---
@@ -1691,7 +1691,7 @@ INITCAP(string)
<tr>
<td>
- {% highlight text %}
--- End diff --
Unnecessary changes.
---
[GitHub] flink issue #4128: [FLINK-6893][table]Add BIN supported in SQL
Posted by sunjincheng121 <gi...@git.apache.org>.
Github user sunjincheng121 commented on the issue:
https://github.com/apache/flink/pull/4128
I have rebase the code. I appreciated if you can review this PR. @wuchong @shaoxuan-wang
Best, Jincheng
---
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] flink pull request #4128: [FLINK-6893][table]Add BIN supported in SQL
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/flink/pull/4128
---
[GitHub] flink pull request #4128: [FLINK-6893][table]Add BIN supported in SQL
Posted by haohui <gi...@git.apache.org>.
Github user haohui commented on a diff in the pull request:
https://github.com/apache/flink/pull/4128#discussion_r140702779
--- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/calls/FunctionGenerator.scala ---
@@ -414,6 +415,11 @@ object FunctionGenerator {
DOUBLE_TYPE_INFO,
BuiltInMethods.LOG_WITH_BASE)
+ addSqlFunction(
--- End diff --
Unnecessary changes?
---
[GitHub] flink pull request #4128: [FLINK-6893][table]Add BIN supported in SQL
Posted by wuchong <gi...@git.apache.org>.
Github user wuchong commented on a diff in the pull request:
https://github.com/apache/flink/pull/4128#discussion_r127866461
--- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/runtime/functions/ScalarFunctions.scala ---
@@ -82,4 +82,24 @@ object ScalarFunctions {
}
sb.toString
}
+
+ /**
+ * Returns a string representation of the binary value of N, Returns NULL if N is NULL.
+ */
+ def bin(n: Long): String = {
+ if (null == n) {
+ return null
+ }
+ val value = new Array[Byte](64)
+ var num = n
+ // Extract the bits of num into value[] from right to left
+ var len: Int = 0
+ do {
+ len += 1
+ value(value.length - len) = ('0' + (num & 1)).toByte
+ num >>>= 1
+ } while (num != 0)
--- End diff --
Use `Long.toBinaryString(long)` to parse it.
---
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] flink pull request #4128: [FLINK-6893][table]Add BIN supported in SQL
Posted by wuchong <gi...@git.apache.org>.
Github user wuchong commented on a diff in the pull request:
https://github.com/apache/flink/pull/4128#discussion_r127868565
--- Diff: flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/ScalarFunctionsTest.scala ---
@@ -352,6 +352,14 @@ class ScalarFunctionsTest extends ScalarTypesTestBase {
"Flink~~~~xx")
}
+ @Test
+ def testBin(): Unit = {
+ testSqlApi("BIN(12)", "1100")
+ testSqlApi("BIN(10)", "1010")
+ testSqlApi("BIN(0)", "0")
+ testSqlApi("BIN(f32)","1111111111111111111111111111111111111111111111111111111111111111")
+ }
+
--- End diff --
Would be better to add validation tests to `ScalarFunctionsValidationTest` to check the expected exception for unsupported operand types.
---
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] flink pull request #4128: [FLINK-6893][table]Add BIN supported in SQL
Posted by sunjincheng121 <gi...@git.apache.org>.
Github user sunjincheng121 commented on a diff in the pull request:
https://github.com/apache/flink/pull/4128#discussion_r140644236
--- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/sql/ScalarSqlFunctions.scala ---
@@ -33,6 +33,14 @@ object ScalarSqlFunctions {
OperandTypes.NILADIC,
SqlFunctionCategory.NUMERIC)
+ val BIN = new SqlFunction(
+ "BIN",
+ SqlKind.OTHER_FUNCTION,
+ ReturnTypes.explicit(SqlTypeName.VARCHAR),
+ null,
+ OperandTypes.NUMERIC,
--- End diff --
Yes, In current code we only support BYTE,SHORT,INTEGER,LONG. If we try to using a FLOAT input we will got the EXCEPTION.
If understand you correctly you want define a new operand types checker, just like `tableAPI(ScalarSqlFunction)`, But I in SQL I'd better using CALCITE's default `OperandTypeChecker`. What do you think?
---