/// <summary> /// Returns a data table containing column metadata of the reader. /// </summary> /// <returns>a DataTable containing column metadata.</returns> public override DataTable GetSchemaTable() { DisposeCheck(); if (tables.Current == null) { return(null); } string projectId = bigQueryCommand.Connection.ProjectId; string dataSetId = bigQueryCommand.Connection.DataSetId; string tableId = tables.Current.TableReference.TableId; DataTable dataTable = new DataTable { TableName = tableId }; dataTable.Columns.Add("ColumnName", typeof(string)); dataTable.Columns.Add("DataType", typeof(Type)); try { Table tableSchema = bigQueryService.Tables.Get(projectId, dataSetId, tableId).Execute(); foreach (var tableFieldSchema in tableSchema.Schema.Fields) { dataTable.Rows.Add(tableFieldSchema.Name, BigQueryTypeConverter.ToType(tableFieldSchema.Type)); } } catch (GoogleApiException e) { throw e.Wrap(); } return(dataTable); }
/// <summary> /// Gets the type of the specified column. /// </summary> /// <param name="ordinal"> The ordinal number of a column.</param> /// <returns>The type of the specified column.</returns> public override Type GetFieldType(int ordinal) { DisposeCheck(); RangeCheck(ordinal); string type = schema.Fields[ordinal].Type; Type fieldType = BigQueryTypeConverter.ToType(type); if(fieldType != null) return fieldType; throw new ArgumentOutOfRangeException(nameof(ordinal), ordinal, "No field with ordinal"); }
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 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)); }
public void StringConvertTest(string stringType, Type systemType, BigQueryDbType bigQueryType) { Assert.Equal(systemType, BigQueryTypeConverter.ToType(stringType)); Assert.Equal(bigQueryType, BigQueryTypeConverter.ToBigQueryDbType(stringType)); }
public void TypeAndDbTypeTest(Type type1, DbType dbType, Type type2) { Assert.Equal(dbType, BigQueryTypeConverter.ToDbType(type1)); Assert.Equal(type2, BigQueryTypeConverter.ToType(dbType)); }
public void TypeAndBigQueryDbTypeTest(Type type1, BigQueryDbType bigQueryType, Type type2) { Assert.Equal(bigQueryType, BigQueryTypeConverter.ToBigQueryDbType(type1)); Assert.Equal(type2, BigQueryTypeConverter.ToType(bigQueryType)); }