clintropolis commented on code in PR #14943:
URL: https://github.com/apache/druid/pull/14943#discussion_r1316646922
##########
processing/src/main/java/org/apache/druid/math/expr/BuiltInExprMacros.java:
##########
@@ -144,4 +145,47 @@ public Object getLiteralValue()
}
}
}
+
+ public static class StringDecodeBase64UTFExprMacro implements
ExprMacroTable.ExprMacro
+ {
+
+ public static final String NAME = "decode_base64_utf8";
+
+ @Override
+ public Expr apply(List<Expr> args)
+ {
+ return new StringDecodeBase64UTFExpression(args);
+ }
+
+ @Override
+ public String name()
+ {
+ return NAME;
+ }
+
+ final class StringDecodeBase64UTFExpression extends
ExprMacroTable.BaseScalarMacroFunctionExpr
+ {
+ public StringDecodeBase64UTFExpression(List<Expr> args)
+ {
+ super(NAME, args);
+ validationHelperCheckArgumentCount(args, 1);
+ }
+
+ @Override
+ public ExprEval eval(ObjectBinding bindings)
+ {
+ ExprEval<?> toDecode = args.get(0).eval(bindings);
+ if (toDecode.value() == null) {
+ return ExprEval.of(null);
+ }
+ return new StringExpr(new
String(StringUtils.decodeBase64String(toDecode.asString()),
StandardCharsets.UTF_8)).eval(bindings);
Review Comment:
You could also use
`StringUtils.fromUtf8(StringUtils.decodeBase64String(...))`
##########
sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/DecodeBase64UTFOperatorConversion.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.druid.sql.calcite.expression.builtin;
+
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.sql.SqlFunction;
+import org.apache.calcite.sql.SqlFunctionCategory;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.type.SqlTypeFamily;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.math.expr.BuiltInExprMacros;
+import org.apache.druid.segment.column.ColumnType;
+import org.apache.druid.segment.column.RowSignature;
+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 javax.annotation.Nullable;
+
+public class DecodeBase64UTFOperatorConversion implements SqlOperatorConversion
Review Comment:
I think you can just use `DirectOperatorConversion` which will save you from
having to implement `toDruidExpression`
##########
processing/src/main/java/org/apache/druid/math/expr/BuiltInExprMacros.java:
##########
@@ -144,4 +145,47 @@ public Object getLiteralValue()
}
}
}
+
+ public static class StringDecodeBase64UTFExprMacro implements
ExprMacroTable.ExprMacro
Review Comment:
It would be useful to implement `getOutputType`, `isLiteral`,
`isNullLiteral`, and `getLiteralValue` similar to
`ComplexDecodeBase64Expression`.
##########
processing/src/main/java/org/apache/druid/math/expr/ExprMacroTable.java:
##########
@@ -44,7 +44,8 @@
public class ExprMacroTable
{
private static final List<ExprMacro> BUILT_IN = ImmutableList.of(
- new BuiltInExprMacros.ComplexDecodeBase64ExprMacro()
+ new BuiltInExprMacros.ComplexDecodeBase64ExprMacro(),
+ new BuiltInExprMacros.StringDecodeBase64UTFExprMacro()
Review Comment:
it doesn't necessarily have to be in this PR, but it would be nice to add an
alias for `ComplexDecodeBase64ExprMacro ` (and also the SQL layer), perhaps
just by extending the class and overriding the usage of `NAME` so it has
consistent naming with this new function, e.g. `decode_base64_complex`
--
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]