Пример #1
0
 public bool StartsWith(DcColumn col)
 {
     if (Size == 0)
     {
         return(false);
     }
     return(Segments[0] == col);
 }
Пример #2
0
 public ColumnTree(DcColumn col, ColumnTree parent = null)
 {
     Column   = col;
     Children = new List <ColumnTree>();
     if (parent != null)
     {
         parent.AddChild(this);
     }
 }
Пример #3
0
        public virtual void FromJson(JObject json, DcSpace ws)
        {
            // List of schemas
            foreach (JObject schema in json["schemas"])
            {
                DcSchema sch = (DcSchema)Utils.CreateObjectFromJson(schema);
                if (sch != null)
                {
                    sch.FromJson(schema, this);
                    _schemas.Add(sch);
                }
            }

            // List of tables
            foreach (JObject table in json["tables"])
            {
                DcTable tab = (DcTable)Utils.CreateObjectFromJson(table);
                if (tab != null)
                {
                    tab.FromJson(table, this);
                    _tables.Add(tab);
                }
            }

            // Load all columns from all schema (now all tables are present)
            foreach (JObject schema in json["schemas"])
            {
                foreach (JObject column in schema["columns"]) // List of columns
                {
                    DcColumn col = (DcColumn)Utils.CreateObjectFromJson(column);
                    if (col != null)
                    {
                        col.FromJson(column, this);
                        _columns.Add(col);
                    }
                }
            }

            // Second pass on all columns with the purpose to load their definitions (now all columns are present)
            foreach (JObject schema in json["schemas"])
            {
                foreach (JObject column in schema["columns"]) // List of columns
                {
                    DcColumn col = (DcColumn)Utils.CreateObjectFromJson(column);
                    if (col != null)
                    {
                        col.FromJson(column, this);

                        // Find the same existing column (possibly without a definition)
                        DcColumn existing = col.Input.GetColumn(col.Name);

                        // Copy the definition
                        existing.FromJson(column, this);
                    }
                }
            }
        }
Пример #4
0
        public ColumnMappingEntry(DcColumn sourceColumn)
        {
            Source = sourceColumn;

            IsMatched = false;
            IsKey     = sourceColumn.IsKey;

            TargetTypes = new ObservableCollection <DcTable>();
        }
Пример #5
0
        public string Value(string dimName)
        {
            DcColumn dim = GridView.Set.GetColumn(dimName);

            if (dim == null)
            {
                return(null);
            }
            return((string)dim.GetData().GetValue(Offset));
        }
Пример #6
0
        public void ProjectionTest() // Defining new tables via function projection and populate them
        {
            CreateSampleData(schema);

            DcTable t2 = schema.GetSubTable("Table 2");

            DcColumn c21 = t2.GetColumn("Column 21");
            DcColumn c22 = t2.GetColumn("Column 22");
            DcColumn c23 = t2.GetColumn("Column 23");

            //
            // Project "Table 2" along "Column 21" and get 2 unique records in a new set "Value A" (3 references) and "Value B" (1 reference)
            //
            DcTable t3 = space.CreateTable(DcSchemaKind.Dc, "Table 3", schema.Root);

            DcColumn c31 = space.CreateColumn(c21.Name, t3, c21.Output, true);

            // Create a generating column
            DcColumn c24 = space.CreateColumn("Project", t2, t3, false);

            c24.GetData().Formula      = "(( [String] [Column 21] = [Column 21] ))";
            c24.GetData().IsAppendData = true;

            t3.GetData().Populate();

            Assert.AreEqual(2, t3.GetData().Length);

            Assert.AreEqual(0, c24.GetData().GetValue(0));
            Assert.AreEqual(0, c24.GetData().GetValue(1));
            Assert.AreEqual(0, c24.GetData().GetValue(2));
            Assert.AreEqual(1, c24.GetData().GetValue(3));

            //
            // Defining a combination of "Column 21" and "Column 22" and project with 3 unique records in a new set
            //
            DcTable t4 = space.CreateTable(DcSchemaKind.Dc, "Table 4", schema.Root);

            DcColumn c41 = space.CreateColumn(c21.Name, t4, c21.Output, true);
            DcColumn c42 = space.CreateColumn(c22.Name, t4, c22.Output, true);

            DcColumn c25 = space.CreateColumn("Project", t2, t4, false);

            c25.GetData().Formula      = "(( [String] [Column 21] = [Column 21], [Integer] [Column 22] = [Column 22] ))";
            c25.GetData().IsAppendData = true;

            t4.GetData().Populate();

            Assert.AreEqual(3, t4.GetData().Length);

            Assert.AreEqual(0, c25.GetData().GetValue(0));
            Assert.AreEqual(1, c25.GetData().GetValue(1));
            Assert.AreEqual(1, c25.GetData().GetValue(2));
            Assert.AreEqual(2, c25.GetData().GetValue(3));
        }
Пример #7
0
        public string this[int index] // It returns values that are shown in grid columns
        {
            get
            {
                object cell = Offset;

                if (GridView.ShowPaths) // Use stored paths
                {
                    ColumnPath path = GridView.Paths[index];
                    int        ofs;
                    for (int i = 0; i < path.Segments.Count; i++)
                    {
                        ofs = (int)cell; // Use output as an input for the next iteration

                        if (path.Segments[i].GetData().IsNull(ofs))
                        {
                            cell = null;
                            break; // Cannot continue with next segments
                        }
                        else
                        {
                            cell = path.Segments[i].GetData().GetValue(ofs);
                        }
                    }
                }
                else // Use greater dimensions
                {
                    int dimCount = GridView.Set.Columns.Count;
                    if (index < 0 || index >= dimCount)
                    {
                        return(null);
                    }
                    DcColumn dim = GridView.Set.Columns[index];

                    if (dim.GetData().IsNull(Offset))
                    {
                        cell = null;
                    }
                    else
                    {
                        cell = dim.GetData().GetValue(Offset);
                    }
                }

                if (cell == null)
                {
                    return("");
                }
                else
                {
                    return(Convert.ToString(cell));
                }
            }
        }
Пример #8
0
        /* TODO: Notify after adding
         * public virtual void Add()
         * {
         *  if (IsSuper) // Only one super-dim per table can exist
         *  {
         *      if (Input != null && Input.SuperColumn != null)
         *      {
         *          Input.SuperColumn.Remove(); // Replace the existing column by the new one
         *      }
         *  }
         *
         *  if (Output != null) Output.InputColumns.Add(this);
         *  if (Input != null) Input.Columns.Add(this);
         *
         *  // Notify that a new child has been added
         *  if (Input != null) ((Table)Input).NotifyAdd(this);
         *  if (Output != null) ((Table)Output).NotifyAdd(this);
         * }
         */
        public virtual void DeleteColumn(DcColumn column)
        {
            Debug.Assert(!column.Input.IsPrimitive, "Wrong use: top columns cannot be created/deleted.");
            // TODO: Check constraints: deleting a super-column means deleting the corresponding table (with all its columns)

            //DeleteColumnPropagate(column);

            _columns.Remove(column);

            NotifyRemove(column);
        }
Пример #9
0
 private void AddLastSegment(DcColumn segment)
 {
     if (!isInverse)
     {
         InsertLast(segment);
     }
     else
     {
         InsertFirst(segment);
     }
 }
