/// <inheritdoc /> public async Task <bool> ReadNextBatch() { EnsureNotDisposed(); HttpResponseMessage response; using (var httpClient = CreateHttpClient()) { response = await httpClient.GetAsync(string.Empty); } if (!response.IsSuccessStatusCode) { throw new HBaseException("HBase 返回了表示操作不成功的 HTTP 状态码:" + response.StatusCode); } if (response.StatusCode == HttpStatusCode.NoContent) { // 返回的 HTTP 状态码为 204 No Content _batch = null; return(false); } var responseBody = await response.Content.ReadAsStringAsync(); var responseObject = HBaseSerializationHelper.DeserializeObject <HBaseRowWrapper>(responseBody); _batch = responseObject.Rows; return(true); }
public void ColumnDeserialization() { var json = "\"ZmFtaWx5OmNvbHVtbg==\""; var column = HBaseSerializationHelper.DeserializeObject <HBaseColumn>(json); Assert.Equal("family", column.ColumnFamilyName); Assert.Equal("column", column.ColumnName); }
public void CellDeserialization() { var json = "{\"column\":\"ZmFtaWx5OmNvbHVtbg==\",\"timestamp\":325,\"$\":\"aGVsbG8gd29ybGQ=\"}"; var cell = HBaseSerializationHelper.DeserializeObject <HBaseCell>(json); Assert.Equal(new HBaseColumn("family", "column"), cell.Column, new HBaseColumnEqualityComparer()); Assert.Equal(325, cell.Timestamp); Assert.Equal(Encoding.UTF8.GetBytes("hello world"), cell.Data); }
public void ColumnCollectionDeserialization() { var json = "[\"ZmFtaWx5MTpjb2x1bW4x\",\"ZmFtaWx5Mjpjb2x1bW4y\",\"ZmFtaWx5Mzpjb2x1bW4z\"]"; var columns = HBaseSerializationHelper.DeserializeObject <HBaseColumn[]>(json); Assert.Equal(new [] { new HBaseColumn("family1", "column1"), new HBaseColumn("family2", "column2"), new HBaseColumn("family3", "column3"), }, columns, new HBaseColumnEqualityComparer()); }
/// <inheritdoc /> public async Task <HBaseRow> Find(string tableName, string rowKey, HBaseFindOptions options = null) { if (tableName == null) { throw new ArgumentNullException(nameof(tableName)); } if (rowKey == null) { throw new ArgumentNullException(nameof(rowKey)); } var urlBuilder = new StringBuilder($"{tableName}/{rowKey}"); if (options?.Column != null) { urlBuilder.AppendFormat("/{0}", options.Column); } if (options?.Timestamp != null) { urlBuilder.AppendFormat("/{0}", options.Timestamp); } if (options?.NumberOfVersions != null) { urlBuilder.AppendFormat("?v={0}", options.NumberOfVersions); } var url = urlBuilder.ToString(); HttpResponseMessage response; using (var httpClient = CreateHttpClient()) { response = await httpClient.GetAsync(url); } if (!response.IsSuccessStatusCode) { throw new HBaseException("HBase REST API 返回了表示错误的 HTTP 状态码:" + response.StatusCode); } var responseBody = await response.Content.ReadAsStringAsync(); var data = HBaseSerializationHelper.DeserializeObject <HBaseRowWrapper>(responseBody); if (data.Rows == null || data.Rows.Count == 0) { return(null); } return(data.Rows[0]); }
public void RowCollectionDeserialization() { var json = "[{\"key\":\"cm93IGtleSAx\",\"Cell\":[{\"column\":\"ZmFtaWx5MTpjb2x1bW4x\",\"timestamp\":325,\"$\":\"aGVsbG8gd29ybGQ=\"},{\"column\":\"ZmFtaWx5Mjpjb2x1bW4y\",\"timestamp\":1015,\"$\":\"Z29vZGJ5ZSB3b3JsZA==\"}]},{\"key\":\"cm93IGtleSAy\",\"Cell\":[{\"column\":\"ZmFtaWx5Mzpjb2x1bW4z\",\"timestamp\":76,\"$\":\"5L2g5aW95LiW55WM\"},{\"column\":\"ZmFtaWx5NDpjb2x1bW40\",\"timestamp\":1111,\"$\":\"5YaN6KeB5LiW55WM\"}]}]"; var rows = HBaseSerializationHelper.DeserializeObject <HBaseRow[]>(json); var row1 = new HBaseRow { Key = "row key 1" }; row1.Cells.Add(new HBaseCell { Column = new HBaseColumn("family1", "column1"), Timestamp = 325, Data = Encoding.UTF8.GetBytes("hello world") }); row1.Cells.Add(new HBaseCell { Column = new HBaseColumn("family2", "column2"), Timestamp = 1015, Data = Encoding.UTF8.GetBytes("goodbye world") }); var row2 = new HBaseRow { Key = "row key 2" }; row2.Cells.Add(new HBaseCell { Column = new HBaseColumn("family3", "column3"), Timestamp = 76, Data = Encoding.UTF8.GetBytes("你好世界") }); row2.Cells.Add(new HBaseCell { Column = new HBaseColumn("family4", "column4"), Timestamp = 1111, Data = Encoding.UTF8.GetBytes("再见世界") }); Assert.Equal(new [] { row1, row2 }, rows, new HBaseRowEqualityComparer()); }
public void CellCollectionDeserialization() { var json = "[{\"column\":\"ZmFtaWx5MTpjb2x1bW4x\",\"timestamp\":325,\"$\":\"aGVsbG8gd29ybGQ=\"},{\"column\":\"ZmFtaWx5Mjpjb2x1bW4y\",\"timestamp\":1015,\"$\":\"Z29vZGJ5ZSB3b3JsZA==\"}]"; var cells = HBaseSerializationHelper.DeserializeObject <HBaseCell[]>(json); Assert.Equal(new [] { new HBaseCell { Column = new HBaseColumn("family1", "column1"), Timestamp = 325, Data = Encoding.UTF8.GetBytes("hello world") }, new HBaseCell { Column = new HBaseColumn("family2", "column2"), Timestamp = 1015, Data = Encoding.UTF8.GetBytes("goodbye world") } }, cells, new HBaseCellEqualityComparer()); }
public void RowDeserialization() { var json = "{\"key\":\"cm93IGtleQ==\",\"Cell\":[{\"column\":\"ZmFtaWx5MTpjb2x1bW4x\",\"timestamp\":325,\"$\":\"aGVsbG8gd29ybGQ=\"},{\"column\":\"ZmFtaWx5Mjpjb2x1bW4y\",\"timestamp\":1015,\"$\":\"Z29vZGJ5ZSB3b3JsZA==\"}]}"; var row = HBaseSerializationHelper.DeserializeObject <HBaseRow>(json); var expectedRow = new HBaseRow { Key = "row key" }; expectedRow.Cells.Add(new HBaseCell { Column = new HBaseColumn("family1", "column1"), Timestamp = 325, Data = Encoding.UTF8.GetBytes("hello world") }); expectedRow.Cells.Add(new HBaseCell { Column = new HBaseColumn("family2", "column2"), Timestamp = 1015, Data = Encoding.UTF8.GetBytes("goodbye world") }); Assert.Equal(expectedRow, row, new HBaseRowEqualityComparer()); }