Skip to content

Commit

Permalink
Merge pull request #156 from microsoft/vpl/python-test
Browse files Browse the repository at this point in the history
Vpl/python test
  • Loading branch information
vplauzon authored Jan 4, 2024
2 parents 4dbe83e + e2a9484 commit 270ec78
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
5 changes: 2 additions & 3 deletions code/DeltaKustoLib/CommandModel/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,13 @@ private static IEnumerable<string> 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<string>();

foreach (var line in lines)
{
if (line == string.Empty)
if (line.Trim() == string.Empty)
{
if (currentCommandLines.Any())
{
Expand Down
34 changes: 34 additions & 0 deletions code/DeltaKustoUnitTest/CommandParsing/CreateFunctionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CreateFunctionCommand>(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]);
}
}
}
2 changes: 1 addition & 1 deletion code/delta-kusto/delta-kusto.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>delta_kusto</RootNamespace>
<Nullable>enable</Nullable>
<Version>0.15.1</Version>
<Version>0.15.2</Version>
<!-- Avoid having each library being trimmed (instead of only opt-in ones) -->
<TrimMode>partial</TrimMode>
<!-- Important to avoid the trimming warning hell ; since we automate-test everything, we do not need static analysis -->
Expand Down

0 comments on commit 270ec78

Please sign in to comment.