Skip to content

Commit 34aa704

Browse files
committed
better terminology
1 parent 984149c commit 34aa704

File tree

6 files changed

+29
-30
lines changed

6 files changed

+29
-30
lines changed

src/MiniSQL.Api/Controllers/DatabaseController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ private SelectResult HandleSelectStatement(SelectStatement statement)
174174
foreach (SchemaRecord indexSchema in indexSchemas)
175175
{
176176
// if there has a condition `=` on indexed column
177-
if (statement.Condition.Ands.ContainsKey(indexSchema.SQL.AttributeName)
178-
&& statement.Condition.Ands[indexSchema.SQL.AttributeName].Operator == Operator.Equal)
177+
if (statement.Condition.SimpleMinterms.ContainsKey(indexSchema.SQL.AttributeName)
178+
&& statement.Condition.SimpleMinterms[indexSchema.SQL.AttributeName].Operator == Operator.Equal)
179179
{
180180
isIndexTreeAvailable = true;
181181
// find out the primary key
182-
List<AtomValue> wrappedPrimaryKey = _recordManager.SelectRecord(statement.Condition.Ands[indexSchema.SQL.AttributeName].RightOperand.ConcreteValue, indexSchema.RootPage);
182+
List<AtomValue> wrappedPrimaryKey = _recordManager.SelectRecord(statement.Condition.SimpleMinterms[indexSchema.SQL.AttributeName].RightOperand.ConcreteValue, indexSchema.RootPage);
183183
primaryKey = wrappedPrimaryKey?[0];
184184
break;
185185
}

src/MiniSQL.CatalogManager/Controllers/Catalog.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public void CheckValidation(IStatement statement)
212212
else if (x.Condition.AttributeName == "")
213213
{
214214

215-
if (x.Condition.Ands.Count == 0)
215+
if (x.Condition.SimpleMinterms.Count == 0)
216216
{
217217
//if the ands is empty and attribute name is emply, the statement means select * from a table
218218
return;
@@ -221,7 +221,7 @@ public void CheckValidation(IStatement statement)
221221
{
222222
//for each attribute in the egression list(named 'ands')
223223
//check whether the attribute is in the attribute list of this table
224-
foreach (KeyValuePair<string, Expression> expression_piece in x.Condition.Ands)
224+
foreach (KeyValuePair<string, Expression> expression_piece in x.Condition.SimpleMinterms)
225225
{
226226
if (!a.return_table(x.FromTable).Has_attribute(expression_piece.Key))
227227
{
@@ -257,7 +257,7 @@ public void CheckValidation(IStatement statement)
257257
else if (x.Condition.AttributeName == "")
258258
{
259259

260-
if (x.Condition.Ands.Count == 0)
260+
if (x.Condition.SimpleMinterms.Count == 0)
261261
{
262262
//if the ands is empty and attribute name is emply, the statement means select * from a table
263263
return;
@@ -266,7 +266,7 @@ public void CheckValidation(IStatement statement)
266266
{
267267
//for each attribute in the epression list(named 'ands')
268268
//check whether the attribute is in the attribute list of this table
269-
foreach (KeyValuePair<string, Expression> expression_piece in x.Condition.Ands)
269+
foreach (KeyValuePair<string, Expression> expression_piece in x.Condition.SimpleMinterms)
270270
{
271271
if (!a.return_table(x.TableName).Has_attribute(expression_piece.Key))
272272
{

src/MiniSQL.IndexManager/Controllers/BTreeController.Find.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public List<BTreeCell> FindCells(BTreeNode root, Expression expression, string k
3939
{
4040
return LinearSearch(root, expression, attributeDeclarations);
4141
}
42-
else if (expression.Ands.ContainsKey(keyName))
42+
else if (expression.SimpleMinterms.ContainsKey(keyName))
4343
{
4444
List<BTreeCell> result = new List<BTreeCell>();
4545
List<AtomValue> values = new List<AtomValue>();
@@ -49,11 +49,11 @@ public List<BTreeCell> FindCells(BTreeNode root, Expression expression, string k
4949
UInt16 offset;
5050
int begin_Index;
5151

52-
AtomValue bound = expression.Ands[keyName].RightOperand.ConcreteValue;
52+
AtomValue bound = expression.SimpleMinterms[keyName].RightOperand.ConcreteValue;
5353

5454
values.Add(bound);
5555
DBRecord keyFind = new DBRecord(values);
56-
switch (expression.Ands[keyName].Operator)
56+
switch (expression.SimpleMinterms[keyName].Operator)
5757
{
5858
case Operator.NotEqual:
5959
return LinearSearch(root, expression, attributeDeclarations);

src/MiniSQL.Library/Models/Statement/Expression.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,22 @@ public class Expression
3737
public AtomValue ConcreteValue { get; set; } = null;
3838
// use if this Expression is only an attribute (variable)
3939
public string AttributeName { get; set; } = "";
40-
41-
// {attribute name: expression with only the variable/attribute}
42-
private Dictionary<string, Expression> ands = null;
40+
private Dictionary<string, Expression> simpleMinterms = null;
4341
// to help B-Tree's single key searching
4442
// NOTICE: never try to modify it by yourself
45-
public Dictionary<string, Expression> Ands
43+
// only contains simple expressions, with left child being variable, right child being concrete value, and root being non-and operator.
44+
public Dictionary<string, Expression> SimpleMinterms
4645
{
4746
get
4847
{
49-
if (this.ands == null)
48+
if (this.simpleMinterms == null)
5049
{
51-
this.ands = new Dictionary<string, Expression>();
50+
this.simpleMinterms = new Dictionary<string, Expression>();
5251
this.BuildAndList();
53-
return this.ands;
52+
return this.simpleMinterms;
5453
}
5554
else
56-
return this.ands;
55+
return this.simpleMinterms;
5756
}
5857
}
5958

@@ -99,33 +98,33 @@ private void BuildAndList()
9998
break;
10099
}
101100
// add to the "and" list
102-
this.Ands[this.LeftOperand.AttributeName] = this;
101+
this.SimpleMinterms[this.LeftOperand.AttributeName] = this;
103102
}
104103
else if (this.LeftOperand.Operator == Operator.AtomVariable
105104
&& this.RightOperand.Operator == Operator.AtomConcreteValue)
106-
this.Ands[this.LeftOperand.AttributeName] = this;
105+
this.SimpleMinterms[this.LeftOperand.AttributeName] = this;
107106
}
108-
// only operator `and` could take `Ands` in its children
107+
// only operator `and` could take `SimpleMinterms` in its children
109108
else if (this.Operator == Operator.And)
110109
{
111-
foreach (var andExpresion in this.LeftOperand.Ands.ToList())
110+
foreach (var andExpresion in this.LeftOperand.SimpleMinterms.ToList())
112111
{
113-
this.Ands[andExpresion.Key] = andExpresion.Value;
112+
this.SimpleMinterms[andExpresion.Key] = andExpresion.Value;
114113
}
115114
// duplicate key will be overwritten
116-
foreach (var andExpresion in this.RightOperand.Ands.ToList())
115+
foreach (var andExpresion in this.RightOperand.SimpleMinterms.ToList())
117116
{
118-
this.Ands[andExpresion.Key] = andExpresion.Value;
117+
this.SimpleMinterms[andExpresion.Key] = andExpresion.Value;
119118
}
120119
}
121120
}
122121

123122
// check if a value could satisfy part of the expression
124123
public bool CheckKey(string attributeName, AtomValue valueToCheck)
125124
{
126-
if (this.Ands.ContainsKey(attributeName))
125+
if (this.SimpleMinterms.ContainsKey(attributeName))
127126
{
128-
AtomValue result = this.Ands[attributeName].Calculate(new List<AttributeValue>
127+
AtomValue result = this.SimpleMinterms[attributeName].Calculate(new List<AttributeValue>
129128
{
130129
new AttributeValue(attributeName, new AtomValue()
131130
{
@@ -173,7 +172,7 @@ public AtomValue Calculate(List<AttributeValue> row)
173172
// // make sure the types of children are the same
174173
// if (leftValue?.Type != rightValue?.Type)
175174
// {
176-
// throw new System.Exception("Operands type not matched!");
175+
// throw new System.Exception("OpersimpleMinterms type not matched!");
177176
// }
178177

179178
// calculate the two children into a value

src/MiniSQL.Library/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private static void TestCalculateSingleValue()
105105
private static void TestAndList()
106106
{
107107
Expression andsExpression = GetAndsExpression();
108-
var andList = andsExpression.Ands;
108+
var andList = andsExpression.SimpleMinterms;
109109
// "not equal" operator is ignored
110110
Debug.Assert(andList.ContainsKey("a") == false);
111111
Debug.Assert(andList["b"].Operator == Operator.LessThanOrEqualTo);

tests/MiniSQL.Library.Tests/UnitTest1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private static void TestCalculateSingleValue()
106106
private static void TestAndList()
107107
{
108108
Expression andsExpression = GetAndsExpression();
109-
var andList = andsExpression.Ands;
109+
var andList = andsExpression.SimpleMinterms;
110110
// "not equal" operator is ignored
111111
Assert.False(andList.ContainsKey("a"));
112112
Assert.Equal(Operator.LessThanOrEqualTo, andList["b"].Operator);

0 commit comments

Comments
 (0)