Browse Source

feat: Add the ESQL testing module

pull/1552/head
colin 1 week ago
parent
commit
ddda353df5
  1. 1
      aspnet-core/LINGYUN.MicroService.All.slnx
  2. 3
      aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/FodyWeavers.xml
  3. 30
      aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/FodyWeavers.xsd
  4. 27
      aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/LINGYUN/Abp/Elasticsearch/EsqlQuery/EsqlExpressionQueryService.cs
  5. 22
      aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/README.md
  6. 20
      aspnet-core/tests/LINGYUN.Abp.Elasticsearch.EsqlQuery.Tests/LINGYUN.Abp.Elasticsearch.EsqlQuery.Tests.csproj
  7. 7
      aspnet-core/tests/LINGYUN.Abp.Elasticsearch.EsqlQuery.Tests/LINGYUN/Abp/Elasticsearch/EsqlQuery/AbpElasticsearchEsqlQueryTestBase.cs
  8. 21
      aspnet-core/tests/LINGYUN.Abp.Elasticsearch.EsqlQuery.Tests/LINGYUN/Abp/Elasticsearch/EsqlQuery/AbpElasticsearchEsqlQueryTestModule.cs
  9. 5
      aspnet-core/tests/LINGYUN.Abp.Elasticsearch.EsqlQuery.Tests/LINGYUN/Abp/Elasticsearch/EsqlQuery/EsqlExpressionQueryService_Tests.cs

1
aspnet-core/LINGYUN.MicroService.All.slnx

@ -530,6 +530,7 @@
<Project Path="tests/LINGYUN.Abp.BlobStoring.Aliyun.Tests/LINGYUN.Abp.BlobStoring.Aliyun.Tests.csproj" />
<Project Path="tests/LINGYUN.Abp.BlobStoring.Nexus.Tests/LINGYUN.Abp.BlobStoring.Nexus.Tests.csproj" />
<Project Path="tests/LINGYUN.Abp.DataProtection.Tests/LINGYUN.Abp.DataProtection.Tests.csproj" />
<Project Path="tests/LINGYUN.Abp.Elasticsearch.EsqlQuery.Tests/LINGYUN.Abp.Elasticsearch.EsqlQuery.Tests.csproj" Id="52d961a7-c89d-4fca-ad35-8c7f3588aeb9" />
<Project Path="tests/LINGYUN.Abp.Elasticsearch.Tests/LINGYUN.Abp.Elasticsearch.Tests.csproj" Id="056a13a4-8fbb-4437-adc8-fe76d0869880" />
<Project Path="tests/LINGYUN.Abp.Emailing.Platform.Tests/LINGYUN.Abp.Emailing.Platform.Tests.csproj" />
<Project Path="tests/LINGYUN.Abp.EntityFrameworkCore.Tests/LINGYUN.Abp.EntityFrameworkCore.Tests.csproj" />

3
aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/FodyWeavers.xml

@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ConfigureAwait ContinueOnCapturedContext="false" />
</Weavers>

30
aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/FodyWeavers.xsd

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" />
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>

27
aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/LINGYUN/Abp/Elasticsearch/EsqlQuery/EsqlExpressionQueryService.cs

@ -11,6 +11,15 @@ using Volo.Abp.DependencyInjection;
namespace LINGYUN.Abp.Elasticsearch.EsqlQuery;
/// <summary>
/// NOTE: The tests for methods like Contains in the collection have failed. Please do not use this interface for collection filtering.
/// TODO: According to the official documentation, is it feasible? Is the support for nested types not available?
/// See: https://www.elastic.co/docs/reference/elasticsearch/clients/dotnet/linq-to-esql#linq-esql-filtering
/// var brands = new[] { "TechCorp", "StyleMax", "HomeBase" };
/// client.Esql.Query<Product>(q => q.Where(p => brands.Contains(p.Brand)));
/// → WHERE brand IN ("TechCorp", "StyleMax", "HomeBase")
/// </summary>
[Dependency(ReplaceServices = true)]
public class EsqlExpressionQueryService : ExpressionQueryService, ITransientDependency
{
@ -29,6 +38,7 @@ public class EsqlExpressionQueryService : ExpressionQueryService, ITransientDepe
var client = ClientFactory.Create();
return await client.Esql.CreateQuery<TDocument>()
.From(indexName)
.Where(expression)
.AsEsqlQueryable()
.CountAsync(cancellationToken);
@ -42,18 +52,31 @@ public class EsqlExpressionQueryService : ExpressionQueryService, ITransientDepe
int skipCount = 0,
Fields? sourceExcludes = null,
Fields? sourceIncludes = null,
object[]? beginMarker = null,
CancellationToken cancellationToken = default) where TDocument : class
{
var client = ClientFactory.Create();
var query = client.Esql.CreateQuery<TDocument>().Where(expression);
var query = client.Esql.CreateQuery<TDocument>()
.From(indexName)
.Where(expression);
if (!sorting.IsNullOrWhiteSpace())
{
query = query.OrderBy(sorting);
}
if (sourceExcludes != null)
{
query = query.Drop(sourceExcludes.Select(f => f.Name!).ToArray());
}
if (sourceIncludes != null)
{
query = query.Keep(sourceIncludes.Select(f => f.Name!).ToArray());
}
// TODO: 需要构建范围过滤条件,加入到query中以实现分页查询
// See: https://www.elastic.co/docs/reference/elasticsearch/clients/dotnet/linq-to-esql#linq-esql-sorting
return await query
.PageBy(skipCount, maxResultCount)
.Take(maxResultCount)
.AsEsqlQueryable()
.ToListAsync(cancellationToken);
}

