예제 #1
0
        /// <summary>
        ///    Builds a cell or row query URI.
        /// </summary>
        /// <param name="query"></param>
        public string BuildCellOrRowQuery(CellQuery query)
        {
            if (!query.CanDescribeTable())
            {
                throw new ArgumentException(Resources.ResourceBuilder_MinimumForCellOrRowQueryNotMet);
            }

            return BuildFromCellQuery(query).ToString();
        }
예제 #2
0
        private static StringBuilder BuildFromCellQuery(CellQuery query)
        {
            bool hasTimestamp = query.EndTimestamp.HasValue
                && (!query.BeginTimestamp.HasValue || query.BeginTimestamp.Value < query.EndTimestamp.Value);

            StringBuilder uriBuilder = BuildFromDescriptor(query);

            bool columnsMissing = query.Cells == null || query.Cells.All(cell => string.IsNullOrEmpty(cell.Column));
            if (columnsMissing && !hasTimestamp)
            {
                return SetMaxVersions(query.MaxVersions, uriBuilder);
            }

            if (!columnsMissing)
            {
                HBaseCellDescriptor[] validCells = query.Cells.Where(cell => !string.IsNullOrEmpty(cell.Column)).ToArray();

                HBaseCellDescriptor firstCell = validCells.First();
                uriBuilder.AppendFormat(_appendSegmentFormat, firstCell.Column);

                if (!string.IsNullOrEmpty(firstCell.Qualifier))
                {
                    uriBuilder.AppendFormat(_appendQualifierFormat, firstCell.Qualifier);
                }

                foreach (HBaseCellDescriptor cell in validCells.Skip(1))
                {
                    uriBuilder.AppendFormat(_appendRangeFormat, cell.Column);
                    if (!string.IsNullOrEmpty(cell.Qualifier))
                    {
                        uriBuilder.AppendFormat(_appendQualifierFormat, cell.Qualifier);
                    }
                }
            }
            else
            {
                uriBuilder.AppendFormat(_appendSegmentFormat, _wildCard);
            }

            if (hasTimestamp)
            {
                if (query.BeginTimestamp.HasValue)
                {
                    uriBuilder.AppendFormat(_appendSegmentFormat, query.BeginTimestamp);
                    uriBuilder.AppendFormat(_appendRangeFormat, query.EndTimestamp);
                }
                else
                {
                    uriBuilder.AppendFormat(_appendSegmentFormat, query.EndTimestamp);
                }
            }

            return SetMaxVersions(query.MaxVersions, uriBuilder);
        }
예제 #3
0
		/// <summary>
		///    Finds the cells matching the query.
		/// </summary>
		/// <param name="query"></param>
		public CellSet FindCells(CellQuery query)
		{
			string resource = _resourceBuilder.BuildCellOrRowQuery(query);
			IRestResponse response = SendRequest(Method.GET, resource, Options.ContentType);
			_errorProvider.ThrowIfStatusMismatch(response, HttpStatusCode.OK, HttpStatusCode.NotFound);

			var set = new CellSet
			{
				Table = query.Table
			};

			if (response.StatusCode == HttpStatusCode.OK)
				set.AddRange(_converter.ConvertCells(response.Content, query.Table));

			return set;
		}