private static object[] ScalarTest(string name, BigQueryDbType type, object parameterValue, string expectedValue) => new object[] { name, new BigQueryParameter(type, parameterValue), ScalarParameter(type, expectedValue) };
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); }
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); }
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; }
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); }
private static QueryParameter ScalarParameter(BigQueryDbType type, string value) => new QueryParameter { ParameterType = new QueryParameterType { Type = type.ToParameterApiType() }, ParameterValue = new QueryParameterValue { Value = value } };
private static QueryParameter ScalarParameter(BigQueryDbType type, string value) => new QueryParameter { ParameterType = new QueryParameterType { Type = EnumMap.ToApiValue(type) }, ParameterValue = new QueryParameterValue { Value = value } };
public static string ToParameterStringType(BigQueryDbType dbType) { var type = ToStringType(dbType); if (type == "BOOLEAN") { return("BOOL"); } return(type); }
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); }
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); }
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); }
/// <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, }); }
public static Type ToType(BigQueryDbType bqDbType) { return(ToType(ToDbType(bqDbType))); }
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); }
public void DbTypeAndBigQueryDbTypeTest(DbType dbType1, BigQueryDbType bigQueryType, DbType dbType2) { Assert.Equal(bigQueryType, BigQueryTypeConverter.ToBigQueryDbType(dbType1)); Assert.Equal(dbType2, BigQueryTypeConverter.ToDbType(bigQueryType)); }
public void StringConvertTest(string stringType, Type systemType, BigQueryDbType bigQueryType) { Assert.Equal(systemType, BigQueryTypeConverter.ToType(stringType)); Assert.Equal(bigQueryType, BigQueryTypeConverter.ToBigQueryDbType(stringType)); }
/// <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; }
public void TypeAndBigQueryDbTypeTest(Type type1, BigQueryDbType bigQueryType, Type type2) { Assert.Equal(bigQueryType, BigQueryTypeConverter.ToBigQueryDbType(type1)); Assert.Equal(type2, BigQueryTypeConverter.ToType(bigQueryType)); }
public static DbType ToDbType(BigQueryDbType bqDbType) { return(DbTypeToBigQueryDbTypePairs.FindLeftPairFor(bqDbType)); }
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)); }
static string ToStringType(BigQueryDbType dbType) { return(StringToBigQueryDbTypePairs.FindLeftPairFor(dbType)); }
/// <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) { }
internal static string ToParameterApiType(this BigQueryDbType type) => s_typeToNameMapping[type];
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); }