Skip to content

Commit

Permalink
Fix EARLIEST_BY/LATEST_BY signature and include function name in …
Browse files Browse the repository at this point in the history
…signature. (#14352)

* Fix EarliestLatestBySqlAggregator signature; Include function name for all signatures.

* Single quote function signatures, space between args and remove \n.

* fixup UT assertion
  • Loading branch information
abhishekrb19 authored Jun 6, 2023
1 parent 5da601c commit 2d258a9
Show file tree
Hide file tree
Showing 35 changed files with 63 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ private CompressedBigDecimalSqlAggFunction(String name)
OperandTypes.and(OperandTypes.ANY, OperandTypes.family(SqlTypeFamily.ANY)),
OperandTypes.and(
OperandTypes.sequence(
"'" + name + "'(column, size)",
"'" + name + "(column, size)'",
OperandTypes.ANY,
OperandTypes.POSITIVE_INTEGER_LITERAL
),
OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.EXACT_NUMERIC)
),
OperandTypes.and(
OperandTypes.sequence(
"'" + name + "'(column, size, scale)",
"'" + name + "(column, size, scale)'",
OperandTypes.ANY,
OperandTypes.POSITIVE_INTEGER_LITERAL,
OperandTypes.POSITIVE_INTEGER_LITERAL
Expand All @@ -195,7 +195,7 @@ private CompressedBigDecimalSqlAggFunction(String name)
),
OperandTypes.and(
OperandTypes.sequence(
"'" + name + "'(column, size, scale, strictNumberParsing)",
"'" + name + "(column, size, scale, strictNumberParsing)'",
OperandTypes.ANY,
OperandTypes.POSITIVE_INTEGER_LITERAL,
OperandTypes.POSITIVE_INTEGER_LITERAL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public Aggregation toDruidAggregation(

private static class TDigestGenerateSketchSqlAggFunction extends SqlAggFunction
{
private static final String SIGNATURE_WITH_COMPRESSION = "'" + NAME + "(column, compression)'\n";
private static final String SIGNATURE_WITH_COMPRESSION = "'" + NAME + "(column, compression)'";

TDigestGenerateSketchSqlAggFunction()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ public Aggregation toDruidAggregation(

private static class TDigestSketchQuantileSqlAggFunction extends SqlAggFunction
{
private static final String SIGNATURE1 = "'" + NAME + "(column, quantile)'\n";
private static final String SIGNATURE2 = "'" + NAME + "(column, quantile, compression)'\n";
private static final String SIGNATURE1 = "'" + NAME + "(column, quantile)'";
private static final String SIGNATURE2 = "'" + NAME + "(column, quantile, compression)'";

TDigestSketchQuantileSqlAggFunction()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected Aggregation toAggregation(

private static class HllSketchApproxCountDistinctSqlAggFunction extends SqlAggFunction
{
private static final String SIGNATURE = "'" + NAME + "(column, lgK, tgtHllType)'\n";
private static final String SIGNATURE = "'" + NAME + "(column, lgK, tgtHllType)'";

HllSketchApproxCountDistinctSqlAggFunction()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected Aggregation toAggregation(

private static class HllSketchSqlAggFunction extends SqlAggFunction
{
private static final String SIGNATURE = "'" + NAME + "(column, lgK, tgtHllType)'\n";
private static final String SIGNATURE = "'" + NAME + "(column, lgK, tgtHllType)'";

HllSketchSqlAggFunction()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ static long getMaxStreamLengthFromQueryContext(QueryContext queryContext)

private static class DoublesSketchApproxQuantileSqlAggFunction extends SqlAggFunction
{
private static final String SIGNATURE1 = "'" + NAME + "(column, probability)'\n";
private static final String SIGNATURE2 = "'" + NAME + "(column, probability, k)'\n";
private static final String SIGNATURE1 = "'" + NAME + "(column, probability)'";
private static final String SIGNATURE2 = "'" + NAME + "(column, probability, k)'";

DoublesSketchApproxQuantileSqlAggFunction()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public Aggregation toDruidAggregation(

private static class DoublesSketchSqlAggFunction extends SqlAggFunction
{
private static final String SIGNATURE2 = "'" + NAME + "(column, k)'\n";
private static final String SIGNATURE2 = "'" + NAME + "(column, k)'";

DoublesSketchSqlAggFunction()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected Aggregation toAggregation(

private static class ThetaSketchSqlAggFunction extends SqlAggFunction
{
private static final String SIGNATURE = "'" + NAME + "(column, size)'\n";
private static final String SIGNATURE = "'" + NAME + "(column, size)'";

ThetaSketchSqlAggFunction()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected Aggregation toAggregation(

private static class ThetaSketchObjectSqlAggFunction extends SqlAggFunction
{
private static final String SIGNATURE = "'" + NAME + "(column, size)'\n";
private static final String SIGNATURE = "'" + NAME + "(column, size)'";

ThetaSketchObjectSqlAggFunction()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public Aggregation toDruidAggregation(

private static class BloomFilterSqlAggFunction extends SqlAggFunction
{
private static final String SIGNATURE1 = "'" + NAME + "(column, maxNumEntries)'\n";
private static final String SIGNATURE1 = "'" + NAME + "(column, maxNumEntries)'";

BloomFilterSqlAggFunction()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ private static class FixedBucketsHistogramQuantileSqlAggFunction extends SqlAggF
private static final String SIGNATURE1 =
"'"
+ NAME
+ "(column, probability, numBuckets, lowerLimit, upperLimit)'\n";
+ "(column, probability, numBuckets, lowerLimit, upperLimit)'";
private static final String SIGNATURE2 =
"'"
+ NAME
+ "(column, probability, numBuckets, lowerLimit, upperLimit, outlierHandlingMode)'\n";
+ "(column, probability, numBuckets, lowerLimit, upperLimit, outlierHandlingMode)'";

FixedBucketsHistogramQuantileSqlAggFunction()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ public Aggregation toDruidAggregation(

private static class QuantileSqlAggFunction extends SqlAggFunction
{
private static final String SIGNATURE1 = "'" + NAME + "(column, probability)'\n";
private static final String SIGNATURE2 = "'" + NAME + "(column, probability, resolution)'\n";
private static final String SIGNATURE1 = "'" + NAME + "(column, probability)'";
private static final String SIGNATURE2 = "'" + NAME + "(column, probability, resolution)'";

QuantileSqlAggFunction()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private static class ArrayConcatAggFunction extends SqlAggFunction
OperandTypes.or(
OperandTypes.ARRAY,
OperandTypes.sequence(
StringUtils.format("'%s'(expr, maxSizeBytes)", NAME),
StringUtils.format("'%s(expr, maxSizeBytes)'", NAME),
OperandTypes.ARRAY,
OperandTypes.POSITIVE_INTEGER_LITERAL
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private static class ArrayAggFunction extends SqlAggFunction
OperandTypes.or(
OperandTypes.ANY,
OperandTypes.and(
OperandTypes.sequence(StringUtils.format("%s(expr, maxSizeBytes)", NAME), OperandTypes.ANY, OperandTypes.POSITIVE_INTEGER_LITERAL),
OperandTypes.sequence(StringUtils.format("'%s(expr, maxSizeBytes)'", NAME), OperandTypes.ANY, OperandTypes.POSITIVE_INTEGER_LITERAL),
OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.NUMERIC)
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ private static class EarliestLatestSqlAggFunction extends SqlAggFunction
OperandTypes.NUMERIC,
OperandTypes.BOOLEAN,
OperandTypes.sequence(
"'" + aggregatorType.name() + "(expr, maxBytesPerString)'\n",
"'" + aggregatorType.name() + "(expr, maxBytesPerString)'",
OperandTypes.ANY,
OperandTypes.and(OperandTypes.NUMERIC, OperandTypes.LITERAL)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ private static class EarliestByLatestBySqlAggFunction extends SqlAggFunction
InferTypes.RETURN_TYPE,
OperandTypes.or(
OperandTypes.sequence(
"'" + aggregatorType.name() + "(expr, timeColumn)'\n",
"'" + StringUtils.format("%s_BY", aggregatorType.name()) + "(expr, timeColumn)'",
OperandTypes.ANY,
OperandTypes.family(SqlTypeFamily.TIMESTAMP)
),
OperandTypes.sequence(
"'" + aggregatorType.name() + "(expr, timeColumn, maxBytesPerString)'\n",
"'" + StringUtils.format("%s_BY", aggregatorType.name()) + "(expr, timeColumn, maxBytesPerString)'",
OperandTypes.ANY,
OperandTypes.family(SqlTypeFamily.TIMESTAMP),
OperandTypes.and(OperandTypes.NUMERIC, OperandTypes.LITERAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,15 @@ private static class StringAggFunction extends SqlAggFunction
OperandTypes.or(
OperandTypes.and(
OperandTypes.sequence(
StringUtils.format("'%s'(expr, separator)", NAME),
StringUtils.format("'%s(expr, separator)'", NAME),
OperandTypes.ANY,
OperandTypes.STRING
),
OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.STRING)
),
OperandTypes.and(
OperandTypes.sequence(
StringUtils.format("'%s'(expr, separator, maxSizeBytes)", NAME),
StringUtils.format("'%s(expr, separator, maxSizeBytes)'", NAME),
OperandTypes.ANY,
OperandTypes.STRING,
OperandTypes.POSITIVE_INTEGER_LITERAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ArrayAppendOperatorConversion extends DirectOperatorConversion
.operatorBuilder("ARRAY_APPEND")
.operandTypeChecker(
OperandTypes.sequence(
"(array,expr)",
"'ARRAY_APPEND(array, expr)'",
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.ARRAY),
OperandTypes.family(SqlTypeFamily.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ArrayConcatOperatorConversion extends DirectOperatorConversion
.operatorBuilder("ARRAY_CONCAT")
.operandTypeChecker(
OperandTypes.sequence(
"(array,array)",
"'ARRAY_CONCAT(array, array)'",
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.ARRAY),
OperandTypes.family(SqlTypeFamily.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ArrayContainsOperatorConversion extends BaseExpressionDimFilterOper
.operatorBuilder("ARRAY_CONTAINS")
.operandTypeChecker(
OperandTypes.sequence(
"(array,array)",
"'ARRAY_CONTAINS(array, array)'",
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.ARRAY),
OperandTypes.family(SqlTypeFamily.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ArrayOffsetOfOperatorConversion extends DirectOperatorConversion
.operatorBuilder("ARRAY_OFFSET_OF")
.operandTypeChecker(
OperandTypes.sequence(
"(array,expr)",
"'ARRAY_OFFSET_OF(array, expr)'",
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.ARRAY),
OperandTypes.family(SqlTypeFamily.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ArrayOffsetOperatorConversion extends DirectOperatorConversion
.operatorBuilder("ARRAY_OFFSET")
.operandTypeChecker(
OperandTypes.sequence(
"(array,expr)",
"'ARRAY_OFFSET(array, expr)'",
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.ARRAY),
OperandTypes.family(SqlTypeFamily.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ArrayOrdinalOfOperatorConversion extends DirectOperatorConversion
.operatorBuilder("ARRAY_ORDINAL_OF")
.operandTypeChecker(
OperandTypes.sequence(
"(array,expr)",
"'ARRAY_ORDINAL_OF(array, expr)'",
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.ARRAY),
OperandTypes.family(SqlTypeFamily.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ArrayOrdinalOperatorConversion extends DirectOperatorConversion
.operatorBuilder("ARRAY_ORDINAL")
.operandTypeChecker(
OperandTypes.sequence(
"(array,expr)",
"'ARRAY_ORDINAL(array, expr)'",
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.ARRAY),
OperandTypes.family(SqlTypeFamily.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ArrayOverlapOperatorConversion extends BaseExpressionDimFilterOpera
.operatorBuilder("ARRAY_OVERLAP")
.operandTypeChecker(
OperandTypes.sequence(
"(array,array)",
"'ARRAY_OVERLAP(array, array)'",
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.ARRAY),
OperandTypes.family(SqlTypeFamily.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ArrayPrependOperatorConversion extends DirectOperatorConversion
.operatorBuilder("ARRAY_PREPEND")
.operandTypeChecker(
OperandTypes.sequence(
"(expr,array)",
"'ARRAY_PREPEND(expr, array)'",
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.STRING),
OperandTypes.family(SqlTypeFamily.NUMERIC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public class ArraySliceOperatorConversion extends DirectOperatorConversion
.operandTypeChecker(
OperandTypes.or(
OperandTypes.sequence(
"(expr,start)",
"'ARRAY_SLICE(expr, start)'",
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.ARRAY),
OperandTypes.family(SqlTypeFamily.STRING)
),
OperandTypes.family(SqlTypeFamily.NUMERIC)
),
OperandTypes.sequence(
"(expr,start,end)",
"'ARRAY_SLICE(expr, start, end)'",
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.ARRAY),
OperandTypes.family(SqlTypeFamily.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ArrayToStringOperatorConversion extends DirectOperatorConversion
.operatorBuilder("ARRAY_TO_STRING")
.operandTypeChecker(
OperandTypes.sequence(
"(array,expr)",
"'ARRAY_TO_STRING(array, expr)'",
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.ARRAY),
OperandTypes.family(SqlTypeFamily.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class ComplexDecodeBase64OperatorConversion implements SqlOperatorConvers
.operatorBuilder(StringUtils.toUpperCase(BuiltInExprMacros.ComplexDecodeBase64ExprMacro.NAME))
.operandTypeChecker(
OperandTypes.sequence(
"(typeName,base64)",
"'" + StringUtils.toUpperCase(BuiltInExprMacros.ComplexDecodeBase64ExprMacro.NAME) + "(typeName, base64)'",
OperandTypes.and(OperandTypes.family(SqlTypeFamily.STRING), OperandTypes.LITERAL),
OperandTypes.ANY
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ public class IPv4AddressMatchOperatorConversion extends DirectOperatorConversion

private static final SqlFunction SQL_FUNCTION = OperatorConversions
.operatorBuilder(StringUtils.toUpperCase(IPv4AddressMatchExprMacro.FN_NAME))
.operandTypeChecker(OperandTypes.sequence("(expr,string)", ADDRESS_OPERAND, SUBNET_OPERAND))
.operandTypeChecker(
OperandTypes.sequence(
"'" + StringUtils.toUpperCase(IPv4AddressMatchExprMacro.FN_NAME) + "(expr, string)'",
ADDRESS_OPERAND,
SUBNET_OPERAND
)
)
.returnTypeInference(ReturnTypes.BOOLEAN_NULLABLE)
.functionCategory(SqlFunctionCategory.USER_DEFINED_FUNCTION)
.build();
Expand Down
Loading

0 comments on commit 2d258a9

Please sign in to comment.