dianfu commented on a change in pull request #9858: [FLINK-14208][python]
Optimize Python UDFs with parameters of constant values
URL: https://github.com/apache/flink/pull/9858#discussion_r333373867
##########
File path:
flink-python/src/main/java/org/apache/flink/api/common/python/PythonBridgeUtils.java
##########
@@ -70,6 +74,99 @@
return unpickledData;
}
+ public static byte[] literalToPythonObject(RexLiteral o, SqlTypeName
typeName) {
+ byte type;
+ Object value;
+ Pickler pickler = new Pickler();
+ if (o.getValue3() == null) {
+ type = 0;
+ value = null;
+ } else {
+ switch (typeName) {
+ case TINYINT:
+ type = 0;
+ value = ((BigDecimal)
o.getValue3()).byteValueExact();
+ break;
+ case SMALLINT:
+ type = 0;
+ value = ((BigDecimal)
o.getValue3()).shortValueExact();
+ break;
+ case INTEGER:
+ type = 0;
+ value = ((BigDecimal)
o.getValue3()).intValueExact();
+ break;
+ case BIGINT:
+ type = 0;
+ value = ((BigDecimal)
o.getValue3()).longValueExact();
+ break;
+ case FLOAT:
+ type = 0;
+ value = ((BigDecimal)
o.getValue3()).floatValue();
+ break;
+ case DOUBLE:
+ type = 0;
+ value = ((BigDecimal)
o.getValue3()).doubleValue();
+ break;
+ case DECIMAL:
+ type = 0;
+ value = o.getValue3();
+ break;
+ case CHAR:
+ case VARCHAR:
+ type = 0;
+ value = o.getValue3().toString();
+ break;
+ case BOOLEAN:
+ type = 1;
+ value = o.getValue3().toString();
Review comment:
We can pickle boolean type directly, there is no need to convert it to
string.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services