private static SubProduction GetSelectRule() { return(new SubProduction ( new List <ExpressionDefinition> { new TerminalExpressionDefinition { TokenType = TokenType.Select }, new NonTerminalExpressionDefinition { Identifier = ParserConstants.Top }, new NonTerminalExpressionDefinition { Identifier = ParserConstants.SelectColumns }, new TerminalExpressionDefinition { TokenType = TokenType.From }, new NonTerminalExpressionDefinition { Identifier = ParserConstants.Identifier }, new NonTerminalExpressionDefinition { Identifier = ParserConstants.Join }, new NonTerminalExpressionDefinition { Identifier = ParserConstants.Where }, new SemanticActionDefinition((ParsingNode node) => { IdentifierASTNode identifier = node.GetAttributeForKey <IdentifierASTNode>(ParserConstants.Identifier, ParserConstants.SyntaxTreeNode); BooleanExpressionASTNode condition = node.GetAttributeForKey <BooleanExpressionASTNode>(ParserConstants.Where, ParserConstants.SyntaxTreeNode); JoinASTNode join = node.GetAttributeForKey <JoinASTNode>(ParserConstants.Join, ParserConstants.SyntaxTreeNode); TopASTNode top = node.GetAttributeForKey <TopASTNode>(ParserConstants.Top, ParserConstants.SyntaxTreeNode); FromASTNode from = new FromASTNode() { Identifier = identifier }; node.Attributes.Add(ParserConstants.SyntaxTreeNode, new SelectASTNode() { From = from, Condition = condition, Join = join, Top = top, SelectColumns = node.GetAttributeForKey <List <FactorASTNode> >(ParserConstants.SelectColumns, ParserConstants.SyntaxTreeNodes) }); }) } )); }
private bool TryOptimizeIN(SelectASTNode selectASTNode, ReadLogicalElement input, TableDefinition tableDefinition, out CartesianProductElement result) { if (selectASTNode.Condition is RelOpASTNode relOpASTNode && relOpASTNode.RelationOperator == Compiler.Common.RelOp.In) { SelectASTNode innerSelectASTNode = null; IdentifierASTNode outerIdentifierASTNode = null; if (relOpASTNode.Right is SelectASTNode) { innerSelectASTNode = (SelectASTNode)relOpASTNode.Right; if (relOpASTNode.Left is IdentifierASTNode) { outerIdentifierASTNode = (IdentifierASTNode)relOpASTNode.Left; } } if (relOpASTNode.Right is IdentifierASTNode) { outerIdentifierASTNode = (IdentifierASTNode)relOpASTNode.Right; if (relOpASTNode.Left is SelectASTNode) { innerSelectASTNode = (SelectASTNode)relOpASTNode.Left; } } if (innerSelectASTNode != null && outerIdentifierASTNode != null) { result = new CartesianProductElement(input, GetElementForTreeNode(innerSelectASTNode) as ReadLogicalElement, GetColumnFromIdentifierNode(tableDefinition, outerIdentifierASTNode), SelectColumnsToColumns(_relationManager.GetTable(innerSelectASTNode.From.Identifier.Identifier), innerSelectASTNode.SelectColumns).First().AttributeDefinition); return(true); } } result = null; return(false); }
private AttributeDefinition GetColumnFromIdentifierNode(TableDefinition tableDefinition, IdentifierASTNode relopNode) { string column = relopNode.Identifier; return(GetColumnFromJoinString(column.Contains(".") ? GetTableDefinitionFromJoinString(column) : _relationManager.GetTable(tableDefinition.Name).TableDefinition, column)); }