public void LinkParentTable(TableDataBuilder parent)
        {
            if (Parent != null)
            {
                throw new InvalidOperationException("A parent table builder is already linked");
            }


            var asKey = Schema.Keys.Any();

            Parent = parent;
            _parentReferences.Clear();
            foreach (var pk in Parent.Schema.Keys)
            {
                _parentReferences.Add(new Field
                {
                    FieldType = asKey ? FieldType.Key : FieldType.Dimension,
                    Name      = pk.Value.Name,
                    ValueType = pk.Value.ValueType
                }, pk.Index);
            }
            _fieldList.AddRange(_parentReferences.Keys);

            Schema.Associate(parent.Schema, _parentReferences.Keys, Parent.Schema.Keys.Select(fp => fp.Value), false);

            UpdateSchema();
        }
Exemplo n.º 2
0
        public override void InitializeRelatedTables(DataProcessor processor, TableDataBuilder table)
        {
            if (!InlineFields)
            {
                var tables = processor.TableMap.Tables;
                var current = tables.FirstOrDefault(t => t.Name == TableName) as TableDataBuilder;

                if (current != null)
                {
                    if (!current.Schema.FieldsAreEqual(LookupTableBuilder.Schema) || current.GetType() != LookupTableBuilder.GetType())
                    {
                        throw new InvalidOperationException("Lookup tables with the same name must have the same schema and type to be shared");
                    }
                    LookupTableBuilder.Schema.ClearRelations();
                    LookupTableBuilder = current;
                }
                else
                {
                    //Insert dimension tables in the start, since it is referenced by other tables
                    tables.Insert(0, LookupTableBuilder);
                }

                table.Schema.Associate(LookupTableBuilder.Schema,
                    table.Schema.Fields.Where(f => Fields.Contains(f)).ToArray(),
                    LookupTableBuilder.Schema.Keys.Select(fp => fp.Value), true);
            }

            //Initialize realted tables in field mappers
            foreach (var fm in FieldMappers)
            {
                fm.InitializeRelatedTables(processor, InlineFields ? table : LookupTableBuilder);
            }

            base.InitializeRelatedTables(processor, table);
        }
 public void Initialize(DataProcessor processor, TableDataBuilder parentTable)
 {
     foreach (var mapper in TableMappers)
     {
         mapper.Initialize(processor, parentTable);
     }
 }
 public override void InitializeRelatedTables(DataProcessor processor, TableDataBuilder table)
 {
     foreach (var fm in FieldMappers.SelectMany(fms => fms))
     {
         fm.InitializeRelatedTables(processor, table);
     }
 }
Exemplo n.º 5
0
            public object GetValue(TableDataBuilder builder, Indexed <Field> field, object[] row)
            {
                var fields = _scope._uniqueChildFields
                             .GetOrAdd(builder, () => new Dictionary <object[], bool[]>(builder.RowMap.Comparer))
                             .GetOrAdd(row, () => new bool[row.Length]);


                var firstTimeInScope = !fields[field.Index];

                fields[field.Index] = true;
                return(firstTimeInScope ? _value : null);
            }
