public MatchManager()
    {
        times  = 0;
        map_id = 1;
        AI     = new string[]
        {
            "AI/AI1.dll",
            "AI/AI2.dll",
            "AI/AI3.dll",
            "AI/AI4.dll"
        };
#if UNITY_ANDROID
        MapOutput.Output();
#endif
    }
Пример #2
0
 private AutoMapReduceIndex(AutoMapReduceIndexDefinition definition)
     : base(IndexType.AutoMapReduce, IndexSourceType.Documents, definition)
 {
     _isFanout = definition.GroupByFields.Any(x => x.Value.GroupByArrayBehavior == GroupByArrayBehavior.ByIndividualValues);
     _output   = new MapOutput(_isFanout);
 }
Пример #3
0
            public override void Map(ByteSlice row, MapOutput output)
            {
                if (null == TableName)
                {
                    InitFields();
                }

                // Operate on values!

                ByteSlice key;

                bool keep = null == filter || filter.TestRow(row);

                if (DeleteFromFilter)
                {
                    keep = !keep;
                }

                if (keep)
                {
                    if (KeyOn != null)
                    {
                        orderbuf.Clear();
                        for (int iob = 0; iob < KeyOn.Count; iob++)
                        {
                            GetKeyPart gkp = KeyOn[iob];
                            gkp(row, orderbuf);
                        }
#if DEBUG
                        string KeyOnStringValue = "<not evaluated yet>";
                        if (0 != ((orderbuf.Count - 1) % 2))
                        {
                            KeyOnStringValue = "<not a string>";
                        }
                        else
                        {
                            //KeyOnStringValue = System.Text.Encoding.Unicode.GetString(ByteSlice.Prepare(orderbuf, 1, orderbuf.Count - 1).ToBytes());
                            {
                                System.Text.Encoding ue = new System.Text.UnicodeEncoding(false, false, true); // throwOnInvalidBytes=true
                                try
                                {
                                    KeyOnStringValue = ue.GetString(ByteSlice.Prepare(orderbuf, 1, orderbuf.Count - 1).ToBytes());
                                }
                                catch
                                {
                                    KeyOnStringValue = "<not a string>";
                                }
                            }
                        }
#endif
                        while (orderbuf.Count < DSpace_KeyLength)
                        {
                            orderbuf.Add(0);
                        }
                        key = ByteSlice.Prepare(orderbuf);
                    }
                    else // Use default key.
                    {
                        orderbuf.Clear();
                        Entry.ToBytesAppend(defkey, orderbuf);
                        key    = ByteSlice.Prepare(orderbuf);
                        defkey = unchecked (defkey + DSpace_ProcessCount);
                    }

                    if (null != Updates)
                    {
                        updatebuf.Clear();
                        row.AppendTo(updatebuf);
                        for (int ui = 0; ui < Updates.Count; ui++)
                        {
                            UpdateField uf = Updates[ui];
                            DbColumn    ci = cols[uf.FieldIndex];
                            for (int i = 0; i < ci.Type.Size; i++)
                            {
                                updatebuf[ci.RowOffset + i] = uf.NewValue[i];
                            }
                        }
                        row = ByteSlice.Prepare(updatebuf);
                    }
                }
                else
                {
                    if (null == Updates)
                    {
                        if (null != ftools)
                        {
                            ftools.ResetBuffers();
                        }

                        return;
                    }

                    if (KeyOn != null)
                    {
                        key = row;
#if DEBUG
                        throw new Exception("DEBUG:  (!keep) && (KeyOn != null)");
#endif
                    }
                    else
                    {
                        // Use default key.
                        orderbuf.Clear();
                        Entry.ToBytesAppend(defkey, orderbuf);
                        key    = ByteSlice.Prepare(orderbuf);
                        defkey = unchecked (defkey + DSpace_ProcessCount);
                    }
                }

                // If WhatFunctions, might need all input fields, so keep them here and filter out unwanted stuff in reduce.
                if (null != Whats && !WhatFunctions)
                {
                    newfieldsbuf.Clear();
                    for (int iww = 0; iww < Whats.Count; iww++)
                    {
                        int wi = Whats[iww];
                        if (-1 == wi)
                        {
                            DbTypeID ltype;
                            if (null == ftools)
                            {
                                ftools = new DbFunctionTools();
                            }
                            List <byte> lbuf = ftools.AllocBuffer();
                            ByteSlice   cval = Types.LiteralToValueBuffer(awhat[iww], out ltype, lbuf);
                            int         Size = cval.Length;
#if DEBUG
                            if (Size != OutputColumnSizes[iww])
                            {
                                throw new Exception("DEBUG:  " + awhat[iww] + ": (Size{" + Size + "} != OutputColumnSizes[iww]{" + OutputColumnSizes[iww] + "})");
                            }
#endif
                            cval.AppendTo(newfieldsbuf);
                        }
                        else
                        {
                            DbColumn ci          = cols[wi];
                            int      StartOffset = ci.RowOffset;
                            int      Size        = ci.Type.Size;
#if DEBUG
                            if (Size != OutputColumnSizes[iww])
                            {
                                throw new Exception("DEBUG:  (Size != OutputColumnSizes[iww])");
                            }
#endif
                            ByteSlice cval = ByteSlice.Prepare(row, StartOffset, Size);
                            cval.AppendTo(newfieldsbuf);
                        }
                    }
                    row = ByteSlice.Prepare(newfieldsbuf);
                }

                output.Add(key, row);

                if (null != ftools)
                {
                    ftools.ResetBuffers();
                }
            }
