The WHERE clause consists of boolean expressions
Inheritance: WSqlFragment
        public void Invoke(WWhereClause node, MatchGraph graph, Dictionary<string, string> columnTableMapping)
        {
            _graph = graph;
            _columnTableMapping = columnTableMapping;

            if (node.SearchCondition != null)
                node.SearchCondition.Accept(this);
        }
        public void Invoke(WWhereClause node, MatchGraph graph)
        {
            _graph = graph;

            if (node.SearchCondition != null)
            {
                node.SearchCondition.Accept(this);
            }
        }
Example #3
0
        public void Invoke(WWhereClause node, MatchGraph graph, Dictionary <string, string> columnTableMapping)
        {
            _graph = graph;
            _columnTableMapping = columnTableMapping;

            if (node.SearchCondition != null)
            {
                node.SearchCondition.Accept(this);
            }
        }
 public WWhereClause Invoke(WWhereClause node, MatchGraph graph, Dictionary <string, string> columnTableMapping)
 {
     _checkNodeEdgeReferenceVisitor = new CheckNodeEdgeReferenceVisitor(graph, columnTableMapping)
     ;
     if (node.SearchCondition != null)
     {
         node.SearchCondition.Accept(this);
     }
     return(_nodeEdgePredicatesWhenClause);
 }
 public void UpdateWherClause(WWhereClause whereClause, WBooleanExpression node)
 {
     if (whereClause.SearchCondition == null)
     {
         whereClause.SearchCondition = node;
     }
     else
     {
         whereClause.SearchCondition = new WBooleanBinaryExpression
         {
             FirstExpr             = whereClause.SearchCondition,
             SecondExpr            = node,
             BooleanExpressionType = BooleanBinaryExpressionType.And
         };
     }
 }
 private void AttachPredicates(WWhereClause whereClause, MatchGraph graph)
 {
     // Attaches proper parts of the where clause into the Estimiation Query
     var attachPredicateVisitor = new AttachWhereClauseVisitor();
     var columnTableMapping = _context.GetColumnToAliasMapping(_graphMetaData.ColumnsOfNodeTables);
     attachPredicateVisitor.Invoke(whereClause, graph, columnTableMapping);
 }
 public virtual void Visit(WWhereClause node)
 {
     node.AcceptChildren(this);
 }
 public WUpdateSpecification()
 {
     WhereClause = new WWhereClause();
 }
 public WDeleteSpecification()
 {
     WhereClause = new WWhereClause();
 }
        private void TranslateEdgeDelete(WDeleteEdgeSpecification node, List<WSqlStatement> res)
        {
            const string deleteEdgeTableName = "GraphView_DeleteEdgeInternalTable";
            string deleteEdgeTempTable = "DeleteTmp_" + Path.GetRandomFileName().Replace(".", "").Substring(0, 8);

            // Wraps the select statement in a common table expression
            WTableReference sinkTable, sourceTable;
            var deleteCommonTableExpr = ConstructDeleteEdgeSelect(node.SelectDeleteExpr,
                node.EdgeColumn.Alias, deleteEdgeTempTable,
                out sinkTable, out sourceTable);
            var sourceNameTable = sourceTable as WNamedTableReference;
            if (sourceNameTable == null)
                throw new GraphViewException("Source table of DELETE EDGE statement should be a named table reference.");
            var sinkNameTable = sinkTable as WNamedTableReference;
            if (sinkNameTable == null)
                throw new GraphViewException("Sink table of DELETE EDGE statement should be a named table reference.");


            // Get edge select query and reversed edge select query
            WSelectQueryBlock edgeSelectQuery = new WSelectQueryBlock
            {
                SelectElements = new List<WSelectElement>
                {
                    new WSelectScalarExpression
                    {
                        SelectExpr = new WColumnReferenceExpression
                        {
                            MultiPartIdentifier = new WMultiPartIdentifier(new Identifier {Value = "src"})
                        },
                        ColumnName = "source"
                    },
                    new WSelectScalarExpression
                    {
                        SelectExpr = new WFunctionCall
                        {
                            CallTarget = new WMultiPartIdentifierCallTarget
                            {
                                Identifiers = new WMultiPartIdentifier(new Identifier {Value = "dbo"})
                            },
                            FunctionName = new Identifier {Value = GraphViewConnection.GraphViewUdfAssemblyName + "EdgeIdEncoder"},
                            Parameters = new List<WScalarExpression>
                            {
                                new WColumnReferenceExpression
                                {
                                    MultiPartIdentifier = new WMultiPartIdentifier(new Identifier {Value = "edgeid"})
                                },
                            },
                        },
                        ColumnName = "binary1"
                    },
                    new WSelectScalarExpression
                    {
                        SelectExpr = new WFunctionCall
                        {
                            FunctionName = new Identifier{Value = "COUNT"},
                            Parameters = new List<WScalarExpression>
                            {
                                new WColumnReferenceExpression
                                {
                                    MultiPartIdentifier = new WMultiPartIdentifier(new Identifier {Value = "sink"})
                                },
                            },
                        },
                        ColumnName = "sinkCnt"
                    }
                    
                },
                FromClause = new WFromClause
                {
                    TableReferences = new List<WTableReference>
                    {
                        new WSpecialNamedTableReference
                        {
                            TableObjectName = new WSchemaObjectName(new Identifier{Value = deleteEdgeTempTable })
                        }
                    }
                },
                GroupByClause = new WGroupByClause
                {
                    GroupingSpecifications = new List<WGroupingSpecification>
                    {
                        new WExpressionGroupingSpec
                        {
                            Expression = new WValueExpression("src",false)
                        }
                    }
                }
            };
            WSelectQueryBlock reversedEdgeSelectQuery = new WSelectQueryBlock
            {
                SelectElements = new List<WSelectElement>
                {
                    new WSelectScalarExpression
                    {
                        SelectExpr = new WColumnReferenceExpression
                        {
                            MultiPartIdentifier = new WMultiPartIdentifier(new Identifier {Value = "sink"})
                        },
                        ColumnName = "source"
                    },
                    new WSelectScalarExpression
                    {
                        SelectExpr = new WFunctionCall
                        {
                            FunctionName =
                                new Identifier
                                {
                                    Value = "COUNT"
                                },
                            Parameters = new List<WScalarExpression>
                            {
                                new WColumnReferenceExpression
                                {
                                    MultiPartIdentifier = new WMultiPartIdentifier(new Identifier {Value = "src"})
                                },
                            }
                        },
                        ColumnName = "srcCnt"
                    },

                },
                FromClause = edgeSelectQuery.FromClause,
                GroupByClause = new WGroupByClause
                {
                    GroupingSpecifications = new List<WGroupingSpecification>
                    {
                        new WExpressionGroupingSpec
                        {
                            Expression = new WValueExpression("sink", false)
                        }
                    }
                }
            };

            //Check src & sink
            string sourceTableName = sourceNameTable.TableObjectName.ToString();
            string sinkTableName = sinkNameTable.TableObjectName.ToString();
            int compare = string.CompareOrdinal(sourceTableName, sinkTableName);
            WSetClause[] setClauses = new WSetClause[]
            {
                new WFunctionCallSetClause()
                {
                    MutatorFuction = new WFunctionCall
                    {
                        CallTarget = new WMultiPartIdentifierCallTarget()
                        {
                            Identifiers =
                                new WMultiPartIdentifier(new Identifier
                                {
                                    Value = node.EdgeColumn.MultiPartIdentifier.Identifiers.Last().Value + "DeleteCol"
                                })
                        },
                        FunctionName = new Identifier {Value = "WRITE"},
                        Parameters = new WScalarExpression[]
                        {
                            new WColumnReferenceExpression
                            {
                                MultiPartIdentifier = new WMultiPartIdentifier(
                                    new Identifier {Value = deleteEdgeTableName},
                                    new Identifier {Value = "binary1"})
                            },
                            new WValueExpression("null", false),
                            new WValueExpression("null", false)
                        }
                    }
                },
                new WAssignmentSetClause()
                {
                    AssignmentKind = AssignmentKind.Equals,
                    Column = new WColumnReferenceExpression
                    {
                        MultiPartIdentifier =
                            new WMultiPartIdentifier(new Identifier
                            {
                                Value = "InDegree"
                            })
                    },
                    NewValue = new WBinaryExpression
                    {
                        FirstExpr = new WColumnReferenceExpression
                        {
                            MultiPartIdentifier =
                                new WMultiPartIdentifier(new Identifier
                                {
                                    Value = "InDegree"
                                })
                        },
                        SecondExpr = new WColumnReferenceExpression
                        {
                            MultiPartIdentifier = new WMultiPartIdentifier(new Identifier {Value = "srcCnt"})
                        },
                        ExpressionType = BinaryExpressionType.Subtract
                    }
                },
                new WAssignmentSetClause()
                {
                    AssignmentKind = AssignmentKind.Equals,
                    Column = new WColumnReferenceExpression
                    {
                        MultiPartIdentifier =
                            new WMultiPartIdentifier(new Identifier
                            {
                                Value = node.EdgeColumn.MultiPartIdentifier.Identifiers.Last().Value + "OutDegree"
                            })
                    },
                    NewValue = new WBinaryExpression
                    {
                        FirstExpr = new WColumnReferenceExpression
                        {
                            MultiPartIdentifier =
                                new WMultiPartIdentifier(new Identifier
                                {
                                    Value = node.EdgeColumn.MultiPartIdentifier.Identifiers.Last().Value + "OutDegree"
                                })
                        },
                        SecondExpr = new WColumnReferenceExpression
                        {
                            MultiPartIdentifier = new WMultiPartIdentifier(new Identifier {Value = "sinkCnt"})
                        },
                        ExpressionType = BinaryExpressionType.Subtract
                    }
                }
                
            };
            WWhereClause whereClause = new WWhereClause
            {
                SearchCondition = new WBooleanComparisonExpression
                {
                    FirstExpr = new WColumnReferenceExpression
                    {
                        MultiPartIdentifier = new WMultiPartIdentifier(new Identifier { Value = "GlobalNodeId" })
                    },
                    SecondExpr = new WColumnReferenceExpression
                    {
                        MultiPartIdentifier = new WMultiPartIdentifier(
                            new Identifier { Value = deleteEdgeTableName },
                            new Identifier { Value = "source" }
                            )
                    },
                    ComparisonType = BooleanComparisonType.Equals
                }
            };
            if (compare == 0)
            {
                res.Add(new WDeclareTableVariable
                {
                    VariableName = new Identifier { Value = "@" + deleteEdgeTempTable},
                    Definition = new WTableDefinition
                    {
                        ColumnDefinitions = new WColumnDefinition[]
                        {
                            new WColumnDefinition
                            {
                                ColumnIdentifier = new Identifier{Value = "source"},
                                DataType = new WParameterizedDataTypeReference{Name = new WSchemaObjectName(new Identifier{Value = "bigint"})},
                                Constraints = new List<WConstraintDefinition>
                                {
                                    new WUniqueConstraintDefinition
                                    {
                                        Clustered = true,
                                        IsPrimaryKey = true
                                    }
                                }
                            }, 
                            new WColumnDefinition
                            {
                                ColumnIdentifier = new Identifier{Value = "binary1"},
                                DataType = new WParameterizedDataTypeReference
                                {
                                    Name = new WSchemaObjectName(new Identifier{Value = "varbinary"}),
                                    Parameters = new List<Literal>{new MaxLiteral{Value = "max"}}
                                },
                            }, 
                            new WColumnDefinition
                            {
                                ColumnIdentifier = new Identifier{Value = "sinkCnt"},
                                DataType = new WParameterizedDataTypeReference
                                {
                                    Name = new WSchemaObjectName(new Identifier{Value = "int"}),
                                },
                            }, 
                            new WColumnDefinition
                            {
                                ColumnIdentifier = new Identifier{Value = "srcCnt"},
                                DataType = new WParameterizedDataTypeReference
                                {
                                    Name = new WSchemaObjectName(new Identifier{Value = "int"}),
                                },
                            }, 
                        },
                        Indexes = new List<WIndexDefinition>(),
                        TableConstraints = new List<WConstraintDefinition>()
                    }
                });
                var tableVar = new WSpecialNamedTableReference
                {
                    TableObjectName = new WSchemaObjectName(new Identifier { Value = "@" + deleteEdgeTempTable })
                };
                res.Add(deleteCommonTableExpr);
                res.Add(new WInsertSpecification
                {
                    Target = tableVar,
                    InsertSource = new WSelectInsertSource
                    {
                        Select = new WSelectQueryBlock
                        {
                            SelectElements = new WSelectElement[]
                            {
                                new WSelectScalarExpression
                                {
                                    SelectExpr = new WFunctionCall
                                    {
                                        FunctionName = new Identifier {Value = "ISNULL"},
                                        Parameters = new WScalarExpression[]
                                        {
                                            new WColumnReferenceExpression
                                            {
                                                MultiPartIdentifier =
                                                    new WSchemaObjectName(new Identifier[]
                                                    {
                                                        new Identifier {Value = deleteEdgeTableName + "_1"},
                                                        new Identifier {Value = "source"}
                                                    }),
                                            },
                                            new WColumnReferenceExpression
                                            {
                                                MultiPartIdentifier =
                                                    new WSchemaObjectName(new Identifier[]
                                                    {
                                                        new Identifier {Value = deleteEdgeTableName + "_2"},
                                                        new Identifier {Value = "source"}
                                                    }),
                                            },
                                        }
                                    },
                                    ColumnName = "source"
                                },
                                new WSelectScalarExpression
                                {
                                    SelectExpr = new WColumnReferenceExpression
                                    {
                                        MultiPartIdentifier =
                                            new WSchemaObjectName(new Identifier[] {new Identifier {Value = "binary1"}}),
                                    }
                                },
                                //new WSelectScalarExpression
                                //{
                                //    SelectExpr = new WColumnReferenceExpression
                                //    {
                                //                MultiPartIdentifier = new WSchemaObjectName(new Identifier[]{new Identifier{Value = "binary2"}}),
                                //    }
                                //}, 
                                new WSelectScalarExpression
                                {
                                    SelectExpr = new WFunctionCall
                                    {
                                        FunctionName = new Identifier {Value = "ISNULL"},
                                        Parameters = new WScalarExpression[]
                                        {
                                            new WColumnReferenceExpression
                                            {
                                                MultiPartIdentifier =
                                                    new WSchemaObjectName(new Identifier[]
                                                    {
                                                        new Identifier {Value = deleteEdgeTableName + "_1"},
                                                        new Identifier {Value = "sinkCnt"}
                                                    }),
                                            },
                                            new WValueExpression
                                            {
                                                Value = "0"
                                            },
                                        }
                                    },
                                    ColumnName = "sinkCnt"
                                },
                                new WSelectScalarExpression
                                {
                                    SelectExpr = new WFunctionCall
                                    {
                                        FunctionName = new Identifier {Value = "ISNULL"},
                                        Parameters = new WScalarExpression[]
                                        {
                                            new WColumnReferenceExpression
                                            {
                                                MultiPartIdentifier =
                                                    new WSchemaObjectName(new Identifier[]
                                                    {
                                                        new Identifier {Value = deleteEdgeTableName + "_2"},
                                                        new Identifier {Value = "srcCnt"}
                                                    }),
                                            },
                                            new WValueExpression
                                            {
                                                Value = "0"
                                            },
                                        }
                                    },
                                    ColumnName = "srcCnt"
                                },
                            },
                            FromClause = new WFromClause
                            {
                                TableReferences = new WTableReference[]
                                {
                                    new WQualifiedJoin
                                    {
                                        QualifiedJoinType = QualifiedJoinType.FullOuter,
                                        FirstTableRef = new WQueryDerivedTable
                                        {
                                            Alias = new Identifier {Value = deleteEdgeTableName + "_1"},
                                            QueryExpr = edgeSelectQuery
                                        },
                                        SecondTableRef = new WQueryDerivedTable
                                        {
                                            Alias = new Identifier {Value = deleteEdgeTableName + "_2"},
                                            QueryExpr = reversedEdgeSelectQuery
                                        },
                                        JoinCondition = new WBooleanComparisonExpression()
                                        {
                                            ComparisonType = BooleanComparisonType.Equals,
                                            FirstExpr = new WColumnReferenceExpression
                                            {
                                                MultiPartIdentifier =
                                                    new WSchemaObjectName(new Identifier[]
                                                    {
                                                        new Identifier {Value = deleteEdgeTableName + "_1"},
                                                        new Identifier {Value = "source"}
                                                    }),
                                            },
                                            SecondExpr = new WColumnReferenceExpression
                                            {
                                                MultiPartIdentifier =
                                                    new WSchemaObjectName(new Identifier[]
                                                    {
                                                        new Identifier {Value = deleteEdgeTableName + "_2"},
                                                        new Identifier {Value = "source"}
                                                    }),
                                            }
                                        }
                                    },
                                }
                            }
                        }
                    }
                });
                res.Add(new WUpdateSpecification
                {
                    Target = new WNamedTableReference
                    {
                        TableObjectName = sourceNameTable.TableObjectName
                    },
                    SetClauses = setClauses,
                    FromClause = new WFromClause
                    {
                        TableReferences = new WTableReference[]
                        {
                            new WQueryDerivedTable
                            {
                                Alias = new Identifier {Value = deleteEdgeTableName},
                                QueryExpr = new WSelectQueryBlock
                                {
                                    SelectElements = new List<WSelectElement>()
                                    {
                                        new WSelectStarExpression()
                                    },
                                    FromClause = new WFromClause
                                    {
                                        TableReferences = new List<WTableReference> {tableVar}
                                    }
                                }
                            },
                        }
                    },
                    WhereClause = whereClause,
                    TopRowFilter = node.TopRowFilter,
                });
                res.Add(new WSqlUnknownStatement
                {
                    Statement = String.Format("DELETE FROM @{0}", deleteEdgeTempTable)
                });
            }
            else
            {
                // Declare table variables
                res.Add(new WDeclareTableVariable
                {
                    VariableName = new Identifier { Value = "@" + deleteEdgeTempTable + "_1" },
                    Definition = new WTableDefinition
                    {
                        ColumnDefinitions = new WColumnDefinition[]
                        {
                            new WColumnDefinition
                            {
                                ColumnIdentifier = new Identifier {Value = "source"},
                                DataType =
                                    new WParameterizedDataTypeReference
                                    {
                                        Name = new WSchemaObjectName(new Identifier {Value = "bigint"})
                                    },
                                Constraints = new List<WConstraintDefinition>
                                {
                                    new WUniqueConstraintDefinition
                                    {
                                        Clustered = true,
                                        IsPrimaryKey = true
                                    }
                                }
                            },
                            new WColumnDefinition
                            {
                                ColumnIdentifier = new Identifier {Value = "binary1"},
                                DataType = new WParameterizedDataTypeReference
                                {
                                    Name = new WSchemaObjectName(new Identifier {Value = "varbinary"}),
                                    Parameters = new List<Literal> {new MaxLiteral {Value = "max"}}
                                },
                            },
                            new WColumnDefinition
                            {
                                ColumnIdentifier = new Identifier {Value = "sinkCnt"},
                                DataType = new WParameterizedDataTypeReference
                                {
                                    Name = new WSchemaObjectName(new Identifier {Value = "int"}),
                                },
                            },
                        },
                        Indexes = new List<WIndexDefinition>(),
                        TableConstraints = new List<WConstraintDefinition>()
                    }
                });
                res.Add(new WDeclareTableVariable
                {
                    VariableName = new Identifier { Value = "@" + deleteEdgeTempTable + "_2" },
                    Definition = new WTableDefinition
                    {
                        ColumnDefinitions = new WColumnDefinition[]
                        {
                            new WColumnDefinition
                            {
                                ColumnIdentifier = new Identifier {Value = "source"},
                                DataType =
                                    new WParameterizedDataTypeReference
                                    {
                                        Name = new WSchemaObjectName(new Identifier {Value = "bigint"})
                                    },
                                Constraints = new List<WConstraintDefinition>
                                {
                                    new WUniqueConstraintDefinition
                                    {
                                        Clustered = true,
                                        IsPrimaryKey = true
                                    }
                                }
                            },
                            new WColumnDefinition
                            {
                                ColumnIdentifier = new Identifier {Value = "srcCnt"},
                                DataType = new WParameterizedDataTypeReference
                                {
                                    Name = new WSchemaObjectName(new Identifier {Value = "int"}),
                                },
                            },
                        },
                        Indexes = new List<WIndexDefinition>(),
                        TableConstraints = new List<WConstraintDefinition>()
                    }
                });

                var tableVar = new WSpecialNamedTableReference
                {
                    TableObjectName = new WSchemaObjectName(new Identifier { Value = "@" + deleteEdgeTempTable + "_1" })
                };
                var reversedTableVar = new WSpecialNamedTableReference
                {
                    TableObjectName = new WSchemaObjectName(new Identifier { Value = "@" + deleteEdgeTempTable + "_2" })
                };
                WInsertSpecification[] insertStat = new WInsertSpecification[]
                {
                    new WInsertSpecification
                    {
                        Target = tableVar,
                        InsertSource = new WSelectInsertSource
                        {
                            Select = edgeSelectQuery
                        }
                    },
                    new WInsertSpecification
                    {
                        Target = reversedTableVar,
                        InsertSource = new WSelectInsertSource
                        {
                            Select = reversedEdgeSelectQuery
                        }
                    }
                };

                // Update statments for edge and reversed edge
                WUpdateSpecification[] updateStat = new WUpdateSpecification[]
                {
                    new WUpdateSpecification
                    {
                        Target = new WNamedTableReference
                        {
                            TableObjectName = sourceNameTable.TableObjectName
                        },
                        SetClauses = new List<WSetClause> {setClauses[0], setClauses[2]},
                        FromClause = new WFromClause
                        {
                            TableReferences = new WTableReference[]
                            {
                                new WQueryDerivedTable
                                {
                                    QueryExpr = new WSelectQueryBlock
                                    {
                                        SelectElements = new List<WSelectElement>()
                                        {
                                            new WSelectStarExpression()
                                        },
                                        FromClause = new WFromClause
                                        {
                                            TableReferences = new List<WTableReference> {tableVar}
                                        }
                                    },
                                    Alias = new Identifier {Value = deleteEdgeTableName},

                                },
                            }
                        },
                        WhereClause = whereClause,
                        TopRowFilter = node.TopRowFilter
                    },
                    new WUpdateSpecification
                    {
                        Target = new WNamedTableReference
                        {
                            TableObjectName = sinkNameTable.TableObjectName
                        },
                        SetClauses = new List<WSetClause> {setClauses[1]},
                        FromClause = new WFromClause
                        {
                            TableReferences = new WTableReference[]
                            {
                                new WQueryDerivedTable
                                {
                                    Alias = new Identifier {Value = deleteEdgeTableName},
                                    QueryExpr = new WSelectQueryBlock
                                    {
                                        SelectElements = new List<WSelectElement>()
                                        {
                                            new WSelectStarExpression()
                                        },
                                        FromClause = new WFromClause
                                        {
                                            TableReferences = new List<WTableReference> {reversedTableVar}
                                        }
                                    }
                                },
                            }
                        },
                        WhereClause = whereClause,
                        TopRowFilter = node.TopRowFilter
                    },

                };
                bool sourceFirst = compare < 0;
                if (sourceFirst)
                {

                    // With expression
                    res.Add(deleteCommonTableExpr);
                    res.Add(insertStat[0]);
                    res.Add(updateStat[0]);
                    res.Add(new WSqlUnknownStatement
                    {
                        Statement = String.Format("DELETE FROM @{0}_1", deleteEdgeTempTable)
                    });

                    // With expression
                    res.Add(deleteCommonTableExpr);
                    res.Add(insertStat[1]);
                    res.Add(updateStat[1]);
                    res.Add(new WSqlUnknownStatement
                    {
                        Statement = String.Format("DELETE FROM @{0}_2", deleteEdgeTempTable)
                    });
                }
                else
                {

                    // With expression
                    res.Add(deleteCommonTableExpr);
                    res.Add(insertStat[1]);
                    res.Add(updateStat[1]);
                    res.Add(new WSqlUnknownStatement
                    {
                        Statement = String.Format("DELETE FROM @{0}_2", deleteEdgeTempTable)
                    });

                    // With expression
                    res.Add(deleteCommonTableExpr);
                    res.Add(insertStat[0]);
                    res.Add(updateStat[0]);
                    res.Add(new WSqlUnknownStatement
                    {
                        Statement = String.Format("DELETE FROM @{0}_1", deleteEdgeTempTable)
                    });
                }

            }

        }
        private List<WSqlStatement> Translate(IList<WSqlStatement> statements)
        {
            var result = new List<WSqlStatement>();
            var index = 0;
            for (var count = statements.Count; index < count; ++index)
            {
                var insertEdgeStatement = statements[index] as WInsertEdgeSpecification;
                if (insertEdgeStatement != null)
                {
                    result.Add(new WBeginTransactionStatement
                    {
                        Name = new WIdentifierOrValueExpression
                        {
                            Identifier = new Identifier { Value = "InsertEdgeTran" }
                        }
                    });
                    
                    //result.Add(TranslateInsertEdge(insertEdgeStatement, false));
                    //result.Add(TranslateInsertEdge(insertEdgeStatement, true));
                    TranslateEdgeInsert(insertEdgeStatement,result);

                    result.Add(new WCommitTransactionStatement
                    {
                        Name = new WIdentifierOrValueExpression
                        {
                            Identifier = new Identifier { Value = "InsertEdgeTran" }
                        }
                    });
                    continue;
                }
                var deleteEdgeStatement = statements[index] as WDeleteEdgeSpecification;
                if (deleteEdgeStatement != null)
                {
                    result.Add(new WBeginTransactionStatement
                    {
                        Name = new WIdentifierOrValueExpression
                        {
                            Identifier = new Identifier { Value = "DeleteEdgeTran" }
                        }
                    });
                    //result.Add(TranslateDeleteEdge(deleteEdgeStatement, true));
                    //result.Add(TranslateDeleteEdge(deleteEdgeStatement, false));

                    TranslateEdgeDelete(deleteEdgeStatement,result);

                    result.Add(new WCommitTransactionStatement
                    {
                        Name = new WIdentifierOrValueExpression
                        {
                            Identifier = new Identifier { Value = "DeleteEdgeTran" }
                        }
                    });
                    continue;
                }
                var deleteNodeStatement = statements[index] as WDeleteNodeSpecification;
                if (deleteNodeStatement != null)
                {
                    var table = deleteNodeStatement.Target as WNamedTableReference;
                    if (table == null)
                        throw new GraphViewException("Target of DELETE NODE statement should be a named table reference.");
                    WBooleanExpression cond = new WBooleanComparisonExpression
                    {
                        ComparisonType = BooleanComparisonType.Equals,
                        FirstExpr = new WColumnReferenceExpression
                        {
                            MultiPartIdentifier = new WMultiPartIdentifier(new Identifier { Value = "InDegree"})
                        },
                        SecondExpr = new WValueExpression
                        {
                            Value = "0"
                        }
                    };
                    var tableSchema = table.TableObjectName.SchemaIdentifier == null
                        ? "dbo"
                        : table.TableObjectName.SchemaIdentifier.Value;
                    var tableName = table.TableObjectName.BaseIdentifier.Value;
                    using (var command = _conn.CreateCommand())
                    {
                        command.CommandText = string.Format(
                            @"SELECT [TableSchema], [TableName], [ColumnName] FROM [{3}] WHERE TableSchema = '{0}' and [TableName]='{1}' and ColumnRole={2}",
                            tableSchema, tableName, 1, GraphViewConnection.MetadataTables[1]);
                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var col = reader["ColumnName"].ToString();
                                cond = WBooleanBinaryExpression.Conjunction(cond, new WBooleanComparisonExpression
                                {
                                    ComparisonType = BooleanComparisonType.Equals,
                                    FirstExpr = new WColumnReferenceExpression
                                    {
                                        MultiPartIdentifier = new WMultiPartIdentifier(new Identifier { Value = col + "OutDegree" })
                                    },
                                    SecondExpr = new WValueExpression
                                    {
                                        Value = "0"
                                    }

                                });
                            }

                        }
                    }
                    WWhereClause checkDeleteNode = new WWhereClause
                    {
                        SearchCondition = new WBooleanNotExpression {Expression = cond}
                    };
                    if (deleteNodeStatement.WhereClause == null ||
                        deleteNodeStatement.WhereClause.SearchCondition == null)
                    {
                        deleteNodeStatement.WhereClause = new WWhereClause {SearchCondition = cond};
                    }
                    else
                    {
                        checkDeleteNode = new WWhereClause
                        {
                            SearchCondition = new WBooleanBinaryExpression
                            {
                                BooleanExpressionType = BooleanBinaryExpressionType.And,
                                FirstExpr = deleteNodeStatement.WhereClause.SearchCondition,
                                SecondExpr = checkDeleteNode.SearchCondition
                            }
                        };
                        deleteNodeStatement.WhereClause = new WWhereClause
                        {
                            SearchCondition = new WBooleanBinaryExpression
                            {
                                BooleanExpressionType = BooleanBinaryExpressionType.And,
                                FirstExpr = deleteNodeStatement.WhereClause.SearchCondition,
                                SecondExpr = cond
                            }
                        };
                    }
                    using (var command = _conn.CreateCommand())
                    {
                        command.CommandText = string.Format("SELECT InDegree FROM {0}.{1} {2}", tableSchema, tableName,
                            checkDeleteNode.ToString());
                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                throw new GraphViewException(
                                    string.Format(
                                        "Node(s) of node table {0} being deleted still has/have ingoing or outdoing edge(s)",
                                        tableName));
                            }
                        }
                    }
                }
                result.Add(statements[index]);
            }
            return result;
        }
Example #12
0
 public virtual void Visit(WWhereClause node)
 {
     node.AcceptChildren(this);
 }
Example #13
0
 public WSelectQueryBlock()
 {
     FromClause  = new WFromClause();
     WhereClause = new WWhereClause();
 }
 public WWhereClause Invoke(WWhereClause node, MatchGraph graph, Dictionary<string, string> columnTableMapping)
 {
     _checkNodeEdgeReferenceVisitor = new CheckNodeEdgeReferenceVisitor(graph, columnTableMapping)
     ;
     if (node.SearchCondition != null)
         node.SearchCondition.Accept(this);
     return _nodeEdgePredicatesWhenClause;
 }
Example #15
0
 public WUpdateSpecification()
 {
     WhereClause = new WWhereClause();
 }
Example #16
0
 public WDeleteSpecification()
 {
     WhereClause = new WWhereClause();
 }
        private void TranslateNodeDelete(WDeleteNodeSpecification node, List<WSqlStatement> res)
        {
            var table = node.Target as WNamedTableReference;
            if (table == null)
                throw new GraphViewException("Target of DELETE NODE statement should be a named table reference.");
            WBooleanExpression cond = new WBooleanComparisonExpression
            {
                ComparisonType = BooleanComparisonType.Equals,
                FirstExpr = new WColumnReferenceExpression
                {
                    MultiPartIdentifier = new WMultiPartIdentifier(new Identifier { Value = "InDegree" })
                },
                SecondExpr = new WValueExpression
                {
                    Value = "0"
                }
            };
            var tableSchema = table.TableObjectName.SchemaIdentifier == null
                ? "dbo"
                : table.TableObjectName.SchemaIdentifier.Value;
            var tableName = table.TableObjectName.BaseIdentifier.Value;
            using (var command = Tx.Connection.CreateCommand())
            {
                command.Transaction = Tx;
                command.CommandText = string.Format(
                    @"SELECT [TableSchema], [TableName], [ColumnName] FROM [{3}] WHERE TableSchema = '{0}' and [TableName]='{1}' and ColumnRole={2}",
                    tableSchema, tableName, 1, GraphViewConnection.MetadataTables[1]);
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var col = reader["ColumnName"].ToString();
                        cond = WBooleanBinaryExpression.Conjunction(cond, new WBooleanComparisonExpression
                        {
                            ComparisonType = BooleanComparisonType.Equals,
                            FirstExpr = new WColumnReferenceExpression
                            {
                                MultiPartIdentifier = new WMultiPartIdentifier(new Identifier { Value = col + "OutDegree" })
                            },
                            SecondExpr = new WValueExpression
                            {
                                Value = "0"
                            }

                        });
                    }

                }
            }
            WWhereClause checkDeleteNode = new WWhereClause
            {
                SearchCondition = new WBooleanNotExpression { Expression = new WBooleanParenthesisExpression { Expression = cond } }
            };
            if (node.WhereClause == null ||
                node.WhereClause.SearchCondition == null)
            {
                node.WhereClause = new WWhereClause { SearchCondition = cond };
            }
            else
            {
                checkDeleteNode = new WWhereClause
                {
                    SearchCondition = new WBooleanBinaryExpression
                    {
                        BooleanExpressionType = BooleanBinaryExpressionType.And,
                        FirstExpr = node.WhereClause.SearchCondition,
                        SecondExpr = checkDeleteNode.SearchCondition
                    }
                };
                node.WhereClause = new WWhereClause
                {
                    SearchCondition = new WBooleanBinaryExpression
                    {
                        BooleanExpressionType = BooleanBinaryExpressionType.And,
                        FirstExpr = node.WhereClause.SearchCondition,
                        SecondExpr = cond
                    }
                };
            }
            using (var command = Tx.Connection.CreateCommand())
            {
                command.Transaction = Tx;
                command.CommandText = string.Format("SELECT InDegree FROM {0}.{1} {2}", tableSchema, tableName,
                    checkDeleteNode.ToString());
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        throw new GraphViewException(
                            string.Format(
                                "Node(s) of node table {0} being deleted still has/have ingoing or outdoing edge(s)",
                                tableName));
                    }
                }
            }

            res.Add(new WDeleteSpecification
            {
                FromClause = node.FromClause,
                Target = node.Target,
                TopRowFilter = node.TopRowFilter,
                WhereClause = node.WhereClause,
            });
        }
 public void UpdateWherClause(WWhereClause whereClause, WBooleanExpression node)
 {
     if (whereClause.SearchCondition == null)
         whereClause.SearchCondition = node;
     else
     {
         whereClause.SearchCondition = new WBooleanBinaryExpression
         {
             FirstExpr = whereClause.SearchCondition,
             SecondExpr = node,
             BooleanExpressionType = BooleanBinaryExpressionType.And
         };
     }
 }
Example #19
0
 public WSelectQueryBlock()
 {
     FromClause = new WFromClause();
     WhereClause = new WWhereClause();
 }