-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding new function decode_base64_utf8 and expr macro #14943
Changes from all commits
77e964b
fa4d4b7
dffab78
304d973
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it doesn't necessarily have to be in this PR, but it would be nice to add an alias for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can be done registering an AliasedOperatorConversion similar to how SUBSTR or TRUNC is done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that would fix the SQL layer, but this is native expression macros, which do not currently have a generic aliasing thing here. @pranavbhole what are your plans for this aliasing? (I just want to make sure this actually gets done whether or not in this PR, and not lost) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will add aliasing in the followup PR. |
||
); | ||
private static final ExprMacroTable NIL = new ExprMacroTable(Collections.emptyList()); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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.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.sql.calcite.expression.DirectOperatorConversion; | ||
import org.apache.druid.sql.calcite.expression.OperatorConversions; | ||
|
||
public class DecodeBase64UTFOperatorConversion extends DirectOperatorConversion | ||
{ | ||
|
||
private static final SqlFunction SQL_FUNCTION = OperatorConversions | ||
.operatorBuilder(StringUtils.toUpperCase(BuiltInExprMacros.StringDecodeBase64UTFExprMacro.NAME)) | ||
.operandTypes(SqlTypeFamily.CHARACTER) | ||
.returnTypeNullable(SqlTypeName.VARCHAR) | ||
.functionCategory(SqlFunctionCategory.STRING) | ||
.build(); | ||
|
||
public DecodeBase64UTFOperatorConversion() | ||
{ | ||
super(SQL_FUNCTION, SQL_FUNCTION.getName()); | ||
} | ||
|
||
@Override | ||
public SqlOperator calciteOperator() | ||
{ | ||
return SQL_FUNCTION; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be useful to implement
getOutputType
,isLiteral
,isNullLiteral
, andgetLiteralValue
similar toComplexDecodeBase64Expression
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General Q, can this be implemented as an extension of
UnivariateFunction
? But then this is an expression and not exactly a functionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BaseScalarUnivariateMacroFunctionExpr
is the macro version of right thing to extend here since this is a single arugment function, +1 for re-using it since it would simplify things a bit hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed