internal static Cell FromTsCell(TsCell tsc) { if (tsc.boolean_valueSpecified) { return(new Cell <bool>(tsc.boolean_value)); } else if (tsc.double_valueSpecified) { return(new Cell <double>(tsc.double_value)); } else if (tsc.sint64_valueSpecified) { return(new Cell <long>(tsc.sint64_value)); } else if (tsc.timestamp_valueSpecified) { return(new Cell <DateTime>( DateTimeUtil.FromUnixTimeMillis(tsc.timestamp_value))); } else if (tsc.varchar_valueSpecified) { return(new Cell <string>(RiakString.FromBytes(tsc.varchar_value))); } return(new Cell()); }
internal static Cell FromTsCell(TsCell tsc, TsColumnType tsct) { if (tsc.boolean_valueSpecified) { return(new Cell(tsc.boolean_value)); } else if (tsc.double_valueSpecified) { return(new Cell(tsc.double_value)); } else if (tsc.sint64_valueSpecified) { return(new Cell(tsc.sint64_value)); } else if (tsc.timestamp_valueSpecified) { return(new Cell(tsc.timestamp_value, isUnixTimestamp: true)); } else if (tsc.varchar_valueSpecified) { switch (tsct) { case TsColumnType.BLOB: return(new Cell(tsc.varchar_value, ColumnType.Blob)); case TsColumnType.VARCHAR: return(new Cell(tsc.varchar_value, ColumnType.Varchar)); default: return(new Cell(tsc.varchar_value, ColumnType.Varchar)); } } return(new Cell()); }
public void Are_Equatable() { TsCell c0 = new TsCell { boolean_value = Boolean0 }; TsCell c1 = new TsCell { boolean_value = Boolean0 }; Assert.AreEqual(c0, c1, string.Format("c0 {0} c1 {1}", c0, c1)); c0 = new TsCell { double_value = Double0 }; c1 = new TsCell { double_value = Double0 }; Assert.AreEqual(c0, c1, string.Format("c0 {0} c1 {1}", c0, c1)); c0 = new TsCell { sint64_value = Long0 }; c1 = new TsCell { sint64_value = Long0 }; Assert.AreEqual(c0, c1, string.Format("c0 {0} c1 {1}", c0, c1)); var ut = DateTimeUtil.ToUnixTimeMillis(Timestamp0); c0 = new TsCell { timestamp_value = ut }; c1 = new TsCell { timestamp_value = ut }; Assert.AreEqual(c0, c1, string.Format("c0 {0} c1 {1}", c0, c1)); c0 = new TsCell { varchar_value = RiakString.ToBytes(Varchar0) }; c1 = new TsCell { varchar_value = RiakString.ToBytes(Varchar0) }; Assert.AreEqual(c0, c1, string.Format("c0 {0} c1 {1}", c0, c1)); c0 = new TsCell { varchar_value = Blob0 }; c1 = new TsCell { varchar_value = Blob0 }; Assert.AreEqual(c0, c1, string.Format("c0 {0} c1 {1}", c0, c1)); }
internal Row(TsRow tsr, TsColumnDescription[] tscols = null) { Cell[] cary = new Cell[tsr.cells.Count]; for (int i = 0; i < tsr.cells.Count; ++i) { TsCell tsc = tsr.cells[i]; TsColumnType tsct = TsColumnType.VARCHAR; if (EnumerableUtil.NotNullOrEmpty(tscols)) { tsct = tscols[i].type; } Cell c = Cell.FromTsCell(tsc, tsct); cary[i] = c; } cells = cary; }
internal override TsCell ToTsCell() { TsCell rv = null; if (ReferenceEquals(null, v)) { throw new InvalidOperationException("typed Cells require a non-null value"); } if (vtype == typeof(string)) { rv = new TsCell { varchar_value = RiakString.ToBytes((string)Convert.ChangeType(v, TypeCode.String)) }; } else if (vtype == typeof(byte[])) { var bytes = (byte[])AsObject; rv = new TsCell { varchar_value = bytes }; } else if (IsIntegerType(vtype)) { rv = new TsCell { sint64_value = (long)Convert.ChangeType(v, TypeCode.Int64) }; } else if (vtype == typeof(DateTime)) { var dt = (DateTime)Convert.ChangeType(v, TypeCode.DateTime); rv = new TsCell { timestamp_value = DateTimeUtil.ToUnixTimeMillis(dt) }; } else if (vtype == typeof(bool)) { rv = new TsCell { boolean_value = (bool)Convert.ChangeType(v, TypeCode.Boolean) }; } else if (IsDoubleType(vtype)) { rv = new TsCell { double_value = (double)Convert.ChangeType(v, TypeCode.Double) }; } else { string msg = string.Format("could not convert {0}, type: {1}", v.ToString(), v.GetType().Name); throw new InvalidOperationException(msg); } return(rv); }
public void Should_Parse_Resp() { var rsp = new TsGetResp(); rsp.columns.AddRange(TsCols); rsp.rows.AddRange(TsRows); Get cmd = BuildGetReqWithTimeout(); cmd.OnSuccess(rsp); GetResponse response = cmd.Response; var rcols = response.Columns.ToArray(); CollectionAssert.AreEqual(Columns, rcols); var rr = response.Value.ToArray(); for (int i = 0; i < rr.Length; i++) { TsRow tsr = TsRows[i]; TsCell[] tscs = tsr.cells.ToArray(); Row r = rr[i]; Cell[] rcs = r.Cells.ToArray(); Assert.AreEqual(tsr.cells.Count, rcs.Length); for (int j = 0; j < tscs.Length; j++) { TsCell tsc = tscs[j]; Cell c = rcs[j]; if (tsc.boolean_valueSpecified) { Assert.AreEqual(tsc.boolean_value, c.Value); } else if (tsc.double_valueSpecified) { Assert.AreEqual(tsc.double_value, c.Value); } else if (tsc.sint64_valueSpecified) { Assert.AreEqual(tsc.sint64_value, c.Value); } else if (tsc.timestamp_valueSpecified) { Assert.AreEqual( tsc.timestamp_value, c.Value); } else if (tsc.varchar_valueSpecified) { byte[] tsc_val = tsc.varchar_value; byte[] cell_val = (byte[])c.Value; CollectionAssert.AreEqual(tsc_val, cell_val); } else { Assert.Fail(); } } } }