From 85846c2058f08efa5e781ef5722c0a005c6a2988 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Thu, 21 Oct 2021 12:54:01 +0100 Subject: [PATCH] Support params on SQL query & translate APIs (#6027) --- src/Nest/XPack/Sql/ISqlRequest.cs | 7 +++++++ .../XPack/Sql/QuerySql/QuerySqlRequest.cs | 20 +++++++++++++------ .../Sql/TranslateSql/TranslateSqlRequest.cs | 18 +++++++++++++---- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/Nest/XPack/Sql/ISqlRequest.cs b/src/Nest/XPack/Sql/ISqlRequest.cs index 2b9da50573e..d4797006de5 100644 --- a/src/Nest/XPack/Sql/ISqlRequest.cs +++ b/src/Nest/XPack/Sql/ISqlRequest.cs @@ -2,6 +2,7 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information +using System.Collections.Generic; using System.Runtime.Serialization; namespace Nest @@ -19,6 +20,12 @@ public interface ISqlRequest [DataMember(Name ="filter")] QueryContainer Filter { get; set; } + /// + /// Optional values for parameters in the query. + /// + [DataMember(Name = "params")] + IList Params { get; set; } + /// The SQL query you want Elasticsearch to execute [DataMember(Name ="query")] string Query { get; set; } diff --git a/src/Nest/XPack/Sql/QuerySql/QuerySqlRequest.cs b/src/Nest/XPack/Sql/QuerySql/QuerySqlRequest.cs index 5674ea2c805..bac04b77410 100644 --- a/src/Nest/XPack/Sql/QuerySql/QuerySqlRequest.cs +++ b/src/Nest/XPack/Sql/QuerySql/QuerySqlRequest.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information using System; +using System.Collections.Generic; using System.Runtime.Serialization; namespace Nest @@ -51,6 +52,9 @@ public partial class QuerySqlRequest /// public QueryContainer Filter { get; set; } + /// + public IList Params { get; set; } + /// public string Query { get; set; } @@ -70,34 +74,38 @@ public partial class QuerySqlDescriptor string IQuerySqlRequest.Cursor { get; set; } int? ISqlRequest.FetchSize { get; set; } QueryContainer ISqlRequest.Filter { get; set; } + IList ISqlRequest.Params { get; set; } string ISqlRequest.Query { get; set; } IRuntimeFields ISqlRequest.RuntimeFields { get; set; } string ISqlRequest.TimeZone { get; set; } Time IQuerySqlRequest.WaitForCompletionTimeout { get; set; } + /// + public QuerySqlDescriptor Params(IEnumerable parameters) => Assign(parameters, (a, v) => a.Params = v?.ToListOrNullIfEmpty()); + + /// + public QuerySqlDescriptor Params(IList parameters) => Assign(parameters, (a, v) => a.Params = v); + + /// + public QuerySqlDescriptor Params(params object[] parameters) => Assign(parameters, (a, v) => a.Params = v); + /// - /// > public QuerySqlDescriptor Query(string query) => Assign(query, (a, v) => a.Query = v); /// - /// > public QuerySqlDescriptor TimeZone(string timeZone) => Assign(timeZone, (a, v) => a.TimeZone = v); /// - /// > public QuerySqlDescriptor FetchSize(int? fetchSize) => Assign(fetchSize, (a, v) => a.FetchSize = v); /// - /// > public QuerySqlDescriptor Filter(Func, QueryContainer> querySelector) where T : class => Assign(querySelector, (a, v) => a.Filter = v?.Invoke(new QueryContainerDescriptor())); /// - /// > public QuerySqlDescriptor Cursor(string cursor) => Assign(cursor, (a, v) => a.Cursor = v); /// - /// > public QuerySqlDescriptor Columnar(bool? columnar = true) => Assign(columnar, (a, v) => a.Columnar = v); /// diff --git a/src/Nest/XPack/Sql/TranslateSql/TranslateSqlRequest.cs b/src/Nest/XPack/Sql/TranslateSql/TranslateSqlRequest.cs index a44d0951eaf..911780f796c 100644 --- a/src/Nest/XPack/Sql/TranslateSql/TranslateSqlRequest.cs +++ b/src/Nest/XPack/Sql/TranslateSql/TranslateSqlRequest.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information using System; +using System.Collections.Generic; using Elasticsearch.Net.Specification.SqlApi; namespace Nest @@ -22,6 +23,9 @@ protected sealed override void RequestDefaults(TranslateSqlRequestParameters par /// public QueryContainer Filter { get; set; } + /// + public IList Params { get; set; } + /// public string Query { get; set; } @@ -39,24 +43,30 @@ protected sealed override void RequestDefaults(TranslateSqlRequestParameters par int? ISqlRequest.FetchSize { get; set; } QueryContainer ISqlRequest.Filter { get; set; } + IList ISqlRequest.Params { get; set; } string ISqlRequest.Query { get; set; } string ISqlRequest.TimeZone { get; set; } IRuntimeFields ISqlRequest.RuntimeFields { get; set; } + /// + public TranslateSqlDescriptor Params(IEnumerable parameters) => Assign(parameters, (a, v) => a.Params = v?.ToListOrNullIfEmpty()); + + /// + public TranslateSqlDescriptor Params(IList parameters) => Assign(parameters, (a, v) => a.Params = v); + + /// + public TranslateSqlDescriptor Params(params object[] parameters) => Assign(parameters, (a, v) => a.Params = v); + /// - /// > public TranslateSqlDescriptor Query(string query) => Assign(query, (a, v) => a.Query = v); /// - /// > public TranslateSqlDescriptor TimeZone(string timeZone) => Assign(timeZone, (a, v) => a.TimeZone = v); /// - /// > public TranslateSqlDescriptor FetchSize(int? fetchSize) => Assign(fetchSize, (a, v) => a.FetchSize = v); /// - /// > public TranslateSqlDescriptor Filter(Func, QueryContainer> querySelector) where T : class => Assign(querySelector, (a, v) => a.Filter = v?.Invoke(new QueryContainerDescriptor()));