Exemplo n.º 6
0
        protected override IEnumerable<Field> CreateFields()
        {
            _iterator = new FieldMapperIterator(FieldMappers);

            if (!InlineFields)
            {
                LookupTableBuilder = CreateLookupBuilder();
                if (LookupTableBuilder.Schema.Keys.Length == 0)
                {
                    LookupTableBuilder.AddHashKey(HashKeyFactory);
                }
            }

            return GetFields(InlineFields ? FieldTarget.Inline : FieldTarget.KeyReference).ToArray(); 
        }
        public virtual void Initialize(DataProcessor processor, TableDataBuilder parentTable)
        {
            Builders = new List<BuilderInfo>();
            foreach (var def in TableDefinitions)
            {
                var fieldMappers = def.FieldMappers.ToArray();
                foreach (var mapper in fieldMappers)
                {
                    mapper.Initialize(processor);
                }


                var builder = fieldMappers.Length == 0
                    ? null
                    : new TableDataBuilder(def.Name, fieldMappers);                

                var builderInfo = new BuilderInfo(builder);

                if( builder != null )                
                {
                    if (parentTable != null)
                    {
                        builder.LinkParentTable(parentTable);
                    }

                    builder.EnsureKey(KeyFactory.Default);

                    processor.TableMap.Tables.Add(builderInfo.Builder);
                }

                foreach (var fieldMapper in fieldMappers)
                {
                    fieldMapper.InitializeRelatedTables(processor, builderInfo.Builder);
                }

                if (def.TableMappers != null)
                {
                    foreach (var childTable in def.TableMappers)
                    {
                        builderInfo.Children.Add(childTable);
                        childTable.Initialize(processor, builder ?? parentTable);
                    }
                }

                Builders.Add(builderInfo);
            }
        }
Exemplo n.º 8
0
        public void TestTableDataBuilderFieldOrder()
        {
            var fields = new[]
            {
                new Field {FieldType = FieldType.Key, ValueType = typeof(int), Name = "0"},
                new Field {FieldType = FieldType.Fact,  ValueType = typeof(int), Name = "1"},
                new Field {FieldType = FieldType.Dimension, ValueType = typeof(int), Name = "2"},
                new Field {FieldType = FieldType.Label, ValueType = typeof(int), Name = "3"},
                new Field {FieldType = FieldType.Key,  ValueType = typeof(int),Name = "4"},
                new Field {FieldType = FieldType.Fact,  ValueType = typeof(int),Name = "5"},
                new Field {FieldType = FieldType.Dimension, ValueType = typeof(int), Name = "6"}
            };

            var builder = new TableDataBuilder("Test", fields.Select(f => new StaticFieldMapper(f, 0)));

            Assert.IsTrue(
                builder.Schema.Fields.SequenceEqual(new[] { fields[0], fields[4], fields[2], fields[3], fields[6], fields[1], fields[5] }));
        }
 public void InitializeRelatedTables(DataProcessor processor, TableDataBuilder table)
 {            
 }
Exemplo n.º 10
0
        public void TestTableDataBuilderDefaultValues()
        {
            var fields = new[]
            {
                new Field {FieldType = FieldType.Key, ValueType = typeof(int), Name = "0"},
                new Field {FieldType = FieldType.Key,  ValueType = typeof(int?), Name = "1"},
                new Field {FieldType = FieldType.Key, ValueType = typeof(string), Name = "2"},
                new Field {FieldType = FieldType.Key, ValueType = typeof(DateTime), Name = "3"},
                new Field {FieldType = FieldType.Key,  ValueType = typeof(DateTime?),Name = "4"},                
            };

            var builder = new TableDataBuilder("Test", fields.Select(f => new StaticFieldMapper(f, 0)));
            var row = builder.CreateEmptyRow();

            Assert.IsTrue(
                row.SequenceEqual(new object[] {0, null, null, default(DateTime), null}));
        }
        public void LinkParentTable(TableDataBuilder parent)
        {
            if( Parent != null) throw new InvalidOperationException("A parent table builder is already linked");


            var asKey = Schema.Keys.Any();

            Parent = parent;            
            _parentReferences.Clear();
            foreach (var pk in Parent.Schema.Keys)
            {
                _parentReferences.Add(new Field
                {
                    FieldType = asKey ? FieldType.Key : FieldType.Dimension,
                    Name = pk.Value.Name,
                    ValueType = pk.Value.ValueType
                }, pk.Index);
            }
            _fieldList.AddRange(_parentReferences.Keys);

            Schema.Associate(parent.Schema, _parentReferences.Keys, Parent.Schema.Keys.Select(fp=>fp.Value), false);

            UpdateSchema();                                    
        }
Exemplo n.º 12
0
 public BuilderInfo(TableDataBuilder builder)
 {
     Builder = builder;
     Children = new List<ITableMapper>();
 }