コード例 #1
0
 private static object[] ScalarTest(string name, BigQueryDbType type, object parameterValue, string expectedValue) =>
 new object[]
 {
     name,
     new BigQueryParameter(type, parameterValue),
     ScalarParameter(type, expectedValue)
 };
コード例 #2
0
        private static QueryParameter PopulateArrayParameter(QueryParameter parameter, object value, BigQueryDbType?arrayType)
        {
            if (value == null)
            {
                throw new InvalidOperationException("The value of an array parameter cannot be null");
            }
            if (!IsArrayValue(value))
            {
                throw new InvalidOperationException($"Invalid value for array parameter: {value.GetType()}");
            }
            List <object> values = ((IEnumerable)value).Cast <object>().ToList();

            if (values.Any(v => v == null))
            {
                throw new InvalidOperationException("Array parameter values cannot contain null elements");
            }
            BigQueryDbType actualArrayType = arrayType ?? s_typeMapping[GetArrayElementType(value)];

            parameter.ParameterType = new QueryParameterType
            {
                Type      = BigQueryDbType.Array.ToParameterApiType(),
                ArrayType = new QueryParameterType {
                    Type = actualArrayType.ToParameterApiType()
                }
            };
            var parameterValues = values
                                  .Select(p => new BigQueryParameter(actualArrayType, p).ToQueryParameter().ParameterValue)
                                  .ToList();

            parameter.ParameterValue = new QueryParameterValue {
                ArrayValues = parameterValues
            };
            return(parameter);
        }
コード例 #3
0
 public void ChangeDbTypeTest(DbType dbType, BigQueryDbType bigQueryDbType)
 {
     var param = new BigQueryParameter(parameterName, DbType.Single) { Value = intValue };
     Assert.Equal(DbType.Single, param.DbType);
     Assert.Equal(BigQueryDbType.Float, param.BigQueryDbType);
     param.DbType = dbType;
     Assert.Equal(dbType, param.DbType);
     Assert.Equal(bigQueryDbType, param.BigQueryDbType);
 }
コード例 #4
0
        public BigQueryPartitionAttribute(BigQueryDbType type = BigQueryDbType.Date)
        {
            if (type != BigQueryDbType.Date && type != BigQueryDbType.Timestamp)
            {
                throw new InvalidOperationException($"Type can be only {BigQueryDbType.Date} or {BigQueryDbType.Timestamp}");
            }

            Type = type;
        }
コード例 #5
0
        public void TypeInference(string name, object value, BigQueryDbType expectedType)
        {
            var parameter = new BigQueryParameter();

            parameter.Value = value;
            var queryParameter = parameter.ToQueryParameter();
            var actualType     = EnumMap <BigQueryDbType> .ToValue(queryParameter.ParameterType.Type);

            Assert.Equal(expectedType, actualType);
        }
コード例 #6
0
 private static QueryParameter ScalarParameter(BigQueryDbType type, string value) =>
 new QueryParameter
 {
     ParameterType = new QueryParameterType {
         Type = type.ToParameterApiType()
     },
     ParameterValue = new QueryParameterValue {
         Value = value
     }
 };
コード例 #7
0
 private static QueryParameter ScalarParameter(BigQueryDbType type, string value) =>
 new QueryParameter
 {
     ParameterType = new QueryParameterType {
         Type = EnumMap.ToApiValue(type)
     },
     ParameterValue = new QueryParameterValue {
         Value = value
     }
 };
コード例 #8
0
        public static string ToParameterStringType(BigQueryDbType dbType)
        {
            var type = ToStringType(dbType);

            if (type == "BOOLEAN")
            {
                return("BOOL");
            }

            return(type);
        }
コード例 #9
0
        object ChangeValueType(object value, int ordinal) {
            if(value == null)
                return null;

            BigQueryDbType bigQueryType = BigQueryTypeConverter.ToBigQueryDbType(schema.Fields[ordinal].Type);
            if(bigQueryType == BigQueryDbType.Timestamp) {
                return UnixTimeStampToDateTime(value);
            }

            return Convert.ChangeType(value, BigQueryTypeConverter.ToType(schema.Fields[ordinal].Type), CultureInfo.InvariantCulture);
        }
