From fa2eba4a96cc932364583c2d17afab7b79083f5d Mon Sep 17 00:00:00 2001 From: Tomas Fabian Date: Fri, 9 Apr 2021 16:54:51 +0200 Subject: [PATCH] [Kafka.DotNet.ksqlDB] - scalar collection functions: ArrayMax, ArrayMin --- Joker.Kafka/ChangeLog.md | 3 + .../Functions/KSqlFunctionsExtensions.cs | 128 +++++++++++++++++- .../Query/Visitors/KSqlFunctionVisitor.cs | 2 + 3 files changed, 128 insertions(+), 5 deletions(-) diff --git a/Joker.Kafka/ChangeLog.md b/Joker.Kafka/ChangeLog.md index 9aaebbc5..29b7110c 100644 --- a/Joker.Kafka/ChangeLog.md +++ b/Joker.Kafka/ChangeLog.md @@ -120,6 +120,9 @@ Fixes: - QbservableProvider - ```KSqldbProvider``` - ksqldb REST api provider for push queries (```KSqlDbQueryProvider```, ```KSqlDbQueryStreamProvider```) +# v0.8.0-preview (WIP) - not released yet +- scalar collection functions: ArrayMax, ArrayMin + # TODO: - missing scalar functions https://docs.ksqldb.io/en/latest/developer-guide/ksqldb-reference/scalar-functions/#date-and-time - CreateQueryStream options parameter diff --git a/Joker.Kafka/KSql/Query/Functions/KSqlFunctionsExtensions.cs b/Joker.Kafka/KSql/Query/Functions/KSqlFunctionsExtensions.cs index 24b8d281..a5eff108 100644 --- a/Joker.Kafka/KSql/Query/Functions/KSqlFunctionsExtensions.cs +++ b/Joker.Kafka/KSql/Query/Functions/KSqlFunctionsExtensions.cs @@ -1003,7 +1003,7 @@ public static string ArrayJoin(this KSqlFunctions kSqlFunctions, decimal[] array /// /// /// The array - /// Returns the maximum value from within a given array of primitive elements (not arrays of other arrays, or maps, or structs, or combinations thereof). + /// Number of elements in the array. If the array field is NULL, or contains only NULLs, then NULL is returned. public static int? ArrayLength(this KSqlFunctions kSqlFunctions, string[] array) { throw new InvalidOperationException(ServerSideOperationErrorMessage); @@ -1014,7 +1014,7 @@ public static string ArrayJoin(this KSqlFunctions kSqlFunctions, decimal[] array /// /// /// The array - /// Returns the maximum value from within a given array of primitive elements (not arrays of other arrays, or maps, or structs, or combinations thereof). + /// Number of elements in the array. If the array field is NULL, or contains only NULLs, then NULL is returned. public static int? ArrayLength(this KSqlFunctions kSqlFunctions, int[] array) { throw new InvalidOperationException(ServerSideOperationErrorMessage); @@ -1025,7 +1025,7 @@ public static string ArrayJoin(this KSqlFunctions kSqlFunctions, decimal[] array /// /// /// The array - /// Returns the maximum value from within a given array of primitive elements (not arrays of other arrays, or maps, or structs, or combinations thereof). + /// Number of elements in the array. If the array field is NULL, or contains only NULLs, then NULL is returned. public static int? ArrayLength(this KSqlFunctions kSqlFunctions, long[] array) { throw new InvalidOperationException(ServerSideOperationErrorMessage); @@ -1036,7 +1036,7 @@ public static string ArrayJoin(this KSqlFunctions kSqlFunctions, decimal[] array /// /// /// The array - /// Returns the maximum value from within a given array of primitive elements (not arrays of other arrays, or maps, or structs, or combinations thereof). + /// Number of elements in the array. If the array field is NULL, or contains only NULLs, then NULL is returned. public static int? ArrayLength(this KSqlFunctions kSqlFunctions, double[] array) { throw new InvalidOperationException(ServerSideOperationErrorMessage); @@ -1047,7 +1047,7 @@ public static string ArrayJoin(this KSqlFunctions kSqlFunctions, decimal[] array /// /// /// The array - /// Returns the maximum value from within a given array of primitive elements (not arrays of other arrays, or maps, or structs, or combinations thereof). + /// Number of elements in the array. If the array field is NULL, or contains only NULLs, then NULL is returned. public static int? ArrayLength(this KSqlFunctions kSqlFunctions, decimal[] array) { throw new InvalidOperationException(ServerSideOperationErrorMessage); @@ -1057,6 +1057,124 @@ public static string ArrayJoin(this KSqlFunctions kSqlFunctions, decimal[] array #region ARRAY_MAX + /// + /// Given an array, return the maximum value. Array entries are compared according to their natural sort order, which sorts the various data-types. + /// + /// + /// The array + /// Returns the maximum value from within a given array of primitive elements (not arrays of other arrays, or maps, or structs, or combinations thereof). + public static int? ArrayMax(this KSqlFunctions kSqlFunctions, string[] array) + { + throw new InvalidOperationException(ServerSideOperationErrorMessage); + } + + /// + /// Given an array, return the maximum value. Array entries are compared according to their natural sort order, which sorts the various data-types. + /// + /// + /// The array + /// Returns the maximum value from within a given array of primitive elements (not arrays of other arrays, or maps, or structs, or combinations thereof). + public static int? ArrayMax(this KSqlFunctions kSqlFunctions, int[] array) + { + throw new InvalidOperationException(ServerSideOperationErrorMessage); + } + + /// + /// Given an array, return the maximum value. Array entries are compared according to their natural sort order, which sorts the various data-types. + /// + /// + /// The array + /// Returns the maximum value from within a given array of primitive elements (not arrays of other arrays, or maps, or structs, or combinations thereof). + public static int? ArrayMax(this KSqlFunctions kSqlFunctions, long[] array) + { + throw new InvalidOperationException(ServerSideOperationErrorMessage); + } + + /// + /// Given an array, return the maximum value. Array entries are compared according to their natural sort order, which sorts the various data-types. + /// + /// + /// The array + /// Returns the maximum value from within a given array of primitive elements (not arrays of other arrays, or maps, or structs, or combinations thereof). + public static int? ArrayMax(this KSqlFunctions kSqlFunctions, double[] array) + { + throw new InvalidOperationException(ServerSideOperationErrorMessage); + } + + /// + /// Given an array, return the maximum value. Array entries are compared according to their natural sort order, which sorts the various data-types. + /// + /// + /// The array + /// Returns the maximum value from within a given array of primitive elements (not arrays of other arrays, or maps, or structs, or combinations thereof). + public static int? ArrayMax(this KSqlFunctions kSqlFunctions, decimal[] array) + { + throw new InvalidOperationException(ServerSideOperationErrorMessage); + } + + #endregion + + #region ArrayMin + + /// + /// Given an array, return the minimum value. Array entries are compared according to their natural sort order, which sorts the various data-types. + /// + /// + /// The array + /// Returns the minimum value from within a given array of primitive elements (not arrays of other arrays, or maps, or structs, or combinations thereof). + public static int? ArrayMin(this KSqlFunctions kSqlFunctions, string[] array) + { + throw new InvalidOperationException(ServerSideOperationErrorMessage); + } + + /// + /// Given an array, return the minimum value. Array entries are compared according to their natural sort order, which sorts the various data-types. + /// + /// + /// The array + /// Returns the minimum value from within a given array of primitive elements (not arrays of other arrays, or maps, or structs, or combinations thereof). + public static int? ArrayMin(this KSqlFunctions kSqlFunctions, int[] array) + { + throw new InvalidOperationException(ServerSideOperationErrorMessage); + } + + /// + /// Given an array, return the minimum value. Array entries are compared according to their natural sort order, which sorts the various data-types. + /// + /// + /// The array + /// Returns the minimum value from within a given array of primitive elements (not arrays of other arrays, or maps, or structs, or combinations thereof). + public static int? ArrayMin(this KSqlFunctions kSqlFunctions, long[] array) + { + throw new InvalidOperationException(ServerSideOperationErrorMessage); + } + + /// + /// Given an array, return the minimum value. Array entries are compared according to their natural sort order, which sorts the various data-types. + /// + /// + /// The array + /// Returns the minimum value from within a given array of primitive elements (not arrays of other arrays, or maps, or structs, or combinations thereof). + public static int? ArrayMin(this KSqlFunctions kSqlFunctions, double[] array) + { + throw new InvalidOperationException(ServerSideOperationErrorMessage); + } + + /// + /// Given an array, return the minimum value. Array entries are compared according to their natural sort order, which sorts the various data-types. + /// + /// + /// The array + /// Returns the minimum value from within a given array of primitive elements (not arrays of other arrays, or maps, or structs, or combinations thereof). + public static int? ArrayMin(this KSqlFunctions kSqlFunctions, decimal[] array) + { + throw new InvalidOperationException(ServerSideOperationErrorMessage); + } + + #endregion + + #region ARRAY_REMOVE + #endregion diff --git a/Joker.Kafka/KSql/Query/Visitors/KSqlFunctionVisitor.cs b/Joker.Kafka/KSql/Query/Visitors/KSqlFunctionVisitor.cs index 74915b8e..ea3d4c4c 100644 --- a/Joker.Kafka/KSql/Query/Visitors/KSqlFunctionVisitor.cs +++ b/Joker.Kafka/KSql/Query/Visitors/KSqlFunctionVisitor.cs @@ -72,6 +72,8 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp case nameof(KSqlFunctionsExtensions.ArrayIntersect): case nameof(KSqlFunctionsExtensions.ArrayJoin): case nameof(KSqlFunctionsExtensions.ArrayLength): + case nameof(KSqlFunctionsExtensions.ArrayMax): + case nameof(KSqlFunctionsExtensions.ArrayMin): Append($"{methodInfo.Name.ToKSqlFunctionName()}"); PrintFunctionArguments(methodCallExpression.Arguments.Skip(1)); break;