mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
- 增加 Clickhouse Sample 采样子句;
This commit is contained in:
@ -16,6 +16,9 @@ public static partial class FreeSqlClickHouseGlobalExtensions
|
||||
public static string FormatClickHouse(this string that, params object[] args) => _clickHouseAdo.Addslashes(that, args);
|
||||
static FreeSql.ClickHouse.ClickHouseAdo _clickHouseAdo = new FreeSql.ClickHouse.ClickHouseAdo();
|
||||
|
||||
/// <summary>
|
||||
/// Clickhouse limit by
|
||||
/// </summary>
|
||||
public static ISelect<T> LimitBy<T>(this ISelect<T> that, Expression<Func<T, object>> selector, int limit, int offset = 0)
|
||||
{
|
||||
if (limit <= 0 && offset <= 0) return that;
|
||||
@ -25,7 +28,7 @@ public static partial class FreeSqlClickHouseGlobalExtensions
|
||||
try
|
||||
{
|
||||
s0p.InternalOrderBy(selector);
|
||||
s0p._limitBy = $"limit {(offset > 0 ? $"{offset}, " : "")}{limit} by {s0p._orderby}";
|
||||
s0p._limitBy = $"LIMIT {(offset > 0 ? $"{offset}, " : "")}{limit} BY {s0p._orderby}";
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -33,4 +36,20 @@ public static partial class FreeSqlClickHouseGlobalExtensions
|
||||
}
|
||||
return that;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clickhouse 采样子句
|
||||
/// </summary>
|
||||
public static ISelect<T> Sample<T>(this ISelect<T> that, decimal k, int n, decimal m)
|
||||
{
|
||||
var s0p = that as ClickHouseSelect<T>;
|
||||
if (k > 0)
|
||||
if (m > 0)
|
||||
s0p._sample = $"SAMPLE {k} OFFSET {m}";
|
||||
else
|
||||
s0p._sample = $"SAMPLE {k}";
|
||||
else if (n > 0)
|
||||
s0p._sample = $"SAMPLE {k}";
|
||||
return that;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user