示例#1
0
        public ConvertTransform(IHostEnvironment env, Arguments args, IDataView input)
            : base(env, RegistrationName, env.CheckRef(args, nameof(args)).Column,
                   input, null)
        {
            Host.AssertNonEmpty(Infos);
            Host.Assert(Infos.Length == Utils.Size(args.Column));

            _exes = new ColInfoEx[Infos.Length];
            for (int i = 0; i < _exes.Length; i++)
            {
                DataKind kind;
                KeyRange range;
                var      col = args.Column[i];
                if (col.ResultType != null)
                {
                    kind  = col.ResultType.Value;
                    range = !string.IsNullOrEmpty(col.Range) ? KeyRange.Parse(col.Range) : col.KeyRange;
                }
                else if (col.KeyRange != null || !string.IsNullOrEmpty(col.Range))
                {
                    kind  = Infos[i].TypeSrc.IsKey ? Infos[i].TypeSrc.RawKind : DataKind.U4;
                    range = col.KeyRange ?? KeyRange.Parse(col.Range);
                }
                else if (args.ResultType != null)
                {
                    kind  = args.ResultType.Value;
                    range = !string.IsNullOrEmpty(args.Range) ? KeyRange.Parse(args.Range) : args.KeyRange;
                }
                else if (args.KeyRange != null || !string.IsNullOrEmpty(args.Range))
                {
                    kind  = Infos[i].TypeSrc.IsKey ? Infos[i].TypeSrc.RawKind : DataKind.U4;
                    range = args.KeyRange ?? KeyRange.Parse(args.Range);
                }
                else
                {
                    kind  = DataKind.Num;
                    range = null;
                }
                Host.CheckUserArg(Enum.IsDefined(typeof(DataKind), kind), nameof(args.ResultType));

                PrimitiveType itemType;
                if (!TryCreateEx(Host, Infos[i], kind, range, out itemType, out _exes[i]))
                {
                    throw Host.ExceptUserArg(nameof(args.Column),
                                             "source column '{0}' with item type '{1}' is not compatible with destination type '{2}'",
                                             input.Schema.GetColumnName(Infos[i].Source), Infos[i].TypeSrc.ItemType, itemType);
                }
            }
            SetMetadata();
        }