Exemplo n.º 1
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));
        }
Exemplo n.º 2
0
        private XElement XmlForCell(Cell cell)
        {
            Identifier          identifier     = cell.Identifier;
            HBaseCellDescriptor cellDescriptor = identifier != null ? identifier.CellDescriptor : null;
            string column    = cellDescriptor != null ? cellDescriptor.Column : null;
            string qualifier = cellDescriptor != null ? cellDescriptor.Qualifier : null;
            long?  timestamp = identifier != null ? identifier.Timestamp : null;

            var cellXml = new XElement(_cellName, new XText(_codec.Encode(cell.Value)));

            if (!string.IsNullOrEmpty(column))
            {
                cellXml.Add(new XAttribute(_columnName, _codec.Encode(string.Format(_columnFormat, column, qualifier))));
            }
            if (timestamp.HasValue)
            {
                cellXml.Add(new XAttribute(_timestampName, timestamp.Value));
            }

            return(cellXml);
        }