Beispiel #1
0
 public TableRel(string name, DcSpace space)
     : base(name, space)
 {
     SuperPaths   = new List <ColumnAtt>();
     SubPaths     = new List <ColumnAtt>();
     GreaterPaths = new List <ColumnAtt>();
     LesserPaths  = new List <ColumnAtt>();
 }
Beispiel #2
0
 public TableCsv(string name, DcSpace space)
     : base(name, space)
 {
     HasHeaderRecord = true;
     Delimiter       = ",";
     CultureInfo     = System.Globalization.CultureInfo.CurrentCulture;
     Encoding        = Encoding.UTF8;
 }
Beispiel #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);
                    }
                }
            }
        }
Beispiel #4
0
        public override void FromJson(JObject json, DcSpace ws) // Init this object fields by using json object
        {
            base.FromJson(json, ws);                            // ColumnPath

            RelationalColumnName       = (string)json["RelationalColumnName"];
            RelationalPkName           = (string)json["RelationalPkName"];
            RelationalFkName           = (string)json["RelationalFkName"];
            RelationalTargetTableName  = (string)json["RelationalTargetTableName"];
            RelationalTargetColumnName = (string)json["RelationalTargetColumnName"];
        }
Beispiel #5
0
        public virtual void FromJson(JObject json, DcSpace ws)
        {
            // No super-object

            Similarity = (double)json["similarity"];

            SourcePath = (ColumnPath)Com.Schema.Utils.CreateObjectFromJson((JObject)json["source_path"]);
            SourcePath.FromJson((JObject)json["source_path"], ws);

            TargetPath = (ColumnPath)Com.Schema.Utils.CreateObjectFromJson((JObject)json["target_path"]);
            TargetPath.FromJson((JObject)json["target_path"], ws);
        }
Beispiel #6
0
        public virtual void FromJson(JObject json, DcSpace ws) // Init this object fields by using json object
        {
            // No super-object

            Name  = (string)json["name"];
            IsKey = json["key"] != null?StringSimilarity.JsonTrue((string)json["key"]) : false;

            IsSuper = json["super"] != null?StringSimilarity.JsonTrue((string)json["super"]) : false;

            Input  = (DcTable)Utils.ResolveJsonRef((JObject)json["lesser_table"], ws);
            Output = (DcTable)Utils.ResolveJsonRef((JObject)json["greater_table"], ws);
        }
Beispiel #7
0
        public override void FromJson(JObject json, DcSpace ws)
        {
            base.FromJson(json, ws); // Set

            _schemaKind = json["SchemaKind"] != null ? (DcSchemaKind)(int)json["SchemaKind"] : DcSchemaKind.Dc;

            // List of tables
            // Tables are stored in space

            // List of columns
            // Columns cannot be loaded because not all schemas might have been loaded (so it is a problem with import columns)
        }
Beispiel #8
0
        public virtual void FromJson(JObject json, DcSpace ws)
        {
            // No super-object

            Name = (string)json["name"];

            // TODO: JSON object for DcTableData including definition
            JObject tableDef = (JObject)json["definition"];
            if (tableDef != null)
            {
                WhereFormula = (string)tableDef["whereFormula"];
            }
        }
Beispiel #9
0
        private void OkCommand_Executed(object state)
        {
            DcSpace space = mainVM.Space;

            if (IsNew)
            {
                // Create a new table using parameters in the dialog
                TableCsv table = (TableCsv)space.CreateTable(DcSchemaKind.Csv, TableName, Schema.Root);

                table.GetData().WhereFormula = TableFormula;

                table.FilePath        = FilePath;
                table.HasHeaderRecord = HasHeaderRecord;
                table.Delimiter       = Delimiter;
                table.CultureInfo.NumberFormat.NumberDecimalSeparator = Decimal;

                // Load (read-only) column descriptions from CSV to schema
                //var columns = table.LoadSchema();
                //var columns = ((SchemaCsv)Schema).LoadSchema(table);

                Table = table;
            }
            else
            {
                TableCsv table = (TableCsv)Table;

                table.Name = TableName;
                table.GetData().WhereFormula = TableFormula;

                table.FilePath        = FilePath;
                table.HasHeaderRecord = HasHeaderRecord;
                table.Delimiter       = Delimiter;
                table.CultureInfo.NumberFormat.NumberDecimalSeparator = Decimal;

                foreach (DcColumn col in table.Columns.ToArray())
                {
                    if (!col.IsSuper)
                    {
                        space.DeleteColumn(col);
                    }
                }

                // Load (read-only) column descriptions from CSV to schema
                //var columns = table.LoadSchema();
                //var columns = ((SchemaCsv)Schema).LoadSchema(table);
            }

            ((Com.Schema.Table)Table).NotifyPropertyChanged("");

            this.DialogResult = true;
        }
