philo-he commented on code in PR #12925:
URL: https://github.com/apache/gluten/pull/12925#discussion_r3898938581
##########
gluten-substrait/src/main/java/org/apache/gluten/substrait/expression/SingularOrListNode.java:
##########
@@ -25,18 +26,39 @@
public class SingularOrListNode implements ExpressionNode, Serializable {
private final ExpressionNode value;
private final List<ExpressionNode> listNodes = new ArrayList<>();
+ // rawValues and dataType allow delaying literal node construction until
toProtobuf()
+ private final List<Object> rawValues;
+ private final DataType dataType;
SingularOrListNode(ExpressionNode value, List<ExpressionNode> listNodes) {
this.value = value;
this.listNodes.addAll(listNodes);
+ this.rawValues = null;
+ this.dataType = null;
+ }
+
+ SingularOrListNode(ExpressionNode value, List<Object> rawValues, DataType
dataType) {
+ this.value = value;
+ this.rawValues = new ArrayList<>(rawValues);
+ this.dataType = dataType;
}
@Override
public Expression toProtobuf() {
Expression.SingularOrList.Builder builder =
Expression.SingularOrList.newBuilder();
builder.setValue(value.toProtobuf());
- for (ExpressionNode expressionNode : listNodes) {
- builder.addOptions(expressionNode.toProtobuf());
+ if (!listNodes.isEmpty()) {
+ for (ExpressionNode expressionNode : listNodes) {
+ builder.addOptions(expressionNode.toProtobuf());
+ }
+ } else if (rawValues != null) {
+ for (Object obj : rawValues) {
+ // construct a temporary LiteralNode and convert to protobuf to avoid
keeping
+ // many LiteralNode objects in memory at once. Use per-value
nullability.
+ LiteralNode literalNode =
+ (LiteralNode) ExpressionBuilder.makeLiteral(obj, dataType, obj ==
null);
+ builder.addOptions(literalNode.toProtobuf());
+ }
Review Comment:
Would it be better to create a separate class named like
`DeferredSingularOrListNode`? Seems to be cleaner.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]