public void RewriteTables(ISqlElement element)
        {
            var rewrittenTables = new Dictionary <IColumnSource, IColumnSource>();

            TableDeclarationVisitor.Visit(element, original =>
            {
                var rewritten = RewriteTableIfNeeded(original);
                if (rewritten != original)
                {
                    rewrittenTables.Add(original, rewritten);
                }
                return(rewritten);
            });
            new ColumnReferenceVisitor(column =>
            {
                IColumnSource generatedTable;
                if (rewrittenTables.TryGetValue(column.Table, out generatedTable))
                {
                    column.Table = generatedTable;
                }
                return(column);
            }).Visit(element);
        }
        public static void Visit(ISqlElement element, Func <TableDeclarationClause, ISqlElement> visit)
        {
            var visitor = new TableDeclarationVisitor(visit);

            visitor.Visit(element);
        }