示例#1
0
        public void GetFieldMode_Null()
        {
            var field = new TableFieldSchema {
                Mode = null
            };

            Assert.Equal(BigQueryFieldMode.Nullable, field.GetFieldMode());
        }
示例#2
0
        public void GetFieldMode()
        {
            var field = new TableFieldSchema {
                Mode = "REPEATED"
            };

            Assert.Equal(BigQueryFieldMode.Repeated, field.GetFieldMode());
        }
        private static object ConvertSingleValue(object rawValue, TableFieldSchema field)
        {
            if (rawValue == null)
            {
                return(null);
            }
            var type = field.GetFieldType();

            if (field.GetFieldMode() == FieldMode.Repeated)
            {
                JArray array = (JArray)rawValue;
                switch (type)
                {
                case BigqueryDbType.String:
                    return(ConvertArray(array, StringConverter));

                case BigqueryDbType.Integer:
                    return(ConvertArray(array, Int64Converter));

                case BigqueryDbType.Float:
                    return(ConvertArray(array, DoubleConverter));

                case BigqueryDbType.Bytes:
                    return(ConvertArray(array, BytesConverter));

                case BigqueryDbType.Boolean:
                    return(ConvertArray(array, BooleanConverter));

                case BigqueryDbType.Timestamp:
                    return(ConvertArray(array, DateTimeConverter));

                case BigqueryDbType.Record:
                    return(ConvertRecordArray(array, field));

                default:
                    throw new InvalidOperationException($"Unhandled field type {type} {rawValue.GetType()}");
                }
            }
            switch (type)
            {
            case BigqueryDbType.String:
                return(StringConverter((string)rawValue));

            case BigqueryDbType.Integer:
                return(Int64Converter((string)rawValue));

            case BigqueryDbType.Float:
                return(DoubleConverter((string)rawValue));

            case BigqueryDbType.Bytes:
                return(BytesConverter((string)rawValue));

            case BigqueryDbType.Boolean:
                return(BooleanConverter((string)rawValue));

            case BigqueryDbType.Timestamp:
                return(DateTimeConverter((string)rawValue));

            case BigqueryDbType.Record:
                return(ConvertRecord((JObject)rawValue, field));

            default:
                throw new InvalidOperationException($"Unhandled field type {type} {rawValue.GetType()}");
            }
        }
        private static object ConvertSingleValue(object rawValue, TableFieldSchema field)
        {
            if (rawValue == null || (rawValue as JToken)?.Type == JTokenType.Null)
            {
                return(null);
            }
            var type = field.GetFieldType();

            if (field.GetFieldMode() == BigQueryFieldMode.Repeated)
            {
                JArray array = (JArray)rawValue;
                switch (type)
                {
                case BigQueryDbType.String:
                    return(ConvertArray(array, StringConverter));

                case BigQueryDbType.Int64:
                    return(ConvertArray(array, Int64Converter));

                case BigQueryDbType.Float64:
                    return(ConvertArray(array, DoubleConverter));

                case BigQueryDbType.Bytes:
                    return(ConvertArray(array, BytesConverter));

                case BigQueryDbType.Bool:
                    return(ConvertArray(array, BooleanConverter));

                case BigQueryDbType.Timestamp:
                    return(ConvertArray(array, TimestampConverter));

                case BigQueryDbType.Date:
                    return(ConvertArray(array, DateConverter));

                case BigQueryDbType.Time:
                    return(ConvertArray(array, TimeConverter));

                case BigQueryDbType.DateTime:
                    return(ConvertArray(array, DateTimeConverter));

                case BigQueryDbType.Struct:
                    return(ConvertRecordArray(array, field));

                case BigQueryDbType.Numeric:
                    return(ConvertArray(array, NumericConverter));

                case BigQueryDbType.Geography:
                    return(ConvertArray(array, GeographyConverter));

                default:
                    throw new InvalidOperationException($"Unhandled field type {type} {rawValue.GetType()}");
                }
            }
            switch (type)
            {
            case BigQueryDbType.String:
                return(StringConverter((string)rawValue));

            case BigQueryDbType.Int64:
                return(Int64Converter((string)rawValue));

            case BigQueryDbType.Float64:
                return(DoubleConverter((string)rawValue));

            case BigQueryDbType.Bytes:
                return(BytesConverter((string)rawValue));

            case BigQueryDbType.Bool:
                return(BooleanConverter((string)rawValue));

            case BigQueryDbType.Timestamp:
                return(TimestampConverter((string)rawValue));

            case BigQueryDbType.Date:
                return(DateConverter((string)rawValue));

            case BigQueryDbType.Time:
                return(TimeConverter((string)rawValue));

            case BigQueryDbType.DateTime:
                return(DateTimeConverter((string)rawValue));

            case BigQueryDbType.Numeric:
                return(NumericConverter((string)rawValue));

            case BigQueryDbType.Geography:
                return(GeographyConverter((string)rawValue));

            case BigQueryDbType.Struct:
                return(ConvertRecord((JObject)rawValue, field));

            default:
                throw new InvalidOperationException($"Unhandled field type {type} (Underlying type: {rawValue.GetType()})");
            }
        }