From d44a9dc56bc6e560ef1311dfaa3b3246a852741e Mon Sep 17 00:00:00 2001 From: vplauzon Date: Thu, 4 Jan 2024 16:55:26 -0500 Subject: [PATCH 1/2] Add a failing test related to a Python plugin issue --- .../CommandParsing/CreateFunctionTest.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/code/DeltaKustoUnitTest/CommandParsing/CreateFunctionTest.cs b/code/DeltaKustoUnitTest/CommandParsing/CreateFunctionTest.cs index 9bc55f70..f030efa1 100644 --- a/code/DeltaKustoUnitTest/CommandParsing/CreateFunctionTest.cs +++ b/code/DeltaKustoUnitTest/CommandParsing/CreateFunctionTest.cs @@ -362,5 +362,39 @@ public void TableAndPrimitiveTypeParameters() Assert.Equal("a", param3.ParameterName.Name); Assert.Equal("int", param3.PrimitiveType); } + + [Fact] + public void PythonPlugin() + { + var name = "PythonFct"; + var script = $@".create-or-alter function {name}() {{ +range x from 1 to 360 step 1 +| evaluate python(typeof(*, fx:double), +``` +from scipy.stats import gamma,uniform,bernoulli +size = kargs['samples'] +result = df +def GenMixtureUsage(x, size): + rand_bern = bernoulli.rvs(x['ProbLowUsage'], size = size) + rand_gamma = gamma.rvs(a=1, scale=x['AvgUsage'], size=size) + rand_unif = uniform.rvs(size=size) + result = rand_bern*rand_unif + (1-rand_bern)*rand_gamma + return result +result['SimulatedUsage'] = df.apply(lambda x: GenMixtureUsage(x, size = size), axis=1) +``` +, bag_pack('samples', 10) +) +}}"; + var command = ParseOneCommand(script); + + Assert.IsType(command); + + var createFunctionCommand = (CreateFunctionCommand)command; + var body = createFunctionCommand.Body; + var bernIndex = body.IndexOf("rand_bern"); + + Assert.NotEqual(-1, bernIndex); + Assert.NotEqual('\n', body[bernIndex-1]); + } } } \ No newline at end of file From e2a9484d42c7d010aeea5717b75a882564c06a21 Mon Sep 17 00:00:00 2001 From: vplauzon Date: Thu, 4 Jan 2024 17:58:21 -0500 Subject: [PATCH 2/2] Fix failing test --- code/DeltaKustoLib/CommandModel/CommandBase.cs | 5 ++--- code/delta-kusto/delta-kusto.csproj | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/code/DeltaKustoLib/CommandModel/CommandBase.cs b/code/DeltaKustoLib/CommandModel/CommandBase.cs index 75aaf600..133db033 100644 --- a/code/DeltaKustoLib/CommandModel/CommandBase.cs +++ b/code/DeltaKustoLib/CommandModel/CommandBase.cs @@ -297,14 +297,13 @@ private static IEnumerable SplitCommandScripts(string script) { var lines = script .Split('\n') - .Select(l => l.Trim()) // Remove comment lines - .Where(l => !l.StartsWith("//")); + .Where(l => !l.Trim().StartsWith("//")); var currentCommandLines = new List(); foreach (var line in lines) { - if (line == string.Empty) + if (line.Trim() == string.Empty) { if (currentCommandLines.Any()) { diff --git a/code/delta-kusto/delta-kusto.csproj b/code/delta-kusto/delta-kusto.csproj index 681b0daa..76487f40 100644 --- a/code/delta-kusto/delta-kusto.csproj +++ b/code/delta-kusto/delta-kusto.csproj @@ -5,7 +5,7 @@ net7.0 delta_kusto enable - 0.15.1 + 0.15.2 partial