Пример #10
0
        /// <summary>
        /// Expand one attribute by building its path segments as dimension objects.
        /// Use the provided list of attributes for expansion recursively. This list essentially represents a schema.
        /// Also, adjust path names in special cases like empty name or simple structure.
        /// </summary>
        public void ExpandAttribute(List <ColumnAtt> attributes, List <DcColumn> columns) // Add and resolve attributes by creating dimension structure from FKs
        {
            ColumnAtt att = this;

            if (att.Segments.Count > 0)
            {
                return;                         // Already expanded (because of recursion)
            }
            bool isKey = !string.IsNullOrEmpty(att.RelationalPkName) || att.IsKey;

            if (string.IsNullOrEmpty(att.RelationalFkName)) // No FK - primitive column - end of recursion
            {
                // Find or create a primitive dim segment
                DcColumn seg = columns.FirstOrDefault(c => c.Input == att.Input && StringSimilarity.SameColumnName(((ColumnRel)c).RelationalFkName, att.RelationalFkName));
                if (seg == null)
                {
                    seg = new ColumnRel(att.RelationalColumnName, att.Input, att.Output, isKey, false); // Maybe copy constructor?
                    ((ColumnRel)seg).RelationalFkName = att.RelationalFkName;
                    columns.Add(seg);
                }

                att.InsertLast(seg); // add it to this attribute as a single segment
            }
            else
            { // There is FK - non-primitive column
                // Find target set and target attribute (name resolution)
                ColumnAtt tailAtt = attributes.FirstOrDefault(a => StringSimilarity.SameTableName(a.Input.Name, att.RelationalTargetTableName) && StringSimilarity.SameColumnName(a.Name, att.RelationalTargetColumnName));
                DcTable   gTab    = tailAtt.Input;

                // Find or create a dim segment
                DcColumn seg = columns.FirstOrDefault(c => c.Input == att.Input && StringSimilarity.SameColumnName(((ColumnRel)c).RelationalFkName, att.RelationalFkName));
                if (seg == null)
                {
                    seg = new ColumnRel(att.RelationalFkName, att.Input, gTab, isKey, false);
                    ((ColumnRel)seg).RelationalFkName = att.RelationalFkName;
                    columns.Add(seg);
                }

                att.InsertLast(seg); // add it to this attribute as first segment

                //
                // Recursion. Expand tail attribute and add all segments from the tail attribute (continuation)
                //
                tailAtt.ExpandAttribute(attributes, columns);
                att.InsertLast(tailAtt);

                // Adjust name. How many attributes belong to the same FK as this attribute (FK composition)
                List <ColumnAtt> fkAtts = attributes.Where(a => a.Input == att.Input && StringSimilarity.SameColumnName(att.RelationalFkName, a.RelationalFkName)).ToList();
                if (fkAtts.Count == 1)
                {
                    seg.Name = att.RelationalColumnName; // Adjust name. For 1-column FK, name of the FK-dim is the column name (not the FK name)
                }
            }
        }
Пример #11
0
        public void InsertLast(DcColumn col) // Append a new segment to the end of the path
        {
            Debug.Assert(Size == 0 || col.Input == Output, "A new segment appended to a path must continue the previous segments");

            Segments.Add(col);
            Output = col.Output;
            if (Input == null)
            {
                Input = col.Input;
            }
        }
Пример #12
0
        public void InsertFirst(DcColumn col) // Insert a new segment at the beginning of the path
        {
            Debug.Assert(Size == 0 || col.Output == Input, "A path must continue the first segment inserted in the beginning.");

            Segments.Insert(0, col);
            Input = col.Input;
            if (Output == null)
            {
                Output = col.Output;
            }
        }
Пример #13
0
 public bool IsInMashups(DcColumn dim) // Determine if the specified dimension belongs to some mashup
 {
     if (dim == null || MashupTop == null)
     {
         return(false);
     }
     if (IsInMashups(dim.Input) && IsInMashups(dim.Output))
     {
         return(true);
     }
     return(false);
 }
