Example #1
0
        private static Delegate DeserializeUdfs <T>(
            UdfWrapperData data,
            ref int nodeIndex,
            ref int udfIndex)
        {
            UdfWrapperNode node     = data.UdfWrapperNodes[nodeIndex++];
            Type           nodeType = Type.GetType(node.TypeName);

            if (node.HasUdf)
            {
                var udfs = new object[node.NumChildren];
                for (int i = 0; i < node.NumChildren; ++i)
                {
                    udfs[i] = UdfSerDe.Deserialize(data.Udfs[udfIndex++]);
                }

                return(CreateUdfWrapperDelegate <T>(nodeType, udfs));
            }

            var udfWrappers = new object[node.NumChildren];

            for (int i = 0; i < node.NumChildren; ++i)
            {
                udfWrappers[i] = DeserializeUdfs <T>(data, ref nodeIndex, ref udfIndex);
            }

            return(CreateUdfWrapperDelegate <T>(nodeType, udfWrappers));
        }
Example #2
0
        private static void SerializeUdfs(
            Delegate func,
            UdfWrapperNode parent,
            List <UdfWrapperNode> udfWrapperNodes,
            List <UdfSerDe.UdfData> udfs)
        {
            UdfSerDe.UdfData udfData = UdfSerDe.Serialize(func);
            if ((udfData.MethodName != UdfWrapperMethodName) ||
                !Attribute.IsDefined(func.Target.GetType(), typeof(UdfWrapperAttribute)))
            {
                // Found the actual UDF.
                if (parent != null)
                {
                    parent.HasUdf = true;
                    Debug.Assert(parent.NumChildren == 1);
                }

                udfs.Add(udfData);
                return;
            }

            UdfSerDe.FieldData[] fields = udfData.TargetData.Fields;
            if ((fields.Length == 0) || (fields.Length > 2))
            {
                throw new Exception(
                          $"Invalid number of children ({fields.Length}) for {udfData.TypeData.Name}");
            }

            var curNode = new UdfWrapperNode
            {
                TypeName    = udfData.TypeData.Name,
                NumChildren = fields.Length,
                HasUdf      = false
            };

            udfWrapperNodes.Add(curNode);

            foreach (UdfSerDe.FieldData field in fields)
            {
                SerializeUdfs((Delegate)field.Value, curNode, udfWrapperNodes, udfs);
            }
        }