Exemple #1
0
        public int CompareTo(HqlKey bb, int n)
        {
            if (_o[n] == null && bb._o[n] == null)
            {
                return(0);
            }
            else if (_o[n] == null)
            {
                return(-1);
            }
            else if (bb._o[n] == null)
            {
                return(1);
            }

            HqlCompareToken.MakeAppropriateObjects(ref _o[n], ref bb._o[n]);

            if (_o[n] is string && bb._o[n] is string)
            {
                return(String.Compare((string)_o[n], (string)bb._o[n], StringComparison.CurrentCulture));
            }
            if (_o[n] is Int64 && bb._o[n] is Int64)
            {
                return(((Int64)_o[n]).CompareTo((Int64)bb._o[n]));
            }
            if (_o[n] is int && bb._o[n] is int)
            {
                return(((int)_o[n]).CompareTo((int)bb._o[n]));
            }
            if (_o[n] is decimal && bb._o[n] is decimal)
            {
                return(((decimal)_o[n]).CompareTo((decimal)bb._o[n]));
            }
            return(String.Compare(_o[n].ToString(), bb._o[n].ToString(), StringComparison.CurrentCulture));
        }
Exemple #2
0
        ///////////////////////
        // Public

        public bool Equals(HqlKey key)
        {
            if (_o.Length != key._o.Length)
            {
                return(false);
            }

            if (_hash.HasValue && key._hash.HasValue)
            {
                if (GetHashCode() != key.GetHashCode())
                {
                    return(false);
                }
            }

            for (int i = 0; i < _o.Length; ++i)
            {
                if (_o[i] == null)
                {
                    if (key._o[i] != null)
                    {
                        return(false);
                    }
                }
                else if (key._o[i] == null)
                {
                    return(false);
                }
                else if (!_o[i].Equals(key._o[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #3
0
        private int _CalculateHashCode(HqlKey key)
        {
            string sbstr   = key.ToHashString();
            int    h1      = lookup3ycs(sbstr);
            long   modular = 0;

            for (; ;)
            {
                if (!_ht.ContainsKey(h1))
                {
                    _ht[h1] = key;
                    break;
                }
                if (_ht[h1].Equals(key))
                {
                    break;
                }

                // HASH COLLISION!!
                if (modular == 0)
                {
                    modular = lookup3ycs(sbstr + "\x01" + sbstr);
                }
                long newlong = (((long)h1 + modular) % (long)Int32.MaxValue);
                h1 = (int)newlong;
            }
            return(h1);
        }
Exemple #4
0
 public HqlResultRow Find(HqlKey key)
 {
     if (_ht.Contains(key))
     {
         return((HqlResultRow)_ht[key]);
     }
     return(null);
 }
Exemple #5
0
        public void Sort()
        {
//#if DEBUG
//            if (_type != HqlTableType.GROUPBY_TABLE)
//                throw new Exception("Cannot SORT unless it is a GROUPBY");
//#endif
            Dictionary <HqlKey, object> tb = (Dictionary <HqlKey, object>)_ht;

            _keys = new HqlKey[tb.Keys.Count];
            tb.Keys.CopyTo(_keys, 0);
            Array.Sort <HqlKey>(_keys, _comp);
        }
Exemple #6
0
        private void ProcessHavingAndOrder()
        {
            if (_having.Count > 0)
            {
                HqlHavingRow havingRow = new HqlHavingRow(_orderby.FieldGroup, _groupby.FieldGroup, _select.FieldGroup);
                for (IDictionaryEnumerator ptr = _groupby.Table.GetEnumeratorForTable(); ptr.MoveNext();)
                {
                    HqlKey       key2   = (HqlKey)ptr.Key;
                    HqlResultRow value2 = (HqlResultRow)ptr.Value;

                    havingRow.Key = key2;
                    havingRow.Row = value2;

                    if (!_having.Evaluate(havingRow))
                    {
                        value2.ValuesSet = false;
                    }
                }
            }

            if (_orderby.Count > 0)
            {
                // I need to replace the keys with the actual values so that I sort them correctly
                for (IDictionaryEnumerator ptr = _groupby.Table.GetEnumeratorForTable(); ptr.MoveNext();)
                {
                    HqlKey       key2   = (HqlKey)ptr.Key;
                    HqlResultRow value2 = (HqlResultRow)ptr.Value;
                    if (!value2.ValuesSet)
                    {
                        continue;
                    }

                    for (int i = 0; i < _orderby.Count; ++i)
                    {
                        HqlField f = _orderby.FieldGroup[i];
                        if (f.HasFunction)
                        {
                            object o = ((HqlCalc)value2[i]).GetValue();
                            if (f.Scalar != null)
                            {
                                key2[i] = f.Scalar.Evaluate(o);
                            }
                            else
                            {
                                key2[i] = o;
                            }
                        }
                    }
                }
            }
        }
Exemple #7
0
        private bool GetLineMultiSourceFunction()
        {
            for (; ;)
            {
                if (!_loadedFirstFiles)
                {
                    GetLineMultifileStreamableLoadFirstFiles();
                    _loadedFirstFiles = true;
                }

                if (!_successCalculate)
                {
                    _groupby.InitializeForStoringData(_orderby);
                    CalculateDataMultifiles();
                    _successCalculate = true;

                    ProcessHavingAndOrder();

                    _groupby.Table.Sort();
                    _ptr = _groupby.Table.GetSortedEnumeratorForTable();
                }

                if (!_ptr.MoveNext())
                {
                    return(false);
                }

                HqlKey       key   = (HqlKey)_ptr.Current;
                HqlResultRow value = (HqlResultRow)_groupby.Table[key];

                // did this pass the Having command?
                if (!value.ValuesSet)
                {
                    continue;
                }

                _line = _select.EvaluateGroupBy(_orderby.Count, value);

                if (_settings.PrintCategorizeFilename)
                {
                    _outfilename = _settings.Output.EvaluateGroupBy(_orderby.Count + _select.Count, value);
                }

                return(true);
            }
        }
Exemple #8
0
        private void RunQueryToOutputCategorize()
        {
            Dictionary <HqlKey, HqlOutFile> dic = null;

            try
            {
                // have a hash table of the open filenames, when I get 25 open, close them all
                dic = new Dictionary <HqlKey, HqlOutFile>();
                int openedFiles = 0;
                for (; ;)
                {
                    if (openedFiles > 125)
                    {
                        CloseAllFiles(dic);
                        openedFiles = 0;
                    }
                    if (!GetLine())
                    {
                        break;
                    }

                    // due to windows being case-insensitive, I am forcing to uppercase when inside my dictionary.
                    //string upperCaseFilename = _outfilename.ToUpper();
                    HqlKey key = new HqlKey(new string[] { _outfilename.ToUpper() });
                    if (dic.ContainsKey(key))
                    {
                        if (!dic[key].IsOpen)
                        {
                            openedFiles++;
                        }
                    }
                    else
                    {
                        dic[key] = new HqlOutFile(_outfilename);
                        openedFiles++;
                    }
                    dic[key].WriteLine(_line);
                }
            }
            finally
            {
                CloseAllFiles(dic);
            }
        }
Exemple #9
0
        private void CreateKeyAndValue(HqlRecord record)
        {
            HqlKey KEY = null;

            object[] keys = CreateRecordKey(record, _orderby, _groupby, _settings.Output, _linenum);
            KEY = new HqlKey(keys);

            HqlResultRow row = _groupby.FindResultRow(KEY);

            if (row == null)
            {
                row = CreateObjectArrayValue(_orderby, _select, _settings.Output);
            }
#if DEBUG
            else
            {
                int stop = 0;
            }
#endif

            // set the values on the row
            int counter = 0;

            _orderby.AddToResultRow(counter, record, row);
            counter += _orderby.Count;

            _select.AddToResultRow(counter, record, row);
            counter += _select.Count;

            if (_settings.PrintCategorizeFilename)
            {
                _settings.Output.AddToResultRow(counter, record, row);
                //counter += _output.Count;
            }

            if (!row.ValuesSet)
            {
                row.ValuesSet = true;
                _groupby.SetResultRow(KEY, row);
            }
        }
Exemple #10
0
        ///////////////////////
        // Overridden functions

        ///////////////////////
        // Public

        public void Set(HqlKey key, HqlResultRow row)
        {
            _ht[key] = row;
        }
Exemple #11
0
 public void SetResultRow(HqlKey key, HqlResultRow row)
 {
     Table.Set(key, row);
 }
Exemple #12
0
 public HqlResultRow FindResultRow(HqlKey key)
 {
     return(Table.Find(key));
 }
Exemple #13
0
        static public int CalculateHashCode(HqlKey key)
        {
            int h1 = GetUniqueHash()._CalculateHashCode(key);

            return(h1);
        }