From d9df8b51119ca7cb00b0c3ffd73aa1665fafbede Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=BD=98=E5=BB=BA=E4=B8=9C?= <617601767@qq.com>
Date: Thu, 14 Mar 2024 13:42:59 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9F=A5=E8=AF=A2=E6=8E=A5?=
=?UTF-8?q?=E5=8F=A3=E5=88=97=E8=AE=BE=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Hadoop/ZKLT.Hadoop.Interface/ITableService.cs | 6 +-
Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs | 7 ++
Hadoop/ZKLT.Hadoop/HadoopService.cs | 18 ++---
Hadoop/ZKLT.Hadoop/TableService.cs | 69 +++++++++++++++++--
4 files changed, 82 insertions(+), 18 deletions(-)
diff --git a/Hadoop/ZKLT.Hadoop.Interface/ITableService.cs b/Hadoop/ZKLT.Hadoop.Interface/ITableService.cs
index b637140..10b2a6c 100644
--- a/Hadoop/ZKLT.Hadoop.Interface/ITableService.cs
+++ b/Hadoop/ZKLT.Hadoop.Interface/ITableService.cs
@@ -62,7 +62,7 @@ namespace ZKLT.Hadoop.Interface
/// 条件
/// 数据
/// 结果
- public T? QuerySingle(HDP_Source source, HDP_Table table, Dictionary where, Dictionary row);
+ public T? QuerySingle(HDP_Source source, HDP_Table table, Dictionary where, Dictionary row, string[]? col);
///
/// 查询列表
@@ -73,7 +73,7 @@ namespace ZKLT.Hadoop.Interface
/// 条件
/// 数据
/// 结果集
- public T[] Query(HDP_Source source, HDP_Table table, Dictionary? where = null, Dictionary? row = null, Dictionary? order = null);
+ public T[] Query(HDP_Source source, HDP_Table table, Dictionary? where, Dictionary? row, Dictionary? order, string[]? col);
///
/// 查询列表
@@ -84,7 +84,7 @@ namespace ZKLT.Hadoop.Interface
/// 条件
/// 数据
/// 结果集
- public HDP_Page QueryPage(HDP_Source source, HDP_Table table, int pageIndex, int pageSize, Dictionary? where = null, Dictionary? row = null, Dictionary? order = null);
+ public HDP_Page QueryPage(HDP_Source source, HDP_Table table, int pageIndex, int pageSize, Dictionary? where, Dictionary? row, Dictionary? order, string[]? col);
///
diff --git a/Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs b/Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs
index 4931ac8..aa0c339 100644
--- a/Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs
+++ b/Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs
@@ -21,6 +21,8 @@ namespace ZKLT.Hadoop.Model
private string? _Type;
+ private string[]? _Col;
+
private Dictionary? _Where;
private Dictionary? _Data;
@@ -66,5 +68,10 @@ namespace ZKLT.Hadoop.Model
/// 命令类型
///
public string? Type { get => _Type; set => _Type = value; }
+
+ ///
+ /// 列
+ ///
+ public string[]? Col { get => _Col; set => _Col = value; }
}
}
diff --git a/Hadoop/ZKLT.Hadoop/HadoopService.cs b/Hadoop/ZKLT.Hadoop/HadoopService.cs
index 79b77ba..0872e8e 100644
--- a/Hadoop/ZKLT.Hadoop/HadoopService.cs
+++ b/Hadoop/ZKLT.Hadoop/HadoopService.cs
@@ -145,7 +145,7 @@ namespace ZKLT.Hadoop
{ "Id","=" }
}, new Dictionary {
{ "Id",sourceid}
- });
+ }, null);
return _result;
}
@@ -262,7 +262,7 @@ namespace ZKLT.Hadoop
/// 结果
public HDP_Source[] QuerySource(HDP_Command command)
{
- return _TableService.Query(_Source, GetTable("HDP_Source")!, command.Where!, command.Data!, command.Order!);
+ return _TableService.Query(_Source, GetTable("HDP_Source")!, command.Where!, command.Data!, command.Order!, command.Col);
}
///
@@ -287,7 +287,7 @@ namespace ZKLT.Hadoop
{ "Id","=" }
}, new Dictionary {
{ "Id",tableid}
- });
+ }, null);
if (_result != null)
{
@@ -295,7 +295,7 @@ namespace ZKLT.Hadoop
{ "TableId","="}
}, new Dictionary {
{"TableId",_result.Id! }
- });
+ }, null, null);
}
return _result;
@@ -376,7 +376,7 @@ namespace ZKLT.Hadoop
if (_TableService.QuerySingle(_Source, GetTable("HDP_Column")!, new Dictionary
{
{"Id","=" }
- }, HDP_Table.Class2Dictionary(_column)) == null)
+ }, HDP_Table.Class2Dictionary(_column), null) == null)
{
if (!_TableService.Insert(_Source, GetTable("HDP_Column")!, HDP_Table.Class2Dictionary(_column)))
{
@@ -452,7 +452,7 @@ namespace ZKLT.Hadoop
/// 结果
public HDP_Table[] QueryTable(HDP_Command command)
{
- return _TableService.Query(_Source, GetTable("HDP_Table")!, command.Where!, command.Data!, command.Order!);
+ return _TableService.Query(_Source, GetTable("HDP_Table")!, command.Where!, command.Data!, command.Order!, command.Col!);
}
///
@@ -533,7 +533,7 @@ namespace ZKLT.Hadoop
throw new ArgumentException("表不存在");
}
var _source = GetSource(_table.SourceId!);
- return _TableService.QuerySingle(_source!, _table, command.Where!, command.Data!);
+ return _TableService.QuerySingle(_source!, _table, command.Where!, command.Data!, command.Col);
}
///
@@ -554,7 +554,7 @@ namespace ZKLT.Hadoop
throw new ArgumentException("表不存在");
}
var _source = GetSource(_table.SourceId!);
- return _TableService.Query(_source!, _table, command.Where!, command.Data!, command.Order!);
+ return _TableService.Query(_source!, _table, command.Where!, command.Data!, command.Order!, command.Col);
}
///
@@ -583,7 +583,7 @@ namespace ZKLT.Hadoop
throw new ArgumentException("表不存在");
}
var _source = GetSource(_table.SourceId!);
- return _TableService.QueryPage(_source!, _table, (int)command.PageIndex, (int)command.PageSize, command.Where!, command.Data!, command.Order!);
+ return _TableService.QueryPage(_source!, _table, (int)command.PageIndex, (int)command.PageSize, command.Where!, command.Data!, command.Order!, command.Col!);
}
///
diff --git a/Hadoop/ZKLT.Hadoop/TableService.cs b/Hadoop/ZKLT.Hadoop/TableService.cs
index 0d3658a..fee0a39 100644
--- a/Hadoop/ZKLT.Hadoop/TableService.cs
+++ b/Hadoop/ZKLT.Hadoop/TableService.cs
@@ -51,6 +51,33 @@ namespace ZKLT.Hadoop
}
}
+ ///
+ /// 合并列
+ ///
+ /// 表
+ /// 列
+ /// 命令
+ private void MergeCols(HDP_Table table, string[]? cols, StringBuilder command)
+ {
+ if (cols == null || cols.Length == 0)
+ {
+ command.AppendLine(" * ");
+ }
+ StringBuilder _colstr = new StringBuilder();
+ for (var i = 0; i < table.Columns!.Length; i++)
+ {
+ if (cols!.Any(x => x == table.Columns[i].Key))
+ {
+ _colstr.Append($@"`{table.Columns[i].Key}`,");
+ }
+ }
+ if (_colstr[_colstr.Length - 1] == ',')
+ {
+ _colstr.Remove(_colstr.Length - 1, 1);
+ }
+ command.AppendLine(_colstr.ToString());
+ }
+
///
/// 同步结构
///
@@ -504,7 +531,8 @@ namespace ZKLT.Hadoop
/// 条件
/// 数据
/// 结果
- public T? QuerySingle(HDP_Source source, HDP_Table table, Dictionary where, Dictionary row)
+ public T? QuerySingle(HDP_Source source, HDP_Table table, Dictionary where, Dictionary row,
+ string[]? col)
{
//数据校验
if (string.IsNullOrEmpty(table.Key))
@@ -537,7 +565,16 @@ namespace ZKLT.Hadoop
//查询命令
StringBuilder _command = new StringBuilder();
Dictionary _params = new Dictionary();
- _command.AppendLine(@$"SELECT * FROM `{table.Key}`");
+ if (col == null || col.Length == 0)
+ {
+ _command.AppendLine(@$"SELECT * FROM `{table.Key}`");
+ }
+ else
+ {
+ _command.AppendLine("SELECT");
+ MergeCols(table, col, _command);
+ _command.AppendLine($@"FROM `{table.Key}`");
+ }
//执行条件
MergeWhere(table, where, row, _command, _params);
@@ -564,7 +601,8 @@ namespace ZKLT.Hadoop
/// 条件
/// 数据
/// 结果集
- public T[] Query(HDP_Source source, HDP_Table table, Dictionary? where = null, Dictionary? row = null, Dictionary? order = null)
+ public T[] Query(HDP_Source source, HDP_Table table, Dictionary? where, Dictionary? row,
+ Dictionary? order, string[]? col)
{
//数据校验
if (string.IsNullOrEmpty(table.Key))
@@ -589,7 +627,16 @@ namespace ZKLT.Hadoop
//查询命令
StringBuilder _command = new StringBuilder();
Dictionary _params = new Dictionary();
- _command.AppendLine(@$"SELECT * FROM `{table.Key}`");
+ if (col == null || col.Length == 0)
+ {
+ _command.AppendLine(@$"SELECT * FROM `{table.Key}`");
+ }
+ else
+ {
+ _command.AppendLine("SELECT");
+ MergeCols(table, col, _command);
+ _command.AppendLine($@"FROM `{table.Key}`");
+ }
//执行条件
MergeWhere(table, where, row, _command, _params);
@@ -636,7 +683,8 @@ namespace ZKLT.Hadoop
/// 条件
/// 数据
/// 结果集
- public HDP_Page QueryPage(HDP_Source source, HDP_Table table, int pageIndex, int pageSize, Dictionary? where = null, Dictionary? row = null, Dictionary? order = null)
+ public HDP_Page QueryPage(HDP_Source source, HDP_Table table, int pageIndex, int pageSize, Dictionary? where,
+ Dictionary? row, Dictionary? order, string[]? col)
{
//数据校验
if (string.IsNullOrEmpty(table.Key))
@@ -661,7 +709,16 @@ namespace ZKLT.Hadoop
//查询命令
StringBuilder _command = new StringBuilder();
Dictionary _params = new Dictionary();
- _command.AppendLine(@$"SELECT * FROM `{table.Key}`");
+ if (col == null || col.Length == 0)
+ {
+ _command.AppendLine(@$"SELECT * FROM `{table.Key}`");
+ }
+ else
+ {
+ _command.AppendLine("SELECT");
+ MergeCols(table, col, _command);
+ _command.AppendLine($@"FROM `{table.Key}`");
+ }
//执行条件
MergeWhere(table, where, row, _command, _params);