22
aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/README.md

@ -0,0 +1,22 @@
# LINGYUN.Abp.Elasticsearch.EsqlQuery
[IExpressionQueryService](../LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/IExpressionQueryService.cs) 的ES|QL查询集成.
**注意**:
* 使用 ES|QL 查询方案不能进行深度分页,数据条目超出10000时依旧存在ES分页限制.
如需支持深度分页,请使用默认 [ExpressionQueryService](../LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/ExpressionQueryService.cs) `search_after` 方案
* 不支持使用 由于ES|QL不支持 `Skip`, 暂不支持分页查询
* 对于嵌套类型的集合方法测试未通过,请勿使用集合的过滤条件
## 模块引用
```csharp
[DependsOn(typeof(AbpElasticsearchEsqlQueryModule))]
public class YouProjectModule : AbpModule
{
// other
}
```

20
aspnet-core/tests/LINGYUN.Abp.Elasticsearch.EsqlQuery.Tests/LINGYUN.Abp.Elasticsearch.EsqlQuery.Tests.csproj

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<RootNamespace />
<IsPackable>false</IsPackable>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq.AutoMock" />
<PackageReference Include="Serilog.Sinks.Elasticsearch" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\framework\elasticsearch\LINGYUN.Abp.Elasticsearch.EsqlQuery\LINGYUN.Abp.Elasticsearch.EsqlQuery.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.Elasticsearch.Tests\LINGYUN.Abp.Elasticsearch.Tests.csproj" />
</ItemGroup>
</Project>

7
aspnet-core/tests/LINGYUN.Abp.Elasticsearch.EsqlQuery.Tests/LINGYUN/Abp/Elasticsearch/EsqlQuery/AbpElasticsearchEsqlQueryTestBase.cs

@ -0,0 +1,7 @@
using LINGYUN.Abp.Tests;
namespace LINGYUN.Abp.Elasticsearch.EsqlQuery;
public abstract class AbpElasticsearchEsqlQueryTestBase : AbpTestsBase<AbpElasticsearchEsqlQueryTestModule>
{
}

21
aspnet-core/tests/LINGYUN.Abp.Elasticsearch.EsqlQuery.Tests/LINGYUN/Abp/Elasticsearch/EsqlQuery/AbpElasticsearchEsqlQueryTestModule.cs

@ -0,0 +1,21 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity;
namespace LINGYUN.Abp.Elasticsearch.EsqlQuery;
[DependsOn(
typeof(AbpElasticsearchEsqlQueryModule),
typeof(AbpElasticsearchTestModule))]
public class AbpElasticsearchEsqlQueryTestModule : AbpModule
{
private const string UserSecretsId = "D4327320-718E-4A7F-A987-85838EDD8675";
public override void PreConfigureServices(ServiceConfigurationContext context)
{
context.Services.ReplaceConfiguration(ConfigurationHelper.BuildConfiguration(builderAction: builder =>
{
builder.AddUserSecrets(UserSecretsId);
}));
}
}

5
aspnet-core/tests/LINGYUN.Abp.Elasticsearch.EsqlQuery.Tests/LINGYUN/Abp/Elasticsearch/EsqlQuery/EsqlExpressionQueryService_Tests.cs

@ -0,0 +1,5 @@
namespace LINGYUN.Abp.Elasticsearch.EsqlQuery;
public class EsqlExpressionQueryService_Tests : ExpressionQueryService_Tests<AbpElasticsearchEsqlQueryTestModule>
{
}
Loading…
Cancel
Save