Пример #14
0
        public override bool MoveNext()
        {
            // TODO: We need also loop over all source tables

            // It is a traverse algorithm. We move either one step forward or one step back on each iteration of the loop.
            // Various conditions are checked after we arrive at a new child (forward) or before we leave a node and go to the parent.
            // The algorithm returns if either a good node is found (true) or no nodes exist anymore (false).
            while (true)
            {
                var nextSegs = GetNextValidSegments();
                int childNo  = childNumber[Size];

                if (childNo + 1 < nextSegs.Count) // Can move to the next child
                {
                    childNumber[Size] = childNo + 1;
                    AddLastSegment(nextSegs[childNo + 1]);

                    // Process a new node
                    isValidTab[Size] = TargetTableValid();
                    // Coverage. We are interested only in longest paths. If we need to return all (even shorter) paths then remove this block.
                    if (isValidTab[Size])
                    {
                        for (int i = 0; i < Size; i++)
                        {
                            isValidTab[i] = false;
                        }
                    }

                    // Process the child node just added on the next iteration.
                }
                else // No children anymore - return to the previous parent
                {
                    // Before leaving this node, we are able to decide whether it is what we have been looking for because all its children have been processed
                    // If it is what we need then return true
                    if (isValidTab[Size])
                    {
                        isValidTab[Size] = false; // During next call, we have to skip this block
                        return(true);
                    }

                    if (Size == 0)     // Detect finish condition
                    {
                        return(false); // All nodes have been visited - no nodes anymore
                    }

                    // Really leave this node
                    childNumber[Size] = -1;
                    DcColumn column = RemoveLastSegment();

                    // Process the parent node we have just returned to on the next iteration.
                }
            }
        }
Пример #15
0
        public ColumnPath(DcColumn seg)
            : this()
        {
            if (seg == null)
            {
                return;
            }

            Segments.Add(seg);
            Input  = Segments[0].Input;
            Output = Segments[Segments.Count - 1].Output;
        }
Пример #16
0
        public void AggregationTest() // Defining new aggregated columns and evaluate them
        {
            CreateSampleData(schema);

            DcTable t1 = schema.GetSubTable("Table 1");

            DcTable t2 = schema.GetSubTable("Table 2");

            DcColumn c23 = t2.GetColumn("Column 23");
            DcColumn c24 = t2.GetColumn("Table 1");

            //
            // Define aggregated column
            //

            /* We do not use non-syntactic (object) formulas
             * DcColumn c15 = schema.CreateColumn("Agg of Column 23", t1, schema.GetPrimitive("Double"), false);
             * c15.Definition.DefinitionType = DcColumnDefinitionType.AGGREGATION;
             *
             * c15.Definition.FactTable = t2; // Fact table
             * c15.Definition.GroupPaths = new List<DimPath>(new DimPath[] { new DimPath(c24) }); // One group path
             * c15.Definition.MeasurePaths = new List<DimPath>(new DimPath[] { new DimPath(c23) }); // One measure path
             * c15.Definition.Updater = "SUM"; // Aggregation function
             *
             * c15.Add();
             *
             * //
             * // Evaluate expression
             * //
             * c15.Data.SetValue(0.0);
             * c15.Definition.Evaluate(); // {40, 140, 0}
             *
             * Assert.AreEqual(40.0, c15.Data.GetValue(0));
             * Assert.AreEqual(140.0, c15.Data.GetValue(1));
             * Assert.AreEqual(0.0, c15.Data.GetValue(2)); // In fact, it has to be NaN or null (no values have been aggregated)
             */

            //
            // Aggregation via a syntactic formula
            //
            DcColumn c16 = space.CreateColumn("Agg2 of Column 23", t1, schema.GetPrimitiveType("Double"), false);

            c16.GetData().Formula = "AGGREGATE(facts=[Table 2], groups=[Table 1], measure=[Column 23]*2.0 + 1, aggregator=SUM)";

            c16.GetData().SetValue(0.0);
            c16.GetData().Translate();
            c16.GetData().Evaluate(); // {40, 140, 0}

            Assert.AreEqual(81.0, c16.GetData().GetValue(0));
            Assert.AreEqual(283.0, c16.GetData().GetValue(1));
            Assert.AreEqual(0.0, c16.GetData().GetValue(2));
        }
