Exemplo n.º 1
0
        public void PagingOnBoundStatementTest_PageOverZeroRows()
        {
            var    pageSize       = 10;
            var    totalRowLength = 11;
            string tableName      = CreateSimpleTableAndInsert(totalRowLength);

            // insert a guid that we'll keep track of
            Guid guid = Guid.NewGuid();

            string            statementToBeBound             = "SELECT * from " + tableName + " where id=?";
            PreparedStatement preparedStatementWithoutPaging = Session.Prepare(statementToBeBound);
            PreparedStatement preparedStatementWithPaging    = Session.Prepare(statementToBeBound);
            BoundStatement    boundStatemetWithoutPaging     = preparedStatementWithoutPaging.Bind(guid);
            BoundStatement    boundStatemetWithPaging        = preparedStatementWithPaging.Bind(guid);

            boundStatemetWithPaging.SetPageSize(pageSize);

            var rsWithPaging    = Session.Execute(boundStatemetWithPaging);
            var rsWithoutPaging = Session.Execute(boundStatemetWithoutPaging);

            //Check that the internal list of items count is pageSize
            Assert.AreEqual(0, rsWithPaging.InnerQueueCount);
            Assert.AreEqual(0, rsWithoutPaging.InnerQueueCount);

            var allTheRowsPaged = rsWithPaging.ToList();

            Assert.AreEqual(0, allTheRowsPaged.Count);
        }
Exemplo n.º 2
0
        private async Task<IEnumerable<ItemSignalsEntity>> GetSequenceInternalAsync(string itemId, SignalType signal, int pageSize, bool isAntiSequence)
        {
            string rowKey = BuildRowKey(itemId, signal);
            BoundStatement boundStatement = _getStatement.Value.Bind(rowKey, isAntiSequence);

            // setting properties
            boundStatement.SetPageSize(pageSize);

            RowSet rowset = await _session.Get().ExecuteAsync(boundStatement);
            return rowset.Select(r => _mapper.Map<Row, ItemSignalsEntity>(r));
        }
        public async Task <IEnumerable <TimeSeriesRollupsDayEntity> > GetSequenceAsync(string eventId, DateTime fromTime, DateTime toTime, int pageSize)
        {
            BoundStatement boundStatement = _getStatement.Value.Bind(eventId, fromTime, toTime);

            // setting properties
            boundStatement.SetPageSize(pageSize);

            RowSet rowset = await _session.Get().ExecuteAsync(boundStatement);

            return(rowset.Select(r => _mapper.Map <Row, TimeSeriesRollupsDayEntity>(r)));
        }
Exemplo n.º 4
0
        public async Task <IEnumerable <AffinityGroupItemCountsEntity> > GetSequenceAsync(string groupId, SignalType signal, int pageSize)
        {
            string         rowKey         = BuildRowKey(groupId, signal);
            BoundStatement boundStatement = _getStatement.Value.Bind(rowKey);

            // setting properties
            boundStatement.SetPageSize(pageSize);

            RowSet rowset = await _session.Get().ExecuteAsync(boundStatement);

            return(rowset.Select(r => _mapper.Map <Row, AffinityGroupItemCountsEntity>(r)));
        }
        public async Task <IEnumerable <TimeSeriesRawEntity> > GetHourlySequenceAsync(string eventId, DateTime fromTime, DateTime toTime, int pageSize)
        {
            if ((toTime - fromTime).Hours >= 1)
            {
                throw new NotSupportedException("Date range should be fully included in 1-hour bucket");
            }

            string         rowKey         = BuildRowKey(eventId, fromTime);
            BoundStatement boundStatement = _getStatement.Value.Bind(rowKey, fromTime, toTime);

            // setting properties
            boundStatement.SetPageSize(pageSize);

            RowSet rowset = await _session.Get().ExecuteAsync(boundStatement);

            return(rowset.Select(r => _mapper.Map <Row, TimeSeriesRawEntity>(r)));
        }
        /// <summary>
        /// Gets a list of unused YouTubeVideos with the page size specified.
        /// </summary>
        public async Task <List <YouTubeVideo> > GetUnusedVideos(int pageSize)
        {
            // Statement for getting unused videos from a source
            PreparedStatement prepared =
                await _statementCache.NoContext.GetOrAddAsync("SELECT * FROM sample_data_youtube_videos WHERE sourceid = ?");

            // Iterate the list of sources in random order
            var random  = new Random();
            var indexes = Enumerable.Range(0, YouTubeVideoSource.All.Count).OrderBy(_ => random.Next());

            // Build a list of unused videos from the available sources in random order
            var unusedVideos = new List <YouTubeVideo>();

            foreach (int idx in indexes)
            {
                YouTubeVideoSource source = YouTubeVideoSource.All[idx];

                // Use automatic paging to page through all the videos from the source
                BoundStatement bound = prepared.Bind(source.UniqueId);
                bound.SetPageSize(MaxVideosPerRequest);
                RowSet rowSet = await _session.ExecuteAsync(bound).ConfigureAwait(false);

                foreach (Row row in rowSet)
                {
                    var used = row.GetValue <bool?>("used");
                    if (used == false || used == null)
                    {
                        unusedVideos.Add(MapToYouTubeVideo(row, source, random));
                    }

                    // If we've got enough videos, return them
                    if (unusedVideos.Count == pageSize)
                    {
                        return(unusedVideos);
                    }
                }
            }

            // We were unable to fill the quota, so throw
            throw new InvalidOperationException("Unable to get unused videos.  Time to add more sources?");
        }
Exemplo n.º 7
0
        public void PagingOnBoundStatementTest()
        {
            var pageSize       = 10;
            var totalRowLength = 1003;
            Tuple <string, string> tableNameAndStaticKeyVal  = CreateTableWithCompositeIndexAndInsert(Session, totalRowLength);
            string            statementToBeBound             = "SELECT * from " + tableNameAndStaticKeyVal.Item1 + " where label=?";
            PreparedStatement preparedStatementWithoutPaging = Session.Prepare(statementToBeBound);
            PreparedStatement preparedStatementWithPaging    = Session.Prepare(statementToBeBound);
            BoundStatement    boundStatemetWithoutPaging     = preparedStatementWithoutPaging.Bind(tableNameAndStaticKeyVal.Item2);
            BoundStatement    boundStatemetWithPaging        = preparedStatementWithPaging.Bind(tableNameAndStaticKeyVal.Item2);

            boundStatemetWithPaging.SetPageSize(pageSize);

            var rsWithPaging    = Session.Execute(boundStatemetWithPaging);
            var rsWithoutPaging = Session.Execute(boundStatemetWithoutPaging);

            //Check that the internal list of items count is pageSize
            Assert.AreEqual(pageSize, rsWithPaging.InnerQueueCount);
            Assert.AreEqual(totalRowLength, rsWithoutPaging.InnerQueueCount);

            var allTheRowsPaged = rsWithPaging.ToList();

            Assert.AreEqual(totalRowLength, allTheRowsPaged.Count);
        }