siddharthteotia commented on code in PR #8558: URL: https://github.com/apache/pinot/pull/8558#discussion_r855443180
########## pinot-query-planner/src/main/java/org/apache/pinot/query/planner/nodes/RexExpression.java: ########## @@ -0,0 +1,157 @@ +/** + * 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.pinot.query.planner.nodes; + +import java.math.BigDecimal; +import java.util.List; +import java.util.stream.Collectors; +import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.rex.RexCall; +import org.apache.calcite.rex.RexInputRef; +import org.apache.calcite.rex.RexLiteral; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.calcite.util.NlsString; +import org.apache.pinot.query.planner.nodes.serde.ProtoProperties; +import org.checkerframework.checker.nullness.qual.Nullable; + + +/** + * {@code RexExpression} is the serializable format of the {@link RexNode}. + */ +public abstract class RexExpression { + @ProtoProperties + protected SqlKind _sqlKind; + @ProtoProperties + protected RelDataType _dataType; + + public SqlKind getKind() { + return _sqlKind; + } + + public RelDataType getDataType() { + return _dataType; + } + + public static RexExpression toRexExpression(RexNode rexNode) { + if (rexNode instanceof RexInputRef) { + return new RexExpression.InputRef(((RexInputRef) rexNode).getIndex()); + } else if (rexNode instanceof RexLiteral) { + RexLiteral rexLiteral = ((RexLiteral) rexNode); + return new RexExpression.Literal(rexLiteral.getType(), rexLiteral.getTypeName(), rexLiteral.getValue()); + } else if (rexNode instanceof RexCall) { + RexCall rexCall = (RexCall) rexNode; + List<RexExpression> operands = rexCall.getOperands().stream().map(RexExpression::toRexExpression) + .collect(Collectors.toList()); + return new RexExpression.FunctionCall(rexCall.getKind(), rexCall.getType(), rexCall.getOperator().getName(), + operands); + } else { + throw new IllegalArgumentException("Unsupported RexNode type with SqlKind: " + rexNode.getKind()); Review Comment: Use entire `RexNode` in the message instead of `SqlKind` ? -- 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-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org