Skip to content

Commit

Permalink
[Kafka.DotNet.ksqlDB] - numeric functions Abs, Ceil, Floor, Random, Sign
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasfabian committed Feb 6, 2021
1 parent 1234aeb commit b63e3e6
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 1 deletion.
124 changes: 124 additions & 0 deletions Joker.Kafka/KSql/Query/Functions/KSqlFunctionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,128 @@ public static class KSqlFunctionsExtensions
{
private static string ServerSideOperationErrorMessage = "Operator is not intended for client side operations";

#region Numeric

#region Abs

public static int Abs(this KSqlFunctions kSqlFunctions, int input)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

public static long Abs(this KSqlFunctions kSqlFunctions, long input)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

public static float Abs(this KSqlFunctions kSqlFunctions, float input)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

public static double Abs(this KSqlFunctions kSqlFunctions, double input)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

public static decimal Abs(this KSqlFunctions kSqlFunctions, decimal input)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

#endregion

#region Ceil

public static float Ceil(this KSqlFunctions kSqlFunctions, float input)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

public static double Ceil(this KSqlFunctions kSqlFunctions, double input)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

public static decimal Ceil(this KSqlFunctions kSqlFunctions, decimal input)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

#endregion

#region Floor

public static float Floor(this KSqlFunctions kSqlFunctions, float input)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

public static double Floor(this KSqlFunctions kSqlFunctions, double input)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

public static decimal Floor(this KSqlFunctions kSqlFunctions, decimal input)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

#endregion

public static double Random(this KSqlFunctions kSqlFunctions)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

#region Sign

public static int Sign(this KSqlFunctions kSqlFunctions, short input)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

public static int Sign(this KSqlFunctions kSqlFunctions, int input)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

public static int Sign(this KSqlFunctions kSqlFunctions, long input)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

public static int Sign(this KSqlFunctions kSqlFunctions, float input)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

public static int Sign(this KSqlFunctions kSqlFunctions, double input)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

public static int Sign(this KSqlFunctions kSqlFunctions, decimal input)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

#endregion

#region Sqrt

//int Sqrt(Func<TSource, int> selector);
//long Sqrt(Func<TSource, long> selector);
//decimal Sqrt(Func<TSource, decimal> selector);
//decimal Sqrt(Func<TSource, float> selector);
//decimal Sqrt(Func<TSource, double> selector);

#endregion

#endregion

#region String functions

public static bool Like(this KSqlFunctions kSqlFunctions, string condition, string patternString)
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
Expand All @@ -30,5 +152,7 @@ public static string Substring(this KSqlFunctions kSqlFunctions, string input, i
{
throw new InvalidOperationException(ServerSideOperationErrorMessage);
}

#endregion
}
}
9 changes: 8 additions & 1 deletion Joker.Kafka/KSql/Query/Visitors/KSqlFunctionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
Visit(methodCallExpression.Arguments[2]);
break;
case nameof(KSqlFunctionsExtensions.Trim):
Append("TRIM(");
case nameof(KSqlFunctionsExtensions.Abs):
case nameof(KSqlFunctionsExtensions.Ceil):
case nameof(KSqlFunctionsExtensions.Floor):
case nameof(KSqlFunctionsExtensions.Sign):
Append($"{methodInfo.Name.ToUpper()}(");
Visit(methodCallExpression.Arguments[1]);
Append(")");
break;
case nameof(KSqlFunctionsExtensions.Random):
Append($"{methodInfo.Name.ToUpper()}()");
break;
case nameof(KSqlFunctionsExtensions.LPad):
case nameof(KSqlFunctionsExtensions.RPad):
Expand Down

0 comments on commit b63e3e6

Please sign in to comment.