public string GetSql()
        {
            var qb = new QueryBuilder(null, null);

            if (ViewType == ViewType.TOP_100)
            {
                qb.TopX = 100;
            }

            var memoryRepository = new MemoryCatalogueRepository();

            qb.AddColumnRange(TableInfo.ColumnInfos.Select(c => new ColumnInfoToIColumn(memoryRepository, c)).ToArray());

            var filter = GetFilterIfAny();

            if (filter != null)
            {
                qb.RootFilterContainer = new SpontaneouslyInventedFilterContainer(memoryRepository, null, new[] { filter }, FilterContainerOperation.AND);
            }

            if (ViewType == ViewType.Aggregate)
            {
                qb.AddCustomLine("count(*),", QueryComponent.QueryTimeColumn);
            }

            var sql = qb.SQL;

            if (ViewType == ViewType.Aggregate)
            {
                throw new NotSupportedException("ViewType.Aggregate can only be applied to ColumnInfos not TableInfos");
            }

            return(sql);
        }
        public string GetSql()
        {
            var qb = new QueryBuilder(null, null, new[] { GetTableInfo() });

            if (ViewType == ViewType.TOP_100)
            {
                qb.TopX = 100;
            }

            if (ViewType == ViewType.Distribution)
            {
                AddDistributionColumns(qb);
            }
            else
            {
                qb.AddColumn(GetIColumn());
            }

            var filter    = GetFilterIfAny();
            var container = GetContainerIfAny();

            if (filter != null && container != null)
            {
                throw new Exception("Cannot generate SQL with both filter and container");
            }

            if (filter != null && !string.IsNullOrWhiteSpace(filter.WhereSQL))
            {
                qb.RootFilterContainer = new SpontaneouslyInventedFilterContainer(new MemoryCatalogueRepository(), null, new[] { filter }, FilterContainerOperation.AND);
            }
            else if (container != null)
            {
                qb.RootFilterContainer = container;
            }

            if (ViewType == ViewType.Aggregate)
            {
                qb.AddCustomLine("count(*) as Count,", QueryComponent.QueryTimeColumn);
            }

            var sql = qb.SQL;

            if (ViewType == ViewType.Aggregate)
            {
                sql += " GROUP BY " + GetColumnSelectSql();
            }

            return(sql);
        }
        public string GetSql()
        {
            var qb = new QueryBuilder(null, null, new [] { ColumnInfo.TableInfo });

            if (ViewType == ViewType.TOP_100)
            {
                qb.TopX = 100;
            }

            if (ViewType == ViewType.Distribution)
            {
                AddDistributionColumns(qb);
            }
            else
            {
                qb.AddColumn(new ColumnInfoToIColumn(new MemoryRepository(), ColumnInfo));
            }

            var filter = GetFilterIfAny();

            if (filter != null && !string.IsNullOrWhiteSpace(filter.WhereSQL))
            {
                qb.RootFilterContainer = new SpontaneouslyInventedFilterContainer(new MemoryCatalogueRepository(), null, new[] { filter }, FilterContainerOperation.AND);
            }

            if (ViewType == ViewType.Aggregate)
            {
                qb.AddCustomLine("count(*),", QueryComponent.QueryTimeColumn);
            }

            var sql = qb.SQL;

            if (ViewType == ViewType.Aggregate)
            {
                sql += " GROUP BY " + ColumnInfo;
            }

            return(sql);
        }