Пример #1
0
        public static void AdjustSchema(Thrift.SchemaElement schema, Type systemType)
        {
            if (IsPrimitiveNullable(systemType))
            {
                throw new ArgumentException($"Type '{systemType}' in column '{schema.Name}' is a nullable type. Please pass either a class or a primitive type.", nameof(systemType));
            }

            TypePrimitive tp = TypePrimitive.Find(systemType);

            schema.Type = tp.ThriftType;

            if (tp.ThriftAnnotation != null)
            {
                schema.Converted_type = tp.ThriftAnnotation.Value;
            }

            //todo: not the best place for it, but it's a special case at the moment
            if (systemType == typeof(decimal))
            {
                schema.Precision = 38;
                schema.Scale     = 18;
            }
        }
Пример #2
0
        public TSchemaElement CreateSchemaElement(string name, Type systemType,
                                                  out Type elementType,
                                                  out string path)
        {
            var th = new TSchemaElement(name);

            if (TypeFactory.TryExtractEnumerableType(systemType, out Type baseType))
            {
                elementType        = baseType;
                path               = BuildRepeatablePath(name);
                th.Repetition_type = Thrift.FieldRepetitionType.REPEATED;
            }
            else if (typeof(Row) == systemType)
            {
                //this is a hierarchy, therefore can be a fake type
                elementType        = typeof(int);
                path               = null;
                th.Repetition_type = Thrift.FieldRepetitionType.OPTIONAL;
            }
            else
            {
                if (TryGetNonNullableType(systemType, out Type nonNullableSystemType))
                {
                    elementType        = nonNullableSystemType;
                    th.Repetition_type = Thrift.FieldRepetitionType.OPTIONAL;
                }
                else if (systemType.GetTypeInfo().IsClass)
                {
                    //reference types are always nullable
                    elementType        = systemType;
                    th.Repetition_type = Thrift.FieldRepetitionType.OPTIONAL;
                }
                else
                {
                    elementType = systemType;
                    //this might be changed later or if column has nulls (on write)
                    th.Repetition_type = Thrift.FieldRepetitionType.REQUIRED;
                }

                path = null;
            }

            //adjust schema

            TypePrimitive tp = TypePrimitive.Find(elementType);

            th.Type = tp.ThriftType;

            if (tp.ThriftAnnotation != null)
            {
                th.Converted_type = tp.ThriftAnnotation.Value;
            }

            //todo: not the best place for it, but it's a special case at the moment
            if (systemType == typeof(decimal))
            {
                th.Precision   = 38;
                th.Scale       = 18;
                th.Type_length = 16; //set to default type length to be used when no elements are added
            }

            return(th);
        }