Beispiel #1
0
        public static long Delete(RecordSet Extent, Predicate Where)
        {

            long n = 0;
            RecordSet rs = new RecordSet(Extent.Columns);
            RecordWriter w = rs.OpenWriter();
            FastReadPlan plan = new FastReadPlan(Extent, Where.NOT, new FNodeSet(Extent.Columns), w);
            plan.Execute();
            w.Close();
            n = Extent.Count - rs.Count;
            Extent._Cache = rs._Cache;
            return n;

            //long n = 0;
            //StaticRegister mem = new StaticRegister(null);
            //Where.AssignRegister(mem);
            //for (int i = Extent.Count - 1; i >= 0; i--)
            //{
            //    mem.Assign(Extent[i]);
            //    if (Where.Render())
            //    {
            //        Extent.Remove(i);
            //        n++;
            //    }

            //}
            //return n;

        }
Beispiel #2
0
        // RecordSet SELECTS //
        public static RecordSet SELECT(DataSet Data, FNodeSet Nodes, Predicate Where)
        {

            RecordSet rs = new RecordSet(Nodes.Columns);
            RecordWriter w = rs.OpenWriter();
            FastReadPlan plan = new FastReadPlan(Data, Where, Nodes, w);
            plan.Execute();
            w.Close();
            return rs;

        }
Beispiel #3
0
        public static RecordWriter GetWriter(Workspace Enviro, Schema Columns, HScriptParser.Return_actionContext context)
        {

            // Get the table name //
            string name = context.full_table_name().table_name().IDENTIFIER().GetText();
            string db =
                (context.full_table_name().database_name() == null)
                ? "GLOBAL"
                : context.full_table_name().database_name().GetText();

            // Figure out if we need to append //
            bool appendto =
                (context.K_INSERT() != null)
                ? true
                : false;

            // Global -- Append //
            if (context.full_table_name().database_name() == null && appendto)
            {
                if (Enviro.ChunkHeap.Exists(name))
                    return Enviro.ChunkHeap[name].OpenWriter();
                throw new HScriptCompileException(string.Format("Chunk '{0}' does not exist", name));
            }

            // Static -- Append //
            if (appendto)
            {
                string fullname = db + "." + name;
                if (Enviro.Exists(db, name))
                    return Enviro.GetStaticTable(db, name).OpenWriter();
                throw new HScriptCompileException(string.Format("Table '{0}' does not exist", fullname));
            }

            // Global -- Create New //
            if (context.full_table_name().database_name() == null)
            {
                RecordSet data = new RecordSet(Columns);
                Enviro.ChunkHeap.Reallocate(name, data);
                return data.OpenWriter();
            }

            // Static -- Create New //
            string dir = Enviro.Connections[db];
            Table t = new Table(dir, name, Columns);
            return t.OpenWriter();

        }
Beispiel #4
0
        // To Methods //
        public RecordSet ToFinal(FNodeSet Fields, Predicate Filter)
        {

            RecordSet rs = new RecordSet(Fields.Columns);
            RecordWriter w = rs.OpenWriter();

            this.WriteToFinal(w, Fields);

            return rs;

        }
Beispiel #5
0
        public override RecordSet Extend(DataSet Data, FNodeSet ClusterVariables, FNodeSet OtherKeepers, Predicate Where)
        {

            // Check that the ClusterVariable count matches the internal node set count //
            if (ClusterVariables.Count != this._fields.Count)
                throw new ArgumentException("The cluster variable count passed does not match the internal cluster variable count");

            // Create the selectors //
            FNodeSet values = OtherKeepers.CloneOfMe();
            FNode n = new FNodeResult(null, new RowClusterCellFunction(this._rule, this._means));
            foreach (FNode t in ClusterVariables.Nodes)
            {
                n.AddChildNode(t.CloneOfMe());
            }
            values.Add("CLUSTER_ID", n);

            // Build a recordset //
            RecordSet rs = new RecordSet(values.Columns);
            RecordWriter w = rs.OpenWriter();

            // Run a fast select //
            FastReadPlan plan = new FastReadPlan(Data, Where, values, w);
            plan.Execute();
            w.Close();

            return rs;

        }