Пример #17
0
        public void Rebuild(DcColumn column)
        {
            // Assume that the specified column has changed (name, formula etc.)
            // The column has been translated (not necessarily successfully)
            // We need to update dependencies by removing old and adding new

            // If formula has been changed then it can appear, disapper, or updated
            // We need to retrieve used columns by removing the old columns

            // If name has been changed then its own deps do not change.
            // However, all columns which use it, have to be re-translated (and will be red which will be propagated)

            // If type has been changed then we need to re-translate
        }
Пример #18
0
        protected void ColumnRenamed(string newName)
        {
            DcSpace  space  = this.Input.Space;
            DcSchema schema = this.Input.Schema;
            DcColumn column = this;

            //
            // Check all elements of the schema that can store column name (tables, columns etc.)
            // Update their definition so that it uses the new name of the specified element
            //
            List <DcTable> tables = space.GetTables(schema); // schema.AllSubTables;
            var            nodes  = new List <ExprNode>();

            foreach (var tab in tables)
            {
                if (tab.IsPrimitive)
                {
                    continue;
                }

                foreach (var col in tab.Columns)
                {
                    if (col.GetData() == null)
                    {
                        continue;
                    }
                    DcColumnData data = col.GetData();

                    /* REFACTOR: Here essentially we want to manually find all uses and hence have to use dependencies API
                     * if (data.FormulaExpr != null)
                     * {
                     *  nodes = data.FormulaExpr.Find((DcColumn)column);
                     *  nodes.ForEach(x => x.Name = newName);
                     * }
                     */
                }

                // Update table definitions by finding the uses of the specified column
                if (tab.GetData().WhereExpr != null)
                {
                    nodes = tab.GetData().WhereExpr.Find((DcColumn)column);
                    nodes.ForEach(x => x.Name = newName);
                }
            }

            column.Name = newName;
        }
Пример #19
0
        public void CsvReadTest() // Load Csv schema and data as a result of evaluation
        {
            DcSpace space = new Space();

            // Create schema for a remote db
            SchemaCsv top = (SchemaCsv)space.CreateSchema("My Files", DcSchemaKind.Csv);

            // Create a remote file description
            TableCsv table = (TableCsv)space.CreateTable(DcSchemaKind.Csv, "Products", top.Root);

            table.FilePath = CsvRead;
            var columns = top.LoadSchema(table);

            Assert.AreEqual(1, top.Root.SubTables.Count);
            Assert.AreEqual(15, top.GetSubTable("Products").Columns.Count);

            Assert.AreEqual("String", top.GetSubTable("Products").GetColumn("Product Name").Output.Name);
            Assert.AreEqual("3", ((ColumnCsv)top.GetSubTable("Products").GetColumn("ID")).SampleValues[1]);

            //
            // Configure import
            //
            DcSchema schema = space.CreateSchema("My Schema", DcSchemaKind.Dc);

            DcTable productsTable = space.CreateTable(DcSchemaKind.Dc, "Products", schema.Root);

            // Manually create column to be imported (we need an automatic mechanism for appending missing columns specified in the formula)
            DcColumn p1 = space.CreateColumn("ID", productsTable, schema.GetPrimitiveType("Integer"), true);
            DcColumn p2 = space.CreateColumn("Product Code", productsTable, schema.GetPrimitiveType("String"), false);
            DcColumn p3 = space.CreateColumn("Custom Product Name", productsTable, schema.GetPrimitiveType("String"), false);
            DcColumn p4 = space.CreateColumn("List Price", productsTable, schema.GetPrimitiveType("Double"), false);
            DcColumn p5 = space.CreateColumn("Constant Column", productsTable, schema.GetPrimitiveType("Double"), false);

            // Define import column
            DcColumn col = space.CreateColumn("Import", top.GetSubTable("Products"), productsTable, false);

            col.GetData().IsAppendData   = true;
            col.GetData().Formula        = "(( [Integer] [ID] = this.[ID], [String] [Product Code] = [Product Code], [String] [Custom Product Name] = [Product Name], [Double] [List Price] = [List Price], [Double] [Constant Column] = 20.02 ))"; // Tuple structure corresponds to output table
            col.GetData().IsAppendData   = true;
            col.GetData().IsAppendSchema = true;

            productsTable.GetData().Populate();

            Assert.AreEqual(45, productsTable.GetData().Length);
            Assert.AreEqual("Northwind Traders Dried Pears", p3.GetData().GetValue(5));
            Assert.AreEqual(20.02, p5.GetData().GetValue(5));
        }
