gianm commented on code in PR #14956:
URL: https://github.com/apache/druid/pull/14956#discussion_r1326574686
##########
processing/src/main/java/org/apache/druid/query/expression/LookupExprMacro.java:
##########
@@ -104,6 +105,15 @@ public ExpressionType getOutputType(InputBindingInspector
inspector)
@Override
public String stringify()
{
+ if (replaceMissingValueWith != null) {
+ return StringUtils.format(
+ "%s(%s, %s, '%s')",
+ FN_NAME,
+ arg.stringify(),
+ lookupExpr.stringify(),
+ replaceMissingValueWith
Review Comment:
This doesn't handle escaping properly. `replaceMissingValueWith` might
contain `'` itself, or newlines, etc.
The simplest way to fix this is to keep the expr around and `stringify()` it
here, like we do with `lookupExpr` (which is also required to be a literal).
##########
sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/QueryLookupOperatorConversion.java:
##########
@@ -30,16 +30,27 @@
import org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider;
import org.apache.druid.query.lookup.RegisteredLookupExtractionFn;
import org.apache.druid.segment.column.RowSignature;
+import org.apache.druid.sql.calcite.expression.BasicOperandTypeChecker;
import org.apache.druid.sql.calcite.expression.DruidExpression;
import org.apache.druid.sql.calcite.expression.OperatorConversions;
import org.apache.druid.sql.calcite.expression.SqlOperatorConversion;
import org.apache.druid.sql.calcite.planner.PlannerContext;
+import java.util.List;
+
public class QueryLookupOperatorConversion implements SqlOperatorConversion
{
private static final SqlFunction SQL_FUNCTION = OperatorConversions
.operatorBuilder("LOOKUP")
- .operandTypes(SqlTypeFamily.CHARACTER, SqlTypeFamily.CHARACTER)
+ .operandTypeChecker(
+ BasicOperandTypeChecker.builder()
+ .operandTypes(
+ SqlTypeFamily.CHARACTER,
+ SqlTypeFamily.CHARACTER,
+ SqlTypeFamily.CHARACTER
+ )
+ .requiredOperandCount(2)
Review Comment:
Since the lookup expr only supports a literal "missing value replacement",
this should include `.literalOperands(2)` (meaning operand 2 must be a literal).
##########
docs/querying/sql-scalar.md:
##########
@@ -98,7 +98,7 @@ String functions accept strings, and return a type
appropriate to the function.
|`CHAR_LENGTH(expr)`|Alias for `LENGTH`.|
|`CHARACTER_LENGTH(expr)`|Alias for `LENGTH`.|
|`STRLEN(expr)`|Alias for `LENGTH`.|
-|`LOOKUP(expr, lookupName)`|Look up `expr` in a registered [query-time lookup
table](lookups.md). Note that lookups can also be queried directly using the
[`lookup` schema](sql.md#from).|
+|`LOOKUP(expr, lookupName, [replaceMissingValueWith])`|Look up `expr` in a
registered [query-time lookup table](lookups.md). Note that lookups can also be
queried directly using the [`lookup` schema](sql.md#from).|
Review Comment:
Update the text to say what `replaceMissingValueWith` does, and to point out
that it must be a constant.
--
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]