Beispiel #6
0
        /*
        private DataSet GenerateSortedDataSet(DataSet Data, FNodeSet Keys, AggregateSet Aggregates, Predicate Where)
        {

            // Create the output nodes //
            FNodeSet nodes = new FNodeSet();
            for(int i = 0; i < Keys.Count; i++)
            {
                nodes.Add(Keys.Alias(i), Keys[i].CloneOfMe());
            }
            List<int> indexes = Aggregates.FieldRefs;
            foreach(int i in indexes)
            {
                nodes.Add(Data.Columns.ColumnName(i), new FNodeFieldRef(null, i, Data.Columns.ColumnAffinity(i), null));
            }

            // Create the temp table //
            DataSet t = new RecordSet(nodes.Columns);
            if (Data.IsBig)
            {
                t = new Table(Data.Directory, Header.TempName(), nodes.Columns);
            }

            // Get data //
            RecordWriter w = t.OpenWriter();
            FastReadPlan frp = new FastReadPlan(Data, Where, nodes, w);
            w.Close();

            // Sort the data //
            Key k = Key.Build(Keys.Count);
            t.Sort(k);

            // Return the data //
            return t;


        }

        private void ExecuteSortedSet(RecordWriter Output, RecordReader BaseReader, FNodeSet Keys, AggregateSet Aggregates, FNodeSet ReturnSet,
            StaticRegister BaseMem, StaticRegister ReturnMem)
        {

            CompoundRecord agg_data = Aggregates.Initialize();
            Record key_data = null;
            Record lag_key = null;
            long Reads = 0;
            long Writes = 0;

            while (!BaseReader.EndOfData)
            {

                // Assign the current register //
                BaseMem.Assign(BaseReader.ReadNext());

                // Get the key value //
                key_data = Keys.Evaluate();

                // Check for a key change //
                if (lag_key == null)
                    lag_key = key_data;
                if (!Record.Equals(key_data, lag_key))
                {

                    // Assing the combined records to the register //
                    ReturnMem.Assign(Record.Join(key_data, Aggregates.Evaluate(agg_data)));

                    // Add the record to the output dataset //
                    Output.Insert(ReturnSet.Evaluate());

                    // Reset the aggregate //
                    agg_data = Aggregates.Initialize();

                    // Writes //
                    Writes++;

                }

                // Accumulate the data //
                Aggregates.Accumulate(agg_data);
                Reads++;

            }

            ReturnMem.Assign(Record.Join(key_data, Aggregates.Evaluate(agg_data)));
            Output.Insert(ReturnSet.Evaluate());

            this._reads = Reads;
            this._writes = Writes + 1;

        }
        */

        public static RecordSet Render(DataSet Source, Predicate Filter, FNodeSet Keys, AggregateSet Aggregates)
        {

            Schema s = Schema.Join(Keys.Columns, Aggregates.GetSchema);
            RecordSet rs = new RecordSet(s);
            RecordWriter w = rs.OpenWriter();

            StaticRegister mem1 = new StaticRegister(Source.Columns);
            Keys.AssignRegister(mem1);
            Aggregates.AssignRegister(mem1);

            StaticRegister mem2 = new StaticRegister(rs.Columns);
            FNodeSet out_nodes = new FNodeSet(rs.Columns);
            out_nodes.AssignRegister(mem2);

            AggregatePlan plan = new AggregatePlan(w, Source, Filter, Keys, Aggregates, new FNodeSet(s), mem1, mem2, Source.Directory);
            plan.Execute();

            w.Close();

            return rs;

        }
Beispiel #7
0
        public override RecordSet Extend(DataSet Data, FNodeSet Inputs, FNodeSet OtherKeepValues, Predicate Where)
        {

            // Combine the keep variables and the expected nodes //
            FNodeSet nodes = FNodeSet.Union(OtherKeepValues.CloneOfMe(), this.Responses.Expected);

            // Open the reader //
            RecordReader rr = Data.OpenReader(Where);

            // Create the output table and stream //
            RecordSet rs = new RecordSet(nodes.Columns);
            RecordWriter Output = rs.OpenWriter();

            // Create a memory structure //
            StaticRegister mem = new StaticRegister(Data.Columns);

            // Assign both the input set and output set to the memory structure //
            nodes.AssignRegister(mem);
            Inputs.AssignRegister(mem);

            // Run through each record //
            while (rr.EndOfData == false)
            {

                // Assign memory //
                mem.Assign(rr.ReadNext());

                // Get the array of doubles for the network //
                double[] d = Record.ToDouble(Inputs.Evaluate());

                // Render each node //
                this._Nodes.Render(d);

                // Output //
                Record t = nodes.Evaluate();
                Output.Insert(t);

            }

            Output.Close();

            return rs;

        }