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);