コード例 #1
0
ファイル: Profiler.cs プロジェクト: modulexcite/DataProfiler
        private static Row GetBuilder(Result result, string aggregate, bool distinct) {
            var processName = "Dp" + result.Name[0].ToString(CultureInfo.InvariantCulture).ToUpper() + result.Name.Substring(1);
            var builder = new ProcessBuilder(processName)
                .Star(aggregate)
                .StarEnabled(false)
                .Connection("input")
                    .Provider("internal")
                .Connection("output")
                    .Provider("internal")
                .Entity(aggregate)
                    .DetectChanges(false)
                    .InputOperation(new RowsOperation(result.Rows))
                    .Group()
                    .Field("group")
                        .Input(false)
                        .Default("group")
                        .Aggregate("group")
                        .PrimaryKey();

            foreach (var field in result.Fields) {
                builder
                    .Field(field.Name)
                    .Length(field.Length)
                    .Type(field.Type)
                    .Aggregate(aggregate)
                    .Distinct(distinct);
            }

            return ProcessFactory.CreateSingle(builder.Process()).Execute().First();
        }
コード例 #2
0
        public Result Import(string resource, decimal sample = 100m) {

            AbstractConnection input;
            bool noLock;

            ConnectionModifier modifier;

            try {
                var userDefined = ProcessFactory.CreateSingle("DataProfiler", new Options() { Mode = "metadata"});
                input = userDefined.Connections["input"];
                modifier = new ConnectionModifier(resource);
                modifier.Modify(ref input);

                var hasEntity = userDefined.Entities.Any();

                sample = sample > 0m && sample < 100m ?
                    sample :
                    hasEntity ? userDefined.Entities[0].Sample : 100m;

                noLock = !hasEntity || userDefined.Entities[0].NoLock;
                TflLogger.Info(userDefined.Name, modifier.Name, "Sample: {0:###} percent, NoLock: {1}", sample, noLock);
            } catch {
                throw new DataProfilerException("You must define a DataProfiler process with an 'input' connection in the transformalize configuration section.");
            }

            var cleanName = Regex.Replace(modifier.Name, "[^a-zA-Z]", string.Empty);

            var builder = new ProcessBuilder("Dp" + cleanName[0].ToString(CultureInfo.InvariantCulture).ToUpper() + cleanName.Substring(1))
                .Connection("input")
                    .Provider(input.Type)
                    .Server(input.Server)
                    .Database(input.Database)
                    .User(input.User)
                    .Password(input.Password)
                    .Port(input.Port)
                    .ConnectionString(input.GetConnectionString())
                .Connection("output")
                    .Provider("internal")
                .Entity(modifier.Name)
                    .DetectChanges(false)
                    .NoLock(noLock)
                    .Sample(sample)
                    .Schema(modifier.Schema);

            var process = ProcessFactory.CreateSingle(builder.Process());

            var result = new Result {
                Name = modifier.Name,
                Fields = process.Entities[0].Fields,
                Rows = process.Execute(),
                Provider = input.Type.ToString()
            };
            result.Properties["server"] = input.Server;
            result.Properties["database"] = input.Database;
            result.Properties["schema"] = modifier.Schema;
            result.Properties["table"] = modifier.Name;
            result.Properties["port"] = input.Port.ToString(CultureInfo.InvariantCulture);

            return result;
        }
コード例 #3
0
        public void Export(Dictionary<string, Row> profile, string file = null) {
            Process userDefined;
            AbstractConnection output;
            var input = new RowsOperation(profile.Select(kv => kv.Value));
            string provider = null;

            try {
                userDefined = ProcessFactory.CreateSingle("DataProfiler", new Options() { Mode = "metadata" });
                output = userDefined.Connections["output"];
            } catch {
                throw new DataProfilerException("You must define a DataProfiler process with an 'output' connection in the transformalize configuration section.");
            }

            // user may override output provider by changing file extension (e.g. .html, .csv, .txt)
            if (file != null) {
                var key = new FileInfo(file).Extension.Replace(".", string.Empty).ToLower();
                provider = _autoProvider.ContainsKey(key) ? _autoProvider[key] : _autoProvider["*"];
            }

            var builder = new ProcessBuilder("DataProfiler")
                .Connection("input")
                    .Provider("internal")
                .Connection("output")
                    .ConnectionString(output.GetConnectionString())
                    .Database(output.Database)
                    .DateFormat(output.DateFormat)
                    .Delimiter(output.Delimiter)
                    .ErrorMode(output.ErrorMode)
                    .File(file ?? output.File)
                    .Folder(output.Folder)
                    .Footer(output.Footer)
                    .Header(output.Header)
                    .Password(output.Password)
                    .Port(output.Port)
                    .Provider(provider ?? output.Type.ToString())
                    .SearchOption(output.SearchOption)
                    .SearchPattern(output.SearchPattern)
                    .Server(output.Server)
                    .Start(output.Start)
                    .User(output.User);

            foreach (var action in userDefined.Actions) {
                builder.Action(action.Action)
                    .After(action.After)
                    .Before(action.Before)
                    .Connection(action.Connection.Name)
                    .File(action.File)
                    .From(action.From)
                    .To(action.To)
                    .Url(action.Url)
                    .Command(action.Command)
                    .Body(action.Body)
                    .Cc(action.Cc)
                    .Modes(action.Modes.ToArray());
            }

            builder.Entity("ProfileExporter")
                .InputOperation(input)
                .Field("field").Label("Field").Length(128).PrimaryKey()
                .Field("type").Label("Type")
                .Field("index").Label("Index").Int32()
                .Field("count").Label("Distinct Count").Int64()
                .Field("min").Label("Min Value").Length(33)
                    .Transform("elipse").Length(30)
                .Field("max").Label("Max Value").Length(33)
                    .Transform("elipse").Length(30)
                .Field("minlength").Label("Min Length").Int64()
                .Field("maxlength").Label("Max Length").Int64();

            ProcessFactory.CreateSingle(builder.Process()).ExecuteScaler();
        }
コード例 #4
0
 public TflProcess Process()
 {
     return(_processBuilder.Process());
 }