DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
GroupNode.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 
21 using Deveel.Data.Sql.Tables;
22 
23 namespace Deveel.Data.Sql.Query {
24  [Serializable]
26  public GroupNode(IQueryPlanNode child, ObjectName groupMaxColumn, SqlExpression[] functions, string[] names)
27  : this(child, new ObjectName[0], groupMaxColumn, functions, names) {
28  }
29 
30  public GroupNode(IQueryPlanNode child, ObjectName[] columnNames, ObjectName groupMaxColumn, SqlExpression[] functions, string[] names) : base(child) {
31  ColumnNames = columnNames;
32  GroupMaxColumn = groupMaxColumn;
33  Functions = functions;
34  Names = names;
35  }
36 
37  private GroupNode(ObjectData data)
38  : base(data) {
39  ColumnNames = data.GetValue<ObjectName[]>("Columns");
40  GroupMaxColumn = data.GetValue<ObjectName>("GroupMax");
41  Functions = data.GetValue<SqlExpression[]>("Functions");
42  Names = data.GetValue<string[]>("Names");
43  }
44 
45  public ObjectName[] ColumnNames { get; private set; }
46 
47  public ObjectName GroupMaxColumn { get; private set; }
48 
49  public SqlExpression[] Functions { get; private set; }
50 
51  public string[] Names { get; private set; }
52 
53  protected override void GetData(SerializeData data) {
54  data.SetValue("Columns", ColumnNames);
55  data.SetValue("GroupMax", GroupMaxColumn);
56  data.SetValue("Functions", Functions);
57  data.SetValue("Names", Names);
58  }
59 
60  public override ITable Evaluate(IRequest context) {
61  var childTable = Child.Evaluate(context);
62  var funTable = new FunctionTable(childTable, Functions, Names, context);
63 
64  // If no columns then it is implied the whole table is the group.
65  if (ColumnNames == null) {
66  funTable = funTable.AsGroup();
67  } else {
68  funTable = funTable.CreateGroupMatrix(ColumnNames);
69  }
70 
71  return funTable.MergeWith(GroupMaxColumn);
72  }
73  }
74 }
Defines the contract to access the data contained into a table of a database.
Definition: ITable.cs:40
A IQueryPlanNode with a single child.
A query to the database to select data from a set of tables and columns.
GroupNode(IQueryPlanNode child, ObjectName[] columnNames, ObjectName groupMaxColumn, SqlExpression[] functions, string[] names)
Definition: GroupNode.cs:30
void SetValue(string key, Type type, object value)
Describes the name of an object within a database.
Definition: ObjectName.cs:44
A node element of a query plan tree. /summary>
override ITable Evaluate(IRequest context)
Definition: GroupNode.cs:60
GroupNode(ObjectData data)
Definition: GroupNode.cs:37
Defines the base class for instances that represent SQL expression tree nodes.
override void GetData(SerializeData data)
Definition: GroupNode.cs:53
GroupNode(IQueryPlanNode child, ObjectName groupMaxColumn, SqlExpression[] functions, string[] names)
Definition: GroupNode.cs:26