Пример #20
0
        public DcColumn RemoveLastAt(int index) // TODO: Implement an additional argument with the number of segments to remove
        {
            DcColumn result = RemoveAt(index);

            if (result == null)
            {
                return(result);
            }

            if (Segments.Count == 0) // This where removal of the first and the last segments is different
            {
                Input  = result.Input;
                Output = result.Input;
            }

            return(result);
        }
Пример #21
0
        public void ColumnDataTest() // DcColumnData. Manually read/write data
        {
            DcTable t1 = schema.GetSubTable("Table 1");

            DcColumn c11 = t1.GetColumn("Column 11");
            DcColumn c12 = t1.GetColumn("Column 12");
            DcColumn c13 = t1.GetColumn("Column 13");

            DcTable  t2  = schema.GetSubTable("Table 2");
            DcColumn c21 = t2.GetColumn("Column 21");
            DcColumn c22 = t2.GetColumn("Column 22");

            //
            // Data
            //

            t1.GetData().Length = 3;

            // 2. Write/read individual column data by using column data methods (not table methods)

            Assert.AreEqual(true, c11.GetData().IsNull(1)); // Initially, all outputs must be null
            c11.GetData().SetValue(1, 10);
            c11.GetData().SetValue(0, 20);
            c11.GetData().SetValue(2, 30);
            Assert.AreEqual(false, c11.GetData().IsNull(1));
            Assert.AreEqual(10, c11.GetData().GetValue(1));

            Assert.AreEqual(true, c13.GetData().IsNull(2)); // Initially, all outputs must be null
            c13.GetData().SetValue(1, 10.0);
            c13.GetData().SetValue(0, 20.0);
            c13.GetData().SetValue(2, 30.0);
            Assert.AreEqual(false, c13.GetData().IsNull(1));
            Assert.AreEqual(10.0, c13.GetData().GetValue(1));

            t2.GetData().Length = 2;

            c21.GetData().SetValue(0, "Value A");
            c21.GetData().SetValue(1, "Value B");

            c22.GetData().SetValue(0, 10);
            c22.GetData().SetValue(1, 20);

            Assert.AreEqual(10, c22.GetData().GetValue(0));
            Assert.AreEqual(20, c22.GetData().GetValue(1));
        }
Пример #22
0
        private DcColumn RemoveLastSegment()
        {
            if (Size == 0)
            {
                return(null);           // Nothing to remove
            }
            DcColumn segment = null;

            if (!isInverse)
            {
                segment = RemoveLast();
            }
            else
            {
                segment = RemoveFirst();
            }
            return(segment);
        }
Пример #23
0
 public ColumnNode(DcColumn col, ColumnNode parent = null)
 {
     Column = col;
     if (parent != null)
     {
         parent.AddChild(this);
     }
     if (Column != null)
     {
         if (Column.Input != null)
         {
             ((Space)Column.Input.Space).CollectionChanged += Input_CollectionChanged;
         }
         if (Column.Output != null)
         {
             ((Space)Column.Output.Space).CollectionChanged += Output_CollectionChanged;
         }
     }
 }
Пример #24
0
        //
        // Change the graph
        //

        // Add columns the specified column depends on
        // The specified columns uses these columns either in its formula or is influenced by them
        // Existing dependencies are not removed but duplicates are not added
        public void AddUsed(DcColumn column, List <DcColumn> usedColumns)
        {
            List <Tuple <DcColumn, DcColumn> > colDeps = dependencies.Where(d => d.Item1 == column).ToList();

            // Add each individual dependency
            foreach (DcColumn col in usedColumns)
            {
                // Check if it is already there
                if (colDeps.Exists(d => d.Item2 == col))
                {
                    continue;
                }

                // If not then add it
                dependencies.Add(new Tuple <DcColumn, DcColumn>(column, col));

                // Add also to the temporary list so that we can check for duplicates
                colDeps.Add(new Tuple <DcColumn, DcColumn>(column, col));
            }
        }
