epugh commented on PR #3119: URL: https://github.com/apache/solr/pull/3119#issuecomment-5357193001
Okay, I had to lean into AI to help me figure out what was going on... I've never really worked with calcite... Root cause found and fixed for the DISTINCT null issue. The bug was two-layered: 1. SolrConverterRule silently drops predicates. The 3-argument constructor accepts a Predicate<RelNode> parameter but never passes it to the parent ConverterRule — it was always relNode -> true effectively. This meant SolrProjectRule::isSupported defined in the previous session was defined but never executed. 2. Calcite 1.42 constant-folds grouped fields. For SELECT DISTINCT str_s, field_i ... WHERE str_s = 'a', Calcite 1.42 rewrites the plan so that str_s is replaced by the literal 'a' in the output project (since the WHERE clause guarantees it). When SolrProjectRule blindly converted this LogicalProject with a bare literal, RexToSolrTranslator returned null for the literal (can't translate to a Solr field name), creating a null key in fieldMappings. Downstream, SolrEnumerator.getter(null) → tuple.get(null) → null. Fix in SolrRules.java: - Added @Override public boolean matches(RelOptRuleCall call) to SolrProjectRule so the isSupported() predicate is actually checked by the planner - Changed the predicate from isFieldRefExpr() (too strict — also rejects CAST(DIVIDE(...)) from avg expansion) to isLiteralExpr() (only rejects projects with bare RexLiteral or CAST(RexLiteral) expressions) When matches() returns false, Calcite falls back to EnumerableCalc for the project while keeping SolrAggregate in Solr convention — correctly computing the constant-folded result at the enumerable layer. -- 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]