Beispiel #10
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;
        }
Beispiel #11
0
        // It is called when preparing this dialog for editing/adding a table or when context changes (not during the process)
        // Essentially, we do it when data context is set.
        private void initViewModel()
        {
            DcSpace space = mainVM.Space;

            if (IsNew)
            {
                TableName    = "New Table";
                TableFormula = "";
            }
            else
            {
                TableName    = Table.Name;
                TableFormula = Table.GetData().WhereFormula;
            }

            FirePropertyNotifyChanged("");
        }
Beispiel #12
0
        // It is called when preparing this dialog for editing/adding a column or when context changes (not during the process)
        // Essentially, we do it when data context is set.
        private void initViewModel()
        {
            // Populate possible schemas using all schemas from the space with some limitations.
            // Rule/constraints for possible schemas:
            // - If input schema (always non-null) is remote, then output schema is only Mashup
            DcSpace  space  = mainVM.Space;
            DcSchema schema = Table.Schema;

            OutputSchemas.Clear();
            List <DcSchema> allSchemas = space.GetSchemas();

            allSchemas.ForEach(x => OutputSchemas.Add(x));

            if (IsNew)
            {
                // Set default parameters: name, schema (e.g., if single), type, key
                ColumnName    = "New Column";
                IsKey         = false;
                ColumnFormula = "";

                // Set selections
                SelectedOutputSchema = mainVM.MashupTop;

                // Set enabled/disabled
                //targetSchemaList.IsEnabled = true;
                //targetTableList.IsEnabled = true;
            }
            else
            {
                // Set existing column parameters: name, schema, type, key
                ColumnName    = Column.Name;
                IsKey         = Column.IsKey;
                ColumnFormula = Column.GetData().Formula;

                // Set selections
                SelectedOutputSchema = Column.Output.Schema;
                SelectedOutputTable  = Column.Output;

                // Set enabled/disabled
                //targetSchemaList.IsEnabled = false;
                //targetTableList.IsEnabled = false;
            }

            FirePropertyNotifyChanged("");
        }
Beispiel #13
0
        public void Resolve(DcSpace space)
        {
            if (!string.IsNullOrEmpty(SchemaName))
            {
                // 1. Resolve schema name
                TypeSchema = space.GetSchema(SchemaName);
                if (TypeSchema == null)
                {
                    return;                     // Cannot resolve
                }
                // 2. Resolve table name
                TypeTable = TypeSchema.GetSubTable(TypeName);
                if (TypeTable == null)
                {
                    return;                    // Cannot resolve
                }
            }
            else if (!string.IsNullOrEmpty(TypeName)) // No schema name (imcomplete info)
            {
                // 1. try to find the table in the mashup
                DcSchema mashup = space.GetSchemas().FirstOrDefault(x => x.GetSchemaKind() == DcSchemaKind.Dc);
                if (mashup != null)
                {
                    TypeTable = mashup.GetSubTable(TypeName);
                    if (TypeTable != null)
                    {
                        TypeSchema = mashup;
                        SchemaName = TypeSchema.Name; // We also reconstruct the name
                        return;
                    }
                }

                // 2. try to find the table in any other schema
                foreach (DcSchema schema in space.GetSchemas())
                {
                    TypeTable = schema.GetSubTable(TypeName);
                    if (TypeTable != null)
                    {
                        TypeSchema = schema;
                        SchemaName = TypeSchema.Name; // We also reconstruct the name
                        return;
                    }
                }
            }
        }
Beispiel #14
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);
        }
Beispiel #15
0
        public virtual void FromJson(JObject json, DcSpace ws)
        {
            // No super-object

            Similarity = (double)json["similarity"];

            _sourceTab = (DcTable)Com.Schema.Utils.ResolveJsonRef((JObject)json["source_table"], ws);
            _targetTab = (DcTable)Com.Schema.Utils.ResolveJsonRef((JObject)json["target_table"], ws);

            // List of matches
            foreach (JObject match in json["matches"])
            {
                PathMatch comMatch = (PathMatch)Com.Schema.Utils.CreateObjectFromJson(match);
                if (comMatch != null)
                {
                    comMatch.FromJson(match, ws);
                    this.Matches.Add(comMatch);
                }
            }
        }
