コード例 #1
0
ファイル: Property.cs プロジェクト: mohdimran068/big-querier
        public static void AppendRecordFieldSchema(TableSchemaBuilder tableBuilder, string name, Type type)
        {
            var simpleFieldOptions = Value.MaybeSimpleFieldOptionsFromType(type);

            if (simpleFieldOptions != null)
            {
                tableBuilder.Add(name, simpleFieldOptions.type, simpleFieldOptions.mode);
                return;
            }

            if (type.IsArray)
            {
                var elementType = type.GetElementType();
                var simpleArrayElementFieldOptions = Value.MaybeSimpleFieldOptionsFromType(elementType);
                if (null != simpleArrayElementFieldOptions)
                {
                    tableBuilder.Add(name, simpleArrayElementFieldOptions.type, BigQueryFieldMode.Repeated);
                    return;
                }

                if (Record.IsContractType(elementType))
                {
                    tableBuilder.Add(name, Record.GetSchema(elementType), BigQueryFieldMode.Repeated);
                    return;
                }
            }

            if (Record.IsContractType(type))
            {
                tableBuilder.Add(name, Record.GetSchema(type), BigQueryFieldMode.Nullable);
                return;
            }

            throw new NotImplementedException($"Type {type.FullName} is not a valid BigQuerier Contract field");
        }
コード例 #2
0
        public static TableSchemaBuilder GetSchemaBuilder(Type schemaType, string indent = "")
        {
            var schemaBuilder = new TableSchemaBuilder();

            foreach (var propertyItem in schemaType.GetProperties())
            {
                if (IgnoreProperty(propertyItem.GetCustomAttribute <BigQuerySchemaAttribute>()))
                {
                    continue;
                }

                if (IsEnumerable(propertyItem.PropertyType))
                {
                    var elementType = GetElementsType(propertyItem);

                    if (IsClass(elementType))
                    {
                        WritePropertyMessage(propertyItem, indent, "IEnumerableClass");
                        var propertySchemaBuilder = GetSchemaBuilder(propertyItem.PropertyType.GetGenericArguments().FirstOrDefault(), indent.Insert(0, _spaces));
                        schemaBuilder.Add(NewTableFieldSchema(propertyItem.Name, "RECORD", BigQueryFieldMode.Repeated.ToString(), propertySchemaBuilder.Build()));
                    }
                    else
                    {
                        WritePropertyMessage(propertyItem, indent, "IEnumerableType");
                        schemaBuilder.Add(NewTableFieldSchema(propertyItem.Name, elementType.ToBigQueryDbType(), BigQueryFieldMode.Repeated.ToString()));
                    }
                }
                else if (IsClass(propertyItem.PropertyType))
                {
                    WritePropertyMessage(propertyItem, indent, "Class");
                    var propertySchemaBuilder = GetSchemaBuilder(propertyItem.PropertyType, indent.Insert(0, _spaces));
                    schemaBuilder.Add(NewTableFieldSchema(propertyItem.Name, "RECORD", BigQueryFieldMode.Nullable.ToString(), propertySchemaBuilder.Build()));
                }
                else
                {
                    WritePropertyMessage(propertyItem, indent, "Type");
                    schemaBuilder.Add(NewTableFieldSchema(propertyItem.Name, propertyItem.PropertyType.ToBigQueryDbType(), BigQueryFieldMode.Nullable.ToString()));
                }
            }
            return(schemaBuilder);
        }
コード例 #3
0
        public static TableSchema BuildSchema <T>()
        {
            var publicProps = typeof(T).GetProperties();

            var builder = new TableSchemaBuilder();

            foreach (var property in publicProps)
            {
                if (property.GetCustomAttribute <BigQueryIgnoreAttribute>() != null)
                {
                    continue;
                }

                builder.Add(SnakeCaseConverter.ConvertToSnakeCase(property.Name), new DataInfoFactory().Get(property).DbType);
            }

            return(builder.Build());
        }
コード例 #4
0
        // Creates a new empty table in Google BigQuery
        public void CreateBigQueryTable(string projectName, string dataSetName, string tableName)
        {
            if (_DataTypeMap == null)
            {
                throw new Exception("DataTypeMap can not be null. Call UploadTableToStorage() or MapColumnTypes() method first");
            }

            BigqueryClient client = BigqueryClient.Create(projectName, _GoogleAPICredential);

            // Build the schema with Google's schema object and our DataTypeMap
            TableSchemaBuilder sBuilder = new TableSchemaBuilder();

            for (int i = 0; i < _DataTypeMap.Keys.Count; i++)
            {
                sBuilder.Add(_DataTypeMap[i].ColumnName, _DataTypeMap[i].BQColumnType);
            }

            // Create the dataset if it doesn't exist.
            BigqueryDataset dataset = client.GetOrCreateDataset(dataSetName);
            BigqueryTable   table   = dataset.GetOrCreateTable(tableName, sBuilder.Build());
        }
コード例 #5
0
        public void Add_InvalidName()
        {
            var builder = new TableSchemaBuilder();

            Assert.Throws <ArgumentException>(() => builder.Add("123", BigQueryDbType.Int64));
        }