public static QsiTableNode VisitSelectStatement(SelectStatement statement) { var tableNode = new PDerivedTableNode(); var columnsNode = new QsiColumnsDeclarationNode(); tableNode.Hints = statement.Hint?.Hints; RepeatedField <AliasedNode> selects = statement.Select; if (statement.IsUnion && selects.Select(s => s.Node.Unwrap()).TryCast(out IEnumerable <ColumnParseNode> columns)) { columnsNode.Columns.AddRange(CreateSequentialColumns(columns)); } else { columnsNode.Columns.AddRange(selects.Select(VisitAliasedNode)); } tableNode.Columns.SetValue(columnsNode); if (statement.IsUnion) { tableNode.Source.SetValue(VisitSelectStatements(statement.Selects)); } else if (statement.From != null) { tableNode.Source.SetValue(VisitTableNode(statement.From)); } if (statement.Where != null) { tableNode.Where.SetValue(ExpressionVisitor.VisitWhere(statement.Where)); } if (statement.Limit != null || statement.Offset != null) { tableNode.Limit.SetValue(ExpressionVisitor.VisitLimitOffset(statement.Limit, statement.Offset)); } if (statement.OrderBy.Any()) { tableNode.Order.SetValue(ExpressionVisitor.VisitOrderBy(statement.OrderBy)); } // statement.GroupBy // statement.Having PTree.RawNode[tableNode] = statement; return(tableNode); }
public static IQsiTreeNode VisitCreateViewStatement(CreateTableStatement node) { QsiDerivedTableNode derivedTableNode; if (node.ColumnDefs.Any()) { derivedTableNode = TreeHelper.Create <PDynamicDerivedTableNode>(n => { n.DynamicColumns = new QsiColumnsDeclarationNode(); n.DynamicColumns.Columns.AddRange(node.ColumnDefs.Select(VisitDynamicColumn)); }); } else { derivedTableNode = new PDerivedTableNode(); } derivedTableNode.Alias.SetValue(new QsiAliasNode { Name = IdentifierVisitor.Visit(node.TableName)[^ 1]