コード例 #10
0
        public void ArrayTypeInference(string name, object value, BigQueryDbType expectedArrayType)
        {
            var parameter = new BigQueryParameter();

            parameter.Value = value;
            var queryParameter = parameter.ToQueryParameter(BigQueryParameterMode.Positional);

            Assert.Equal(BigQueryDbType.Array.ToParameterApiType(), queryParameter.ParameterType.Type);
            var actualArrayType = EnumMap <BigQueryDbType> .ToValue(queryParameter.ParameterType.ArrayType.Type);

            Assert.Equal(expectedArrayType, actualArrayType);
        }
コード例 #11
0
        public void ChangeBigQueryDbTypeTest(BigQueryDbType bigQueryDbType, DbType dbType)
        {
            var param = new BigQueryParameter(parameterName, DbType.Single)
            {
                Value = intValue
            };

            Assert.Equal(DbType.Single, param.DbType);
            Assert.Equal(BigQueryDbType.Float, param.BigQueryDbType);
            param.BigQueryDbType = bigQueryDbType;
            Assert.Equal(bigQueryDbType, param.BigQueryDbType);
            Assert.Equal(dbType, param.DbType);
        }
コード例 #12
0
        /// <summary>
        /// Creates a field with the specified details, and adds it to the schema being built.
        /// </summary>
        /// <param name="name">The name of the field. Must be a valid field name.</param>
        /// <param name="type">The type of the field. Must be a defined member within <see cref="BigQueryDbType"/>, other than <c>Struct</c> or <c>Array</c>.</param>
        /// <param name="mode">The mode of the field. Must be a defined member within <see cref="BigQueryFieldMode"/>.</param>
        /// <param name="description">The description of the field. May be null.</param>
        public void Add(string name, BigQueryDbType type, BigQueryFieldMode mode = BigQueryFieldMode.Nullable, string description = null)
        {
            ValidateFieldName(name, nameof(name));
            GaxPreconditions.CheckArgument(type != BigQueryDbType.Struct, nameof(type),
                                           $"{nameof(BigQueryDbType.Struct)} fields must be specified with their schema");
            GaxPreconditions.CheckArgument(type != BigQueryDbType.Array, nameof(type),
                                           $"{nameof(BigQueryDbType.Array)} fields must be specified with by element type with a {nameof(BigQueryFieldMode)} of {nameof(BigQueryFieldMode.Repeated)}");

            Add(new TableFieldSchema
            {
                Name        = name,
                Type        = EnumMap.ToApiValue(type, nameof(type)),
                Mode        = EnumMap.ToApiValue(mode, nameof(mode)),
                Description = description,
            });
        }
コード例 #13
0
 public static Type ToType(BigQueryDbType bqDbType)
 {
     return(ToType(ToDbType(bqDbType)));
 }
コード例 #14
0
 public void InferDbTypeAndBigQueryDbTypeFromValueTest(object value, DbType exceptedDbType, BigQueryDbType exceptedBQDbType)
 {
     var param = new BigQueryParameter() {Value = value};
     Assert.Equal(value, param.Value);
     Assert.Equal(exceptedDbType, param.DbType);
     Assert.Equal(exceptedBQDbType, param.BigQueryDbType);
 }
コード例 #15
0
 public void DbTypeAndBigQueryDbTypeTest(DbType dbType1, BigQueryDbType bigQueryType, DbType dbType2)
 {
     Assert.Equal(bigQueryType, BigQueryTypeConverter.ToBigQueryDbType(dbType1));
     Assert.Equal(dbType2, BigQueryTypeConverter.ToDbType(bigQueryType));
 }
コード例 #16
0
 public void StringConvertTest(string stringType, Type systemType, BigQueryDbType bigQueryType)
 {
     Assert.Equal(systemType, BigQueryTypeConverter.ToType(stringType));
     Assert.Equal(bigQueryType, BigQueryTypeConverter.ToBigQueryDbType(stringType));
 }
コード例 #17
0
 /// <summary>
 /// Initializes a new instance of the BigQueryParameter class with the specified settings.
 /// </summary>
 /// <param name="parameterName">The name of the parameter.</param>
 /// <param name="bigQueryDbType">A BigQueryDbType enumeration value specifying the data type of the parameter.</param>
 public BigQueryParameter(string parameterName, BigQueryDbType bigQueryDbType)
     : this()
 {
     ParameterName = parameterName;
     BigQueryDbType = bigQueryDbType;
 }
コード例 #18
0
 public void TypeAndBigQueryDbTypeTest(Type type1, BigQueryDbType bigQueryType, Type type2)
 {
     Assert.Equal(bigQueryType, BigQueryTypeConverter.ToBigQueryDbType(type1));
     Assert.Equal(type2, BigQueryTypeConverter.ToType(bigQueryType));
 }
コード例 #19
0
 public static DbType ToDbType(BigQueryDbType bqDbType)
 {
     return(DbTypeToBigQueryDbTypePairs.FindLeftPairFor(bqDbType));
 }
コード例 #20
0
 public void TypeAndBigQueryDbTypeTest(Type type1, BigQueryDbType bigQueryType, Type type2)
 {
     Assert.Equal(bigQueryType, BigQueryTypeConverter.ToBigQueryDbType(type1));
     Assert.Equal(type2, BigQueryTypeConverter.ToType(bigQueryType));
 }
コード例 #21
0
 public void TimesTest(string bigQueryTypeName, Type systemType, BigQueryDbType bigQueryDbType, DbType dbType)
 {
     Assert.Equal(systemType, BigQueryTypeConverter.ToType(bigQueryTypeName));
     Assert.Equal(bigQueryDbType, BigQueryTypeConverter.ToBigQueryDbType(bigQueryTypeName));
     Assert.Equal(dbType, BigQueryTypeConverter.ToDbType(bigQueryDbType));
 }
コード例 #22
0
 public void StringConvertTest(string stringType, Type systemType, BigQueryDbType bigQueryType)
 {
     Assert.Equal(systemType, BigQueryTypeConverter.ToType(stringType));
     Assert.Equal(bigQueryType, BigQueryTypeConverter.ToBigQueryDbType(stringType));
 }
コード例 #23
0
 static string ToStringType(BigQueryDbType dbType)
 {
     return(StringToBigQueryDbTypePairs.FindLeftPairFor(dbType));
 }
コード例 #24
0
 /// <summary>
 /// Initializes a new instance of the BigQueryParameter class with the specified settings.
 /// </summary>
 /// <param name="parameterName">The name of the parameter.</param>
 /// <param name="bigQueryDbType">A BigQueryDbType enumeration value specifying the data type of the parameter.</param>
 public BigQueryParameter(string parameterName, BigQueryDbType bigQueryDbType) : this()
 {
     ParameterName  = parameterName;
     BigQueryDbType = bigQueryDbType;
 }
コード例 #25
0
 /// <summary>
 /// Constructs a parameter with no name, initial value or type.
 /// </summary>
 /// <param name="type">The initial type of the parameter.</param>
 public BigQueryParameter(BigQueryDbType type) : this(null, type, null)
 {
 }
コード例 #26
0
 public void DbTypeAndBigQueryDbTypeTest(DbType dbType1, BigQueryDbType bigQueryType, DbType dbType2)
 {
     Assert.Equal(bigQueryType, BigQueryTypeConverter.ToBigQueryDbType(dbType1));
     Assert.Equal(dbType2, BigQueryTypeConverter.ToDbType(bigQueryType));
 }
コード例 #27
0
ファイル: BigQueryDbType.cs プロジェクト: greggaba/GCDotNet
 internal static string ToParameterApiType(this BigQueryDbType type) => s_typeToNameMapping[type];
コード例 #28
0
        public void InferDbTypeAndBigQueryDbTypeFromValueTest(object value, DbType exceptedDbType, BigQueryDbType exceptedBQDbType)
        {
            var param = new BigQueryParameter()
            {
                Value = value
            };

            Assert.Equal(value, param.Value);
            Assert.Equal(exceptedDbType, param.DbType);
            Assert.Equal(exceptedBQDbType, param.BigQueryDbType);
        }