Пример #4
0
            public override void Map(ByteSlice row, MapOutput output)
            {
                if (JoinType.X == type)
                {
                    ftools = new DbFunctionTools();

                    string QlLeftTableName = DSpace_ExecArgs[0];
                    LeftTableName = Qa.QlArgsUnescape(QlLeftTableName);
                    string stype            = DSpace_ExecArgs[1];
                    string QlRightTableName = DSpace_ExecArgs[2];
                    RightTableName = Qa.QlArgsUnescape(QlRightTableName);
                    string QlOn = DSpace_ExecArgs[3];
                    On = Qa.QlArgsUnescape(QlOn);
                    {
                        string LeftColInfo = Qa.QlArgsUnescape(DSpace_ExecArgs[4]);
                        int    ileq        = LeftColInfo.LastIndexOf('=');
                        string sLeftType   = LeftColInfo.Substring(ileq + 1);
                        LeftType = DbType.Prepare(sLeftType);
                        LeftConv = NeedConv(LeftType, RightType);
                        string[] st = LeftColInfo.Substring(0, ileq).Split(',');
                        LeftOffset = int.Parse(st[0]);
                        LeftSize   = int.Parse(st[1]);
                    }
                    {
                        string RightColInfo = Qa.QlArgsUnescape(DSpace_ExecArgs[5]);
                        int    ileq         = RightColInfo.LastIndexOf('=');
                        string sRightType   = RightColInfo.Substring(ileq + 1);
                        RightType = DbType.Prepare(sRightType);
                        RightConv = NeedConv(RightType, LeftType);
                        string[] st = RightColInfo.Substring(0, ileq).Split(',');
                        RightOffset = int.Parse(st[0]);
                        RightSize   = int.Parse(st[1]);
                    }
                    if (0 == string.Compare("INNER", stype, true))
                    {
                        type = JoinType.INNER_JOIN;
                    }
                    else if (0 == string.Compare("LEFT_OUTER", stype, true))
                    {
                        type = JoinType.LEFT_OUTER_JOIN;
                    }
                    else if (0 == string.Compare("RIGHT_OUTER", stype, true))
                    {
                        type = JoinType.RIGHT_OUTER_JOIN;
                    }
                    else
                    {
                        throw new NotSupportedException("DEBUG:  JOIN type not supported: " + stype);
                    }

                    string DfsTableFilesInput = DSpace_ExecArgs[6];

                    /*
                     * TableFileNames = DfsTableFilesInput.Split(';');
                     * if (2 != TableFileNames.Length)
                     * {
                     *  throw new Exception("DEBUG:  Invalid number of tables");
                     * }
                     * for (int it = 0; it < TableFileNames.Length; it++)
                     * {
                     *  if (TableFileNames[it].StartsWith("dfs://", StringComparison.OrdinalIgnoreCase))
                     *  {
                     *      TableFileNames[it] = TableFileNames[it].Substring(6);
                     *  }
                     *  int iat = TableFileNames[it].IndexOf('@');
                     *  if (-1 != iat)
                     *  {
                     *      TableFileNames[it] = TableFileNames[it].Substring(0, iat);
                     *  }
                     * }
                     * */
                }

                int tableid = GetTableID(row);

                ByteSlice key;

                if (0 == tableid)
                {
                    key = ByteSlice.Prepare(row, LeftOffset, LeftSize);
                    if (null != LeftConv)
                    {
                        key = LeftConv(key, DSpace_KeyLength, ftools);
                    }
                }
                else if (1 == tableid)
                {
                    key = ByteSlice.Prepare(row, RightOffset, RightSize);
                    if (null != RightConv)
                    {
                        key = RightConv(key, DSpace_KeyLength, ftools);
                    }
                }
                else
                {
                    throw new Exception("Map: Unexpected TableID: " + tableid);
                }

                List <byte> valuebuf = ftools.AllocBuffer(1 + 4 + row.Length);

                {
                    DbValue tableiddbvalue = ftools.AllocValue(tableid);
                    tableiddbvalue.Eval().AppendTo(valuebuf);
                }
                row.AppendTo(valuebuf);

                output.Add(key, ByteSlice.Prepare(valuebuf));

                ftools.ResetBuffers();
            }
Пример #5
0
 public override void Map(ByteSlice line, MapOutput output)
 {
     output.Add(line, ByteSlice.Prepare());
 }
Пример #6
0
 public virtual void Map(ByteSlice line, MapOutput output)
 {
 }