Beispiel #16
0
        public override void FromJson(JObject json, DcSpace ws)
        {
            base.FromJson(json, ws); // Table

            FilePath = (string)json["file_path"];

            HasHeaderRecord = (bool)json["HasHeaderRecord"];
            Delimiter       = (string)json["Delimiter"];
            CultureInfo     = new CultureInfo((string)json["CultureInfo"]);

            string encodingName = (string)json["Encoding"];

            if (string.IsNullOrEmpty(encodingName))
            {
                Encoding = System.Text.Encoding.Default;
            }
            else if (encodingName.Contains("ASCII"))
            {
                Encoding = System.Text.Encoding.ASCII;
            }
            else if (encodingName == "Unicode")
            {
                Encoding = System.Text.Encoding.Unicode;
            }
            else if (encodingName.Contains("UTF-32"))
            {
                Encoding = System.Text.Encoding.UTF32;                                       // "Unicode (UTF-32)"
            }
            else if (encodingName.Contains("UTF-7"))
            {
                Encoding = System.Text.Encoding.UTF7;                                      // "Unicode (UTF-7)"
            }
            else if (encodingName.Contains("UTF-8"))
            {
                Encoding = System.Text.Encoding.UTF8;                                      // "Unicode (UTF-8)"
            }
            else
            {
                Encoding = System.Text.Encoding.Default;
            }
        }
Beispiel #17
0
        private void OkCommand_Executed(object state)
        {
            DcSpace space = mainVM.Space;

            if (IsNew)
            {
                // Create a new table using parameters in the dialog
                DcTable table = space.CreateTable(DcSchemaKind.Dc, TableName, Schema.Root);
                table.GetData().WhereFormula = TableFormula;

                Table = table;
            }
            else
            {
                Table.Name = TableName;
                Table.GetData().WhereFormula = TableFormula;
            }

            ((Com.Schema.Table)Table).NotifyPropertyChanged("");

            this.DialogResult = true;
        }
Beispiel #18
0
        public override void FromJson(JObject json, DcSpace ws) // Init this object fields by using json object
        {
            base.FromJson(json, ws);                            // Column

            var    segs     = new List <DcColumn>();
            JArray segments = (JArray)json["segments"];

            for (int i = 0; i < segments.Count; i++)
            {
                JObject  segRef = (JObject)segments[i];
                DcColumn column = (DcColumn)Com.Schema.Utils.ResolveJsonRef(segRef, ws);
                if (column == null) // Failed to resolve the segment
                {
                    segs.Clear();   // Empty path because some segment is absent
                    break;
                }
                segs.Add(column);
            }

            for (int i = 0; i < segs.Count; i++)
            {
                InsertLast(segs[i]);
            }
        }
Beispiel #19
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;
        }
Beispiel #20
0
 public override void FromJson(JObject json, DcSpace ws)
 {
     base.FromJson(json, ws); // Schema
 }
Beispiel #21
0
 public TableCsv(DcSpace space)
     : this("", space)
 {
 }
Beispiel #22
0
 public SchemaOledb(string name, DcSpace space)
     : base(name, space)
 {
     _schemaKind = DcSchemaKind.Oledb;
 }
Beispiel #23
0
 public SchemaOledb(DcSpace space)
     : this("", space)
 {
 }
