DbValueConversion NeedConv(DbType tfrom, DbType tto) { switch (tfrom.ID) { case DbTypeID.INT: switch (tto.ID) { case DbTypeID.LONG: return Conv_IntToLong; case DbTypeID.DOUBLE: return Conv_IntToDouble; } break; case DbTypeID.LONG: switch (tto.ID) { case DbTypeID.DOUBLE: return Conv_LongToDouble; } break; case DbTypeID.CHARS: return Conv_String; } return null; }
public override ByteSlice Eval(out DbType type) { DbValue ret = Context.ExecDbFunction(funcname, args); return ret.Eval(out type); }
public override ByteSlice Eval(out DbType type) { type = this._type; return _value; }
public ImmediateValue(IValueContext Context, ByteSlice value, DbType type) : base(Context) { this._value = value; this._type = type; }
public override ByteSlice Eval(out DbType type) { type = col.Type; return ByteSlice.Prepare(Context.CurrentRow, col.RowOffset, col.Type.Size); }
public abstract ByteSlice Eval(out DbType type);
static int DisplayWidthFromType(DbType type) { switch (type.ID) { case DbTypeID.INT: return 10; case DbTypeID.LONG: return 20; case DbTypeID.DOUBLE: return 20; case DbTypeID.DATETIME: return 22; case DbTypeID.CHARS: if (type.Size <= 1) { return 0; } return (type.Size - 1) / 2; case DbTypeID.NULL: return 4; // Word "NULL". default: //throw new InvalidOperationException("Unknown type width: " + type.Name); return 10; // ? } }
static int DisplayWidthFromType(DbType type, out string sdw) { int dw = DisplayWidthFromType(type); switch (dw) { case 10: sdw = "10"; break; case 20: sdw = "20"; break; case 22: sdw = "22"; break; case 4: sdw = "4"; break; default: sdw = dw.ToString(); break; } return dw; }
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(); }
public DbValue AllocValue(ByteSlice value, DbType type) { if (curval >= values.Count) { ImmediateValue val = new ImmediateValue(null, value, type); values.Add(val); curval++; return val; } else { ImmediateValue val = values[curval++]; val._value = value; val._type = type; return val; } }