Skip to content

Commit

Permalink
fix ut and agg
Browse files Browse the repository at this point in the history
  • Loading branch information
barnuri committed Dec 14, 2024
1 parent 86a757f commit ff3ddef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion LinqToKql.Test/CSharp.OpenSource.LinqToKql.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CSharp.OpenSource.LinqToKql\CSharp.OpenSource.LinqToKql.csproj" />
<ProjectReference Include="..\LinqToKql\CSharp.OpenSource.LinqToKql.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 12 additions & 4 deletions LinqToKql/Translator/Builders/LinqToKQLTranslatorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,25 @@ protected string GetArgMethod(Expression arg)
if (arg is MethodCallExpression methodCall)
{
var methodName = methodCall.Method.Name;
if (methodName == "Count")
return methodName switch
{
return "count()";
}
throw new InvalidOperationException($"{GetType().Name} - fail to translate");
"Count" => "count()",
"Sum" => $"sum({SelectMembers(methodCall.Arguments[1])})",
"Average" => $"avg({SelectMembers(methodCall.Arguments[1])})",
"Min" => $"min({SelectMembers(methodCall.Arguments[1])})",
"Max" => $"max({SelectMembers(methodCall.Arguments[1])})",
_ => throw new InvalidOperationException($"{GetType().Name} - Method {methodName} is not supported."),
};
}
else if (arg is MemberExpression mb2)
{
var propName = mb2.Member.Name;
return propName;
}
else if (arg is ConstantExpression constant)
{
return constant.Value.GetKQLValue();
}
else
{
throw new InvalidOperationException($"{GetType().Name} - Unsupported expression type for aggregation.");
Expand Down

0 comments on commit ff3ddef

Please sign in to comment.