将BoxedUnit转换为Scala元组

时间:2019-05-21 15:34:18

标签: scala apache-spark

大家好,我在运行spark scala代码时遇到错误。 它说 java.lang.ClassCastException:scala.runtime.BoxedUnit无法转换为scala.Tuple4

在保存步骤中,我尝试投射数据集

        private static Type CreateRaportType(List<PropertieInformation> propertieList, string className)
    {
        AssemblyName assemblyName;
        AssemblyBuilder assemblyBuilder;
        ModuleBuilder module;
        TypeBuilder typeBuilder;
        FieldBuilder field;
        PropertyBuilder property;
        MethodAttributes GetSetAttr;
        MethodBuilder currGetPropMthdBldr;
        MethodBuilder currSetPropMthdBldr;
        ILGenerator currGetIL;
        ILGenerator currSetIL;

        Type caType;
        CustomAttributeBuilder caBuilder;

        List<Object> objList = new List<object>();

        assemblyName = new AssemblyName();
        assemblyName.Name = "ReportAssembly";

        assemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
        module = assemblyBuilder.DefineDynamicModule("ReportModule");

        typeBuilder = module.DefineType(className, TypeAttributes.Public | TypeAttributes.Class, typeof(GeneratedClassBase));

        foreach (PropertieInformation propertieInfo in propertieList)
        {
            field = typeBuilder.DefineField("_" + propertieInfo.PropertieName, propertieInfo.PropertieType, FieldAttributes.Private);

            property = typeBuilder.DefineProperty(propertieInfo.PropertieName, PropertyAttributes.None, propertieInfo.PropertieType, new Type[] { propertieInfo.PropertieType });
            GetSetAttr = MethodAttributes.Public | MethodAttributes.HideBySig;

            currGetPropMthdBldr = typeBuilder.DefineMethod("get_value", GetSetAttr, propertieInfo.PropertieType, Type.EmptyTypes);

            currGetIL = currGetPropMthdBldr.GetILGenerator();
            currGetIL.Emit(OpCodes.Ldarg_0);
            currGetIL.Emit(OpCodes.Ldfld, field);
            currGetIL.Emit(OpCodes.Ret);

            currSetPropMthdBldr = typeBuilder.DefineMethod("set_value", GetSetAttr, null, new Type[] { propertieInfo.PropertieType });

            currSetIL = currSetPropMthdBldr.GetILGenerator();
            currSetIL.Emit(OpCodes.Ldarg_0);
            currSetIL.Emit(OpCodes.Ldarg_1);
            currSetIL.Emit(OpCodes.Stfld, field);
            currSetIL.Emit(OpCodes.Ret);

            // Last, we must map the two methods created above to our PropertyBuilder to
            // their corresponding behaviors, "get" and "set" respectively. 
            property.SetGetMethod(currGetPropMthdBldr);
            property.SetSetMethod(currSetPropMthdBldr);

            caType = typeof(Reportable);
            objList.Clear();
            objList.Add(propertieInfo.MemberToDataBind);
            objList.Add(propertieInfo.ControlToUse);
            objList.Add(propertieInfo.PropertieName);

            objList.Add(propertieInfo.PropertieInnerCollectionType);
            objList.Add(propertieInfo.PropertieInnerCollectionName);
            objList.Add(propertieInfo.DisplayName);
            objList.Add(-1);
            objList.Add(FieldListIcon.UnUsedItem);
            objList.Add(propertieInfo.SystemItemKey);
            objList.Add(null);

            var conInfo = caType.GetConstructor(Type.EmptyTypes);
            var conArgs = new object[] { };
            var caTypeFields = caType.GetFields();

            caBuilder = new CustomAttributeBuilder(conInfo, conArgs, caTypeFields, objList.ToArray());

            property.SetCustomAttribute(caBuilder);

            caType = typeof(DisplayNameAttribute);

            if (propertieInfo.IsList)
                caBuilder = new CustomAttributeBuilder(caType.GetConstructor(new Type[] { typeof(string) }), new string[] { propertieInfo.DisplayName });
            else
                caBuilder = new CustomAttributeBuilder(caType.GetConstructor(new Type[] { typeof(string) }), new string[] { propertieInfo.DisplayName });

            property.SetCustomAttribute(caBuilder);
        }
        return typeBuilder.CreateType();
    }

0 个答案:

没有答案