예제 #1
0
        protected void MapWriteJSON(TypeConversionMap map)
        {
            map.Target.DataTypeName = StripNamespace(map.Target.DataType);      // derive type name off actual type.

            switch (map.Target.DataTypeName.ToUpper())
            {
            case "SBYTE":
            case "USHORT":
            case "BYTE":
            case "INT16":
            case "SHORT":
                map.Target.DataTypeName = "Short";
                map.Target.DataType     = typeof(short);
                break;

            case "FLOAT":
            case "SINGLE":
                map.Target.DataTypeName = "Float";
                map.Target.DataType     = typeof(float);
                break;

            case "BYTE[]":
                map.Target.DataTypeName = "String";
                map.Target.DataType     = typeof(string);
                break;

            default:
                break;
            }
        }
예제 #2
0
        protected void MapTargetSqlServer(TypeConversionMap map)
        {
            // If the source is also SQL Server, use original source type information as target.
            if (_source is SourceSqlServer)
            {
                map.Target = map.Source;
            }
            else
            {
                switch (map.Target.DataTypeName.ToUpper())
                {
                // .NET strings convert to NVARCHAR(MAX).
                case "STRING":
                    map.Target.DataTypeName = "NVARCHAR";
                    map.Target.ColumnSize   = -1;
                    break;

                case "BYTE":
                    map.Target.DataTypeName = "TINYINT";
                    break;

                case "SHORT":
                case "INT16":
                    map.Target.DataTypeName = "SMALLINT";
                    break;

                case "INT32":
                    map.Target.DataTypeName = "INT";
                    break;

                case "INT64":
                    map.Target.DataTypeName = "BIGINT";
                    break;

                case "DOUBLE":
                    map.Target.DataTypeName = "DECIMAL";
                    break;

                case "SINGLE":
                    map.Target.DataTypeName = "FLOAT";
                    break;

                case "BOOLEAN":
                    map.Target.DataTypeName = "BIT";
                    break;

                case "BYTE[]":
                    map.Target.DataTypeName = "VARBINARY";
                    break;

                default:
                    break;
                }
            }
        }
예제 #3
0
 protected void Map(TypeConversionMap map, Component component)
 {
     // Use reflection to invoke the concrete component's version of it's mapping logic (if exists).
     if (component != null)
     {
         var componentType = component.GetType();
         var method        = typeof(TypeConverter).GetMethod($"Map{componentType.Name}", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
         if (method != null)
         {
             method.Invoke(this, new[] { map });
         }
     }
 }
예제 #4
0
        protected void MapReadJSON(TypeConversionMap map)
        {
            switch (map.Source.DataTypeName.ToUpper())
            {
            case "DOUBLE":
                map.Target.DataType         = typeof(double);
                map.Target.ColumnSize       = sizeof(double);
                map.Target.NumericPrecision = 38;
                map.Target.NumericScale     = 18;
                break;

            case "STRING":
            case "ARRAYLIST":
                map.Target.DataType = typeof(string);
                break;

            case "INT16":
                map.Target.DataType   = typeof(Int16);
                map.Target.ColumnSize = sizeof(Int16);
                break;

            case "INT32":
                map.Target.DataType   = typeof(Int32);
                map.Target.ColumnSize = sizeof(Int32);
                break;

            case "INT64":
                map.Target.DataType   = typeof(Int64);
                map.Target.ColumnSize = sizeof(Int64);
                break;

            case "DATETIME":
                map.Target.DataType = typeof(DateTime);
                break;

            case "BOOLEAN":
                map.Target.DataType   = typeof(bool);
                map.Target.ColumnSize = sizeof(bool);
                break;

            default:
                break;
            }

            map.Target.DataTypeName = StripNamespace(map.Target.DataType);      // derive type name off actual type.
        }
예제 #5
0
        /// <summary>
        /// Creates a new TypeConversionTable with some general defaults and then apply
        /// source/target specific configurations.
        /// </summary>
        protected void CreateTypeConversionTable()
        {
            TypeConversionTable = new TypeConversionTable();

            // Extract source schema information.
            var schemaTable = _reader.GetSchemaTable();
            int columnIndex = 0;

            foreach (DataRow row in schemaTable.Rows)
            {
                // Default each source column's conversion to the data reader's schema table.
                var map = new TypeConversionMap();
                map.Source.ColumnName       = row["ColumnName"].ToString();
                map.Source.DataType         = Type.GetType(row["DataType"].ToString());
                map.Source.DataTypeName     = row["DataTypeName"].ToString();
                map.Source.ColumnSize       = Cast <int>(row["ColumnSize"]);
                map.Source.NumericPrecision = Cast <Int16>(row["NumericPrecision"]);
                map.Source.NumericScale     = Cast <Int16>(row["NumericScale"]);
                map.Source.AllowNull        = Cast <bool>(row["AllowDBNull"]);
                map.TransportAsBinary       = false;

                // If column names are missing, derive based on index.
                if (map.Source.ColumnName == "")
                {
                    map.Source.ColumnName = $"Column{columnIndex}";
                }

                map.Source.DataTypeName = StripNamespace(map.Source.DataTypeName);

                // Default target to source (special conversion rules for target apply next).
                map.Target = map.Source.Clone();

                // Allow source, formatters, and target to apply their conversion (in that order).
                Map(map, _source);
                Map(map, _readFormatter);
                Map(map, _writeFormatter);
                Map(map, _target);

                TypeConversionTable.Add(map);
                columnIndex++;
            }
        }
예제 #6
0
        protected void MapWriteParquet(TypeConversionMap map)
        {
            // If we're required to transport the data as binary, we need to store it in Parquet as binary as well.
            if (map.TransportAsBinary)
            {
                map.Target.DataType = typeof(byte[]);
            }

            map.Target.DataTypeName = StripNamespace(map.Target.DataType);      // derive type name off actual type.

            switch (map.Target.DataTypeName.ToUpper())
            {
            case "SBYTE":
                map.Target.DataTypeName = "SignedByte";
                map.Target.DataType     = typeof(sbyte);
                break;

            case "USHORT":
                map.Target.DataTypeName = "UnsignedShort";
                map.Target.DataType     = typeof(ushort);
                break;

            case "BYTE":            // Parquet.NET's UnsignedByte throws runtime error, and their Byte is signed, so upconvert to short
            case "INT16":
            case "SHORT":
                map.Target.DataTypeName = "Short";
                map.Target.DataType     = typeof(short);
                break;

            case "FLOAT":
            case "SINGLE":
                map.Target.DataTypeName = "Float";
                map.Target.DataType     = typeof(float);
                break;

            case "BYTE[]":
                map.Target.DataTypeName = "ByteArray";
                map.Target.DataType     = typeof(byte[]);
                break;

            case "TIMESPAN":
                map.Target.DataType     = typeof(DateTimeOffset);
                map.Target.DataTypeName = "DateTimeOffset";
                break;

            default:
                break;
            }

            // Specific type conversions.
            //switch (map.Source.DataTypeName)
            //{
            //    // Parquet defaults to using DateTimeOffset over DateTime.
            //    case "SMALLDATETIME":
            //    case "DATETIME2":
            //    case "DATETIME":
            //        map.Target.DataType = typeof(DateTimeOffset);
            //        map.Target.DataTypeName = "DateTimeOffset";
            //        break;
            //    // Parquest doesn't support GUID, but that's easily converted to a string.
            //    case "UNIQUEIDENTIFIER":
            //    case "GUID":
            //        map.Target.DataType = typeof(string);
            //        map.Target.DataTypeName = "STRING";
            //        break;
            //    case "TIME":
            //        map.Target.DataType = typeof(DateTimeOffset);
            //        map.Target.DataTypeName = "DateTimeOffset";
            //        break;
            //    case "SQL_VARIANT":
            //        map.Target.DataType = typeof(string);
            //        map.Target.DataTypeName = "STRING";
            //        break;
            //    default:
            //        break;
            //}
        }
예제 #7
0
        protected void MapReadParquet(TypeConversionMap map)
        {
            switch (map.Source.DataTypeName.ToUpper())
            {
            case ("DATETIMEOFFSET"):
                map.Target.DataType = typeof(DateTimeOffset);
                break;

            case "DECIMAL":
                map.Target.DataType         = typeof(decimal);
                map.Target.ColumnSize       = 16;
                map.Target.NumericPrecision = 38;
                map.Target.NumericScale     = 18;
                break;

            case "DOUBLE":
                map.Target.DataType         = typeof(double);
                map.Target.ColumnSize       = sizeof(double);
                map.Target.NumericPrecision = 38;
                map.Target.NumericScale     = 18;
                break;

            case "SINGLE":
            case "FLOAT":
                map.Target.DataType   = typeof(float);
                map.Target.ColumnSize = sizeof(float);
                break;

            case "STRING":
                map.Target.DataType = typeof(string);
                break;

            case "UNSIGNEDSHORT":
                map.Target.DataType   = typeof(ushort);
                map.Target.ColumnSize = sizeof(ushort);
                break;

            case "SHORT":
            case "INT16":
                map.Target.DataType   = typeof(Int16);
                map.Target.ColumnSize = sizeof(Int16);
                break;

            case "INT32":
                map.Target.DataType   = typeof(Int32);
                map.Target.ColumnSize = sizeof(Int32);
                break;

            case "INT64":
                map.Target.DataType   = typeof(Int64);
                map.Target.ColumnSize = sizeof(Int64);
                break;

            case "BOOLEAN":
                map.Target.DataType   = typeof(bool);
                map.Target.ColumnSize = sizeof(bool);
                break;

            case "BYTEARRAY":
                map.Target.DataType = typeof(byte[]);
                break;

            default:
                break;
            }

            map.Target.DataTypeName = StripNamespace(map.Target.DataType);      // derive type name off actual type.
        }
예제 #8
0
        protected void MapSourceSqlServer(TypeConversionMap map)
        {
            // If a variable length and the size is "unlimited", force size to -1 which denotes unlimited.
            if ((map.Source.DataTypeName.ToUpper().Contains("CHAR") || map.Source.DataTypeName.ToUpper().Contains("BINARY")) && map.Source.ColumnSize > 8000)
            {
                map.Source.ColumnSize = -1;
                map.Target.ColumnSize = -1;
            }

            switch (map.Source.DataTypeName.ToUpper())
            {
            case "TINYINT":
                map.Target.DataType = typeof(byte);
                break;

            case "SMALLINT":
                map.Target.DataType = typeof(Int16);
                break;

            case "INT":
                map.Target.DataType = typeof(Int32);
                break;

            case "BIGINT":
                map.Target.DataType = typeof(Int64);
                break;

            case "SMALLDATETIME":
            case "DATETIME2":
            case "DATETIME":
                map.Target.DataType = typeof(DateTimeOffset);
                break;

            case "UNIQUEIDENTIFIER":
                map.Target.DataType = typeof(string);
                break;

            case "TIME":
                map.Target.DataType = typeof(TimeSpan);
                break;

            case "SQL_VARIANT":
                map.Target.DataType = typeof(string);
                break;

            case "REAL":
                map.Target.DataType = typeof(double);
                break;

            case "MONEY":
            case "SMALLMONEY":
                map.Target.DataType = typeof(float);
                break;

            case "NUMERIC":
                map.Target.DataType = typeof(double);
                break;

            // SQL Server special types (Geography, Geometry) require special assembly. However, if these are
            // converted to BINARY the assembly isn't required and SQL will convert in target.
            case "GEOGRAPHY":
            case "GEOMETRY":
            case "HIERARCHYID":
                map.Target.DataType   = typeof(byte[]);
                map.TransportAsBinary = true;
                break;
            }

            map.Target.DataTypeName = StripNamespace(map.Target.DataType);      // derive type name off actual type.
        }