Пример #25
0
        public static void CreateSampleSchema(DcSchema schema)
        {
            DcSpace space = schema.Space;

            // Table 1
            DcTable t1 = space.CreateTable(DcSchemaKind.Dc, "Table 1", schema.Root);

            DcColumn c11 = space.CreateColumn("Column 11", t1, schema.GetPrimitiveType("Integer"), true);
            DcColumn c12 = space.CreateColumn("Column 12", t1, schema.GetPrimitiveType("String"), true);
            DcColumn c13 = space.CreateColumn("Column 13", t1, schema.GetPrimitiveType("Double"), false);
            DcColumn c14 = space.CreateColumn("Column 14", t1, schema.GetPrimitiveType("Decimal"), false);

            // Table 2
            DcTable t2 = space.CreateTable(DcSchemaKind.Dc, "Table 2", schema.Root);

            DcColumn c21 = space.CreateColumn("Column 21", t2, schema.GetPrimitiveType("String"), true);
            DcColumn c22 = space.CreateColumn("Column 22", t2, schema.GetPrimitiveType("Integer"), true);
            DcColumn c23 = space.CreateColumn("Column 23", t2, schema.GetPrimitiveType("Double"), false);
            DcColumn c24 = space.CreateColumn("Table 1", t2, t1, false);
        }
Пример #26
0
        public void CsvWriteTest() // Store schema and data to a CSV file as a result of evaluation
        {
            DcSpace  space  = new Space();
            DcSchema schema = space.CreateSchema("My Schema", DcSchemaKind.Dc);

            CoreTest.CreateSampleSchema(schema);

            CoreTest.CreateSampleData(schema);

            DcTable t2 = schema.GetSubTable("Table 2");

            DcColumn c21 = t2.GetColumn("Column 21");
            DcColumn c22 = t2.GetColumn("Column 22");
            DcColumn c23 = t2.GetColumn("Column 23");

            //
            // Create schema for a remote db
            //
            SchemaCsv top = (SchemaCsv)space.CreateSchema("My Files", DcSchemaKind.Csv);

            // Create a remote file description
            TableCsv table = (TableCsv)space.CreateTable(DcSchemaKind.Csv, "Table_1", top.Root);

            table.FilePath = CsvWrite;

            // Manually create column to be imported (we need an automatic mechanism for appending missing columns specified in the formula)
            DcColumn p1 = space.CreateColumn("Column 11", table, top.GetPrimitiveType("String"), true);
            DcColumn p2 = space.CreateColumn("Column 12", table, top.GetPrimitiveType("String"), true);
            DcColumn p3 = space.CreateColumn("Custom Column 13", table, top.GetPrimitiveType("String"), true);
            DcColumn p4 = space.CreateColumn("Constant Column", table, top.GetPrimitiveType("String"), true);

            // Define export column
            DcColumn col = space.CreateColumn("Export", schema.GetSubTable("Table 1"), table, false);

            col.GetData().IsAppendData   = true;
            col.GetData().Formula        = "(( [String] [Column 11] = this.[Column 11], [String] [Column 12] = [Column 12], [String] [Custom Column 13] = [Column 13], [String] [Constant Column] = 20.02 ))"; // Tuple structure corresponds to output table
            col.GetData().IsAppendData   = true;
            col.GetData().IsAppendSchema = true;

            table.Populate();
        }
Пример #27
0
        public void CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            MainWindow vm = ((MainWindow)DataContext);

            if (e.Action == NotifyCollectionChangedAction.Add) // Decide if this node has to add a new child node
            {
                DcColumn column = e.NewItems != null && e.NewItems.Count > 0 && e.NewItems[0] is DcColumn ? (DcColumn)e.NewItems[0] : null;
                if (column == null)
                {
                    return;
                }
                if (column.Input != vm.SelectedTable)
                {
                    return;
                }
                if (vm.ColumnList.Contains(column))
                {
                    return;
                }

                vm.ColumnList.Add(column);
            }
            else if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                DcColumn column = e.OldItems != null && e.OldItems.Count > 0 && e.OldItems[0] is DcColumn ? (DcColumn)e.OldItems[0] : null;
                if (column == null)
                {
                    return;
                }
                if (column.Input != vm.SelectedTable)
                {
                    return;
                }
                if (!vm.ColumnList.Contains(column))
                {
                    return;
                }

                vm.ColumnList.Remove(column);
            }
        }
Пример #28
0
        private void OkCommand_Executed(object state)
        {
            // Save name
            if (string.IsNullOrWhiteSpace(TableName))
            {
                return;
            }

            Table.Name = TableName;

            // Save table
            if (IsNew)
            {
                //Schema.AddTable(Table, null, null);
            }

            // Create free columns for the selected entries
            foreach (var entry in Entries)
            {
                if (!entry.IsSelected)
                {
                    continue;
                }

                DcTable gSet       = entry.Table;
                string  columnName = entry.ColumnName;
                if (string.IsNullOrWhiteSpace(columnName))
                {
                    columnName = gSet.Name;
                }

                // TODO: Check if such a column already exists (name)

                DcColumn gDim = Schema.Space.CreateColumn(columnName, Table, gSet, true);
            }

            this.DialogResult = true;
        }
Пример #29
0
        public void NativeFunctionTest() // Call native function in column definition
        {
            CreateSampleData(schema);

            DcTable t1 = schema.GetSubTable("Table 1");

            DcColumn c11 = t1.GetColumn("Column 11");
            DcColumn c12 = t1.GetColumn("Column 12");
            DcColumn c13 = t1.GetColumn("Column 13");
            DcColumn c14 = t1.GetColumn("Column 14");

            //
            // Define a derived column with a definition
            //
            DcColumn c15 = space.CreateColumn("Column 15", t1, schema.GetPrimitiveType("String"), false);

            c15.GetData().Formula = "call:System.String.Substring( [Column 12], 7, 1 )";

            // Evaluate column
            c15.GetData().Evaluate();

            Assert.AreEqual("0", c15.GetData().GetValue(0));
            Assert.AreEqual("1", c15.GetData().GetValue(1));
            Assert.AreEqual("2", c15.GetData().GetValue(2));

            //
            // Define a derived column with a definition
            //
            DcColumn c16 = space.CreateColumn("Column 15", t1, schema.GetPrimitiveType("Double"), false);

            c16.GetData().Formula = "call:System.Math.Pow( [Column 11] / 10.0, [Column 13] / 10.0 )";

            c16.GetData().Evaluate();

            Assert.AreEqual(4.0, c16.GetData().GetValue(0));
            Assert.AreEqual(1.0, c16.GetData().GetValue(1));
            Assert.AreEqual(27.0, c16.GetData().GetValue(2));
        }
Пример #30
0
        private void OkCommand_Executed(object state)
        {
            if (IsNew)
            {
                // Create a new column using parameters in the dialog
                DcSpace  space                = mainVM.Space;
                DcColumn column               = space.CreateColumn(ColumnName, Table, SelectedOutputTable, IsKey);
                column.GetData().Formula      = ColumnFormula;
                column.GetData().IsAppendData = true;

                Column = column;
            }
            else
            {
                // Update the column using parameters in the dialog
                Column.Name   = ColumnName;
                Column.Output = SelectedOutputTable;
                Column.GetData().Formula = ColumnFormula;
            }

            ((Column)Column).NotifyPropertyChanged("");

            this.DialogResult = true;
        }