-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add SQL APIs Does not include SQL Translate API at this stage. Co-authored-by: Steve Gordon <sgordon@hotmail.co.uk>
- Loading branch information
1 parent
25459f7
commit 08e7891
Showing
26 changed files
with
1,891 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/Elastic.Clients.Elasticsearch/Api/SqlGetAsyncResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// 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.Text.Json.Serialization; | ||
|
||
namespace Elastic.Clients.Elasticsearch.Sql; | ||
|
||
public partial class SqlGetAsyncResponse | ||
{ | ||
[JsonInclude] | ||
[JsonPropertyName("rows")] | ||
public IReadOnlyCollection<SqlRow> Rows { get; init; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// 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; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Elastic.Clients.Elasticsearch.Sql; | ||
|
||
[JsonConverter(typeof(SqlRowConverter))] | ||
public sealed class SqlRow : ReadOnlyCollection<SqlValue> | ||
{ | ||
public SqlRow(IList<SqlValue> list) : base(list) { } | ||
} | ||
|
||
internal sealed class SqlRowConverter : JsonConverter<SqlRow> | ||
{ | ||
public override SqlRow? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
if (reader.TokenType == JsonTokenType.Null) | ||
{ | ||
reader.Read(); | ||
return null; | ||
} | ||
|
||
if (reader.TokenType == JsonTokenType.StartArray) | ||
{ | ||
var values = new List<SqlValue>(); | ||
|
||
while (reader.Read() && reader.TokenType != JsonTokenType.EndArray) | ||
{ | ||
var value = JsonSerializer.Deserialize<SqlValue>(ref reader, options); | ||
values.Add(value); | ||
} | ||
|
||
return new SqlRow(values); | ||
} | ||
|
||
throw new JsonException($"Unexpected JSON token when deserializing {nameof(SqlRow)}."); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, SqlRow value, JsonSerializerOptions options) => throw new NotImplementedException(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// 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; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Elastic.Clients.Elasticsearch.Sql; | ||
|
||
[JsonConverter(typeof(SqlValueConverter))] | ||
public readonly struct SqlValue | ||
{ | ||
private readonly LazyDocument _lazyDocument; | ||
|
||
internal SqlValue(LazyDocument lazyDocument) => _lazyDocument = lazyDocument; | ||
|
||
public T? As<T>() => _lazyDocument.As<T>(); | ||
} | ||
|
||
internal sealed class SqlValueConverter : JsonConverter<SqlValue> | ||
{ | ||
public override SqlValue Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
if (reader.TokenType == JsonTokenType.Null) | ||
{ | ||
reader.Read(); | ||
return default; | ||
} | ||
|
||
var lazyDoc = JsonSerializer.Deserialize<LazyDocument>(ref reader, options); | ||
return new SqlValue(lazyDoc); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, SqlValue value, JsonSerializerOptions options) => throw new NotImplementedException(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,4 +199,4 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o | |
{ | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.