Beispiel #24
0
        // Resolve symbols in the syntax tree by finding referenced schema elements.
        // This also performes schema population by appending columns if they cannot be found.
        // Schema population is performed if the corresponding flag is true.
        protected void Bind()
        {
            // NOTE: This should be removed or moved to the expression. Here we store non-syntactic part of the definition in columndef and then set the expression. Maybe we should have syntactic annotation for APPEND flag (output result annotation, what to do with the output).
            if (formulaExpr.DefinitionType == ColumnDefinitionType.LINK)
            {
                // Adjust the expression according to other parameters of the definition
                if (IsAppendData)
                {
                    formulaExpr.Action = ActionType.APPEND;
                }
                else
                {
                    formulaExpr.Action = ActionType.READ;
                }
            }

            // General parameters
            DcSpace Workspace = Column.Input.Schema.Space;

            if (Column.Input.Schema is SchemaCsv) // Import from CSV
            {
                // Prepare parameter variables for the expression
                DcTable thisTable = Column.Input;

                thisVariable            = new Variable(thisTable.Schema.Name, thisTable.Name, "this");
                thisVariable.TypeSchema = thisTable.Schema;
                thisVariable.TypeTable  = thisTable;

                // Parameterize expression and resolve it (bind names to real objects)
                formulaExpr.OutputVariable.SchemaName = Column.Output.Schema.Name;
                formulaExpr.OutputVariable.TypeName   = Column.Output.Name;
                formulaExpr.OutputVariable.TypeSchema = Column.Output.Schema;
                formulaExpr.OutputVariable.TypeTable  = Column.Output;

                formulaExpr.Resolve(Workspace, new List <DcVariable>()
                {
                    thisVariable
                });
            }
            else if (formulaExpr.DefinitionType == ColumnDefinitionType.ARITHMETIC || formulaExpr.DefinitionType == ColumnDefinitionType.LINK)
            {
                // Prepare parameter variables for the expression
                DcTable thisTable = Column.Input;

                thisVariable            = new Variable(thisTable.Schema.Name, thisTable.Name, "this");
                thisVariable.TypeSchema = thisTable.Schema;
                thisVariable.TypeTable  = thisTable;

                // Parameterize expression and resolve it (bind names to real objects)
                formulaExpr.OutputVariable.SchemaName = Column.Output.Schema.Name;
                formulaExpr.OutputVariable.TypeName   = Column.Output.Name;
                formulaExpr.OutputVariable.TypeSchema = Column.Output.Schema;
                formulaExpr.OutputVariable.TypeTable  = Column.Output;

                formulaExpr.Resolve(Workspace, new List <DcVariable>()
                {
                    thisVariable
                });
            }
            else if (formulaExpr.DefinitionType == ColumnDefinitionType.AGGREGATION)
            {
                // Aassert: FactTable.GroupFormula + ThisSet.ThisFunc = FactTable.MeasureFormula
                // Aassert: if LoopSet == ThisSet then GroupCode = null, ThisFunc = MeasureCode

                // Facts
                factsExpr = formulaExpr.GetChild("facts").GetChild(0);

                // This table and variable
                string  thisTableName = factsExpr.Name;
                DcTable thisTable     = Column.Input.Schema.GetSubTable(thisTableName);

                thisVariable            = new Variable(thisTable.Schema.Name, thisTable.Name, "this");
                thisVariable.TypeSchema = thisTable.Schema;
                thisVariable.TypeTable  = thisTable;

                // Groups
                groupExpr = formulaExpr.GetChild("groups").GetChild(0);

                groupExpr.Resolve(Workspace, new List <DcVariable>()
                {
                    thisVariable
                });

                groupVariable            = new Variable(Column.Input.Schema.Name, Column.Input.Name, "this");
                groupVariable.TypeSchema = Column.Input.Schema;
                groupVariable.TypeTable  = Column.Input;

                // Measure
                measureExpr = formulaExpr.GetChild("measure").GetChild(0);

                measureExpr.Resolve(Workspace, new List <DcVariable>()
                {
                    thisVariable
                });

                measureVariable            = new Variable(Column.Output.Schema.Name, Column.Output.Name, "value");
                measureVariable.TypeSchema = Column.Output.Schema;
                measureVariable.TypeTable  = Column.Output;

                // Updater/aggregation function
                ExprNode updaterExpr = formulaExpr.GetChild("aggregator").GetChild(0);
                outputExpr = ExprNode.CreateUpdater(Column, updaterExpr.Name);

                outputExpr.Resolve(Workspace, new List <DcVariable>()
                {
                    groupVariable, measureVariable
                });
            }
            else
            {
                throw new NotImplementedException("This type of column definition is not implemented.");
            }
        }
Beispiel #25
0
        public override void FromJson(JObject json, DcSpace ws)
        {
            base.FromJson(json, ws); // Column

            ColumnIndex = (int)json["ColumnIndex"];
        }
Beispiel #26
0
 public SchemaCsv(DcSpace space)
     : this("", space)
 {
 }
Beispiel #27
0
 public SchemaCsv(string name, DcSpace space)
     : base(name, space)
 {
     _schemaKind = DcSchemaKind.Csv;
     connection  = new ConnectionCsv();
 }
Beispiel #28
0
 public TableRel(DcSpace space)
     : this("", space)
 {
 }
Beispiel #29
0
        public override void FromJson(JObject json, DcSpace ws)
        {
            base.FromJson(json, ws); // Column

            RelationalFkName = (string)json["RelationalFkName"];
        }
Beispiel #30
0
        public static object ResolveJsonRef(JObject json, DcSpace ws) // Resolve a json reference to a real object
        {
            if (json == null)
            {
                return(null);
            }

            string element_type = (string)json["element_type"];

            if (element_type == null)
            {
                if (json["schema_name"] == null)
                {
                    return(null);
                }
                else if (json["table_name"] == null)
                {
                    element_type = "schema";
                }
                else if (json["column_name"] == null)
                {
                    element_type = "table";
                }
                else
                {
                    element_type = "column";
                }
            }

            if (element_type == "schema") // Find schema
            {
                return(ws.GetSchema((string)json["schema_name"]));
            }
            else if (element_type == "table") // Find table
            {
                DcSchema schema = ws.GetSchema((string)json["schema_name"]);
                if (schema == null)
                {
                    return(null);
                }
                return(schema.GetSubTable((string)json["table_name"]));
            }
            else if (element_type == "column") // Find column
            {
                DcSchema schema = ws.GetSchema((string)json["schema_name"]);
                if (schema == null)
                {
                    return(null);
                }
                DcTable table = schema.GetSubTable((string)json["table_name"]);
                if (table == null)
                {
                    return(null);
                }
                return(table.GetColumn((string)json["column_name"]));
            }
            else
            {
                throw new NotImplementedException("Unknown element type in the reference.");
            }
        }