Skip to content

Commit

Permalink
[ksqlDB.RestApi.Client]: reduced namespaces in KSQL parameters folder
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasfabian committed Apr 27, 2024
1 parent 6219390 commit 96876f8
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
namespace ksqlDB.RestApi.Client.KSql.RestApi.Parameters;

/// <summary>
/// Represents parameters for a KSqlDb endpoint.
/// </summary>
public interface IKSqlDbParameters : IQueryParameters
{
/// <summary>
/// Clones the current parameters.
/// </summary>
/// <returns>A new instance of the parameters with the same values.</returns>
IKSqlDbParameters Clone();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace ksqlDB.RestApi.Client.KSql.RestApi.Parameters
namespace ksqlDB.RestApi.Client.KSql.RestApi.Parameters;

/// <summary>
/// Represents parameters for a pull query.
/// </summary>
public interface IPullQueryParameters : IKSqlDbParameters
{
public interface IPullQueryParameters : IKSqlDbParameters
{
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using ksqlDB.RestApi.Client.KSql.Query.Options;

namespace ksqlDB.RestApi.Client.KSql.RestApi.Parameters
namespace ksqlDB.RestApi.Client.KSql.RestApi.Parameters;

/// <summary>
/// Represents parameters for a push query.
/// </summary>
public interface IPushQueryParameters : IKSqlDbParameters
{
public interface IPushQueryParameters : IKSqlDbParameters
{
AutoOffsetReset AutoOffsetReset { get; set; }
}
AutoOffsetReset AutoOffsetReset { get; set; }
}
17 changes: 14 additions & 3 deletions ksqlDb.RestApi.Client/KSql/RestApi/Parameters/IQueryParameters.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
namespace ksqlDB.RestApi.Client.KSql.RestApi.Parameters;
namespace ksqlDB.RestApi.Client.KSql.RestApi.Parameters;

/// <summary>
/// Represents query parameters for a KSqlDb endpoint.
/// </summary>
public interface IQueryParameters : IQueryOptions
{
/// <summary>
/// A semicolon-delimited sequence of SQL statements to run.
/// </summary>
string Sql { get; set; }


/// <summary>
/// Indexer to access properties by key.
/// </summary>
/// <param name="key">The key of the property.</param>
/// <returns>The value of the property.</returns>
string this[string key] { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace ksqlDB.RestApi.Client.KSql.RestApi.Parameters
namespace ksqlDB.RestApi.Client.KSql.RestApi.Parameters;

/// <summary>
/// Represents parameters for a pull query endpoint.
/// </summary>
public class PullQueryParameters : QueryEndpointParameters<PullQueryParameters>, IPullQueryParameters
{
public class PullQueryParameters : QueryEndpointParameters<PullQueryParameters>, IPullQueryParameters
{
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace ksqlDB.RestApi.Client.KSql.RestApi.Parameters
namespace ksqlDB.RestApi.Client.KSql.RestApi.Parameters;

/// <summary>
/// Represents parameters for a pull query stream endpoint.
/// </summary>
public class PullQueryStreamParameters : QueryStreamEndpointParameters<PullQueryStreamParameters>, IPullQueryParameters
{
public class PullQueryStreamParameters : QueryStreamEndpointParameters<PullQueryStreamParameters>, IPullQueryParameters
{
}
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,73 @@
using System.Text.Json.Serialization;
using ksqlDB.RestApi.Client.KSql.RestApi.Statements;

namespace ksqlDB.RestApi.Client.KSql.RestApi.Parameters
namespace ksqlDB.RestApi.Client.KSql.RestApi.Parameters;

/// <summary>
/// Represents parameters for a '/query' endpoint.
/// </summary>
/// <typeparam name="T">The type of the query stream endpoint parameters.</typeparam>
public class QueryEndpointParameters<T> : IKSqlDbParameters
where T : QueryEndpointParameters<T>, new()
{
public class QueryEndpointParameters<T> : IKSqlDbParameters
where T : QueryEndpointParameters<T>, new()
/// <summary>
/// A semicolon-delimited sequence of SQL statements to run.
/// </summary>
[JsonPropertyName("ksql")]
public string Sql { get; set; } = null!;

/// <summary>
/// Property overrides to run the statements with.
/// </summary>
[JsonPropertyName("streamsProperties")]
public Dictionary<string, string> Properties { get; } = new();

/// <summary>
/// Indexer to access properties by key.
/// </summary>
/// <param name="key">The key of the property.</param>
/// <returns>The value of the property.</returns>
public string this[string key]
{
/// <summary>
/// A semicolon-delimited sequence of SQL statements to run.
/// </summary>
[JsonPropertyName("ksql")]
public string Sql { get; set; } = null!;

/// <summary>
/// Property overrides to run the statements with.
/// </summary>
[JsonPropertyName("streamsProperties")]
public Dictionary<string, string> Properties { get; } = new();

public string this[string key]
{
get => Properties[key];
set => Properties[key] = value;
}
get => Properties[key];
set => Properties[key] = value;
}

internal EndpointType EndpointType { get; set; } = EndpointType.Query;
internal EndpointType EndpointType { get; set; } = EndpointType.Query;

public void FillFrom(IKSqlDbParameters parameters)
{
this.FillQueryParametersFrom(parameters);
}
/// <summary>
/// Fills the parameters from another set of parameters.
/// </summary>
/// <param name="parameters">The parameters to fill from.</param>
public void FillFrom(IKSqlDbParameters parameters)
{
this.FillQueryParametersFrom(parameters);
}

public IKSqlDbParameters Clone()
/// <summary>
/// Clones the current parameters.
/// </summary>
/// <returns>A new instance of the parameters with the same values.</returns>
public IKSqlDbParameters Clone()
{
var queryParams = new T()
{
var queryParams = new T()
{
Sql = Sql,
EndpointType = EndpointType
};
Sql = Sql,
EndpointType = EndpointType
};

foreach (var entry in Properties)
queryParams.Properties.Add(entry.Key, entry.Value);
foreach (var entry in Properties)
queryParams.Properties.Add(entry.Key, entry.Value);

return queryParams;
}
return queryParams;
}

public override string ToString()
{
return this.ToLogInfo();
}
/// <summary>
/// Returns a string representation of the object.
/// </summary>
/// <returns>A string representation of the object.</returns>
public override string ToString()
{
return this.ToLogInfo();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@

namespace ksqlDB.RestApi.Client.KSql.RestApi.Parameters;

/// <summary>
/// Represents parameters for a query.
/// </summary>
public class QueryParameters : QueryEndpointParameters<QueryParameters>, IPushQueryParameters
{
public static readonly string AutoOffsetResetPropertyName = "ksql.streams.auto.offset.reset";

/// <summary>
/// Sets the auto offset reset using <see cref="AutoOffsetReset"/>.
/// </summary>
[JsonIgnore]
public AutoOffsetReset AutoOffsetReset
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static void FillQueryParametersFrom(this IQueryParameters destination,
destination.Properties.Add(entry.Key, entry.Value);
}

public static string ToLogInfo(this IQueryParameters queryParameters)
internal static string ToLogInfo(this IQueryParameters queryParameters)
{
var sb = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,70 @@
using System.Text.Json.Serialization;

namespace ksqlDB.RestApi.Client.KSql.RestApi.Parameters
namespace ksqlDB.RestApi.Client.KSql.RestApi.Parameters;

/// <summary>
/// Represents parameters for a '/query-stream' endpoint.
/// </summary>
/// <typeparam name="T">The type of the query stream endpoint parameters.</typeparam>
public class QueryStreamEndpointParameters<T> : IKSqlDbParameters
where T : QueryStreamEndpointParameters<T>, new()
{
public class QueryStreamEndpointParameters<T> : IKSqlDbParameters
where T : QueryStreamEndpointParameters<T>, new()
{
[JsonPropertyName("sql")]
public string Sql { get; set; } = null!;
/// <summary>
/// A semicolon-delimited sequence of SQL statements to run.
/// </summary>
[JsonPropertyName("sql")]
public string Sql { get; set; } = null!;

[JsonPropertyName("properties")]
public Dictionary<string, string> Properties { get; } = new();
/// <summary>
/// Property overrides to run the statements with.
/// </summary>
[JsonPropertyName("properties")]
public Dictionary<string, string> Properties { get; } = new();

public string this[string key]
{
get => Properties[key];
set => Properties[key] = value;
}
/// <summary>
/// Indexer to access properties by key.
/// </summary>
/// <param name="key">The key of the property.</param>
/// <returns>The value of the property.</returns>
public string this[string key]
{
get => Properties[key];
set => Properties[key] = value;
}

/// <summary>
/// Fills the parameters from another set of parameters.
/// </summary>
/// <param name="parameters">The parameters to fill from.</param>
public void FillFrom(IKSqlDbParameters parameters)
{
this.FillQueryParametersFrom(parameters);
}

public void FillFrom(IKSqlDbParameters parameters)
{
this.FillQueryParametersFrom(parameters);
}

public IKSqlDbParameters Clone()
/// <summary>
/// Clones the current parameters.
/// </summary>
/// <returns>A new instance of the parameters with the same values.</returns>
public IKSqlDbParameters Clone()
{
var queryParams = new T()
{
var queryParams = new T()
{
Sql = Sql
};
Sql = Sql
};

foreach (var entry in Properties)
queryParams.Properties.Add(entry.Key, entry.Value);
foreach (var entry in Properties)
queryParams.Properties.Add(entry.Key, entry.Value);

return queryParams;
}
return queryParams;
}

public override string ToString()
{
return this.ToLogInfo();
}
/// <summary>
/// Returns a string representation of the object.
/// </summary>
/// <returns>A string representation of the object.</returns>
public override string ToString()
{
return this.ToLogInfo();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@

namespace ksqlDB.RestApi.Client.KSql.RestApi.Parameters;

/// <summary>
/// Represents parameters for a query stream.
/// </summary>
public sealed class QueryStreamParameters : QueryStreamEndpointParameters<QueryStreamParameters>, IPushQueryParameters
{
public static readonly string AutoOffsetResetPropertyName = "auto.offset.reset";

/// <summary>
/// Sets the auto offset reset using <see cref="AutoOffsetReset"/>.
/// </summary>
[JsonIgnore]
public AutoOffsetReset AutoOffsetReset
{
Expand Down

0 comments on commit 96876f8

Please sign in to comment.