zabetak commented on code in PR #5196: URL: https://github.com/apache/hive/pull/5196#discussion_r2048601863
########## ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveFilterSortPredicates.java: ########## @@ -220,6 +234,37 @@ public Double visitCall(RexCall call) { return cost + functionCost(call); } + + private Double getSearchCost(RexCall call) { + HiveCalciteUtil.SearchTransformer<Double> transformer = new HiveCalciteUtil.SearchTransformer<>(); + transformer.transform(rexBuilder, call, + new RexFunctionCost(this.rexBuilder) { + @Override + public Double visitLiteral(RexLiteral literal) { + return HiveRelMdSize.INSTANCE.typeValueSize(literal.getType(), literal.getValueAs(Comparable.class)); + } + + @Override + public Double visitInputRef(RexInputRef inputRef) { + return HiveRelMdSize.INSTANCE.averageTypeValueSize(inputRef.getType()); + } + }); + + List<Double> operandCosts = new ArrayList<>(); + + if (!transformer.inNodes.isEmpty()) { + Double inOperandCosts = transformer.inNodes.stream().filter(Objects::nonNull).reduce(1D, Double::sum); + Double inFunctionCost = 2d * (transformer.inNodes.size() - 1); + operandCosts.add(inOperandCosts + inFunctionCost); + } + operandCosts.addAll(transformer.nodes); + + Double searchOperandCost = operandCosts.stream().filter(Objects::nonNull).reduce(1D, Double::sum); + // functionCost is essentially the cost of conjunctions or disjunctions + Double functionCost = operandCosts.size() == 1 ? 0D : 1d * operandCosts.size(); + + return searchOperandCost + functionCost; + } Review Comment: Obsolete comment, please ignore. -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org