예제 #1
0
        public void SingleExpression()
        {
            // arrange
            string key         = "test";
            int    count       = 20;
            var    columnName  = "test-column";
            var    columnValue = "test-value";

            // act
            var index = new CassandraIndexClause <BytesType>(
                key,
                count,
                family => family[columnName] == columnValue);
            var expressions = index.CompiledExpressions;

            // assert
            Assert.AreEqual(1, expressions.Count);

            var firstExpression = expressions[0];

            Assert.IsNotNull(firstExpression);
            Assert.AreEqual((BytesType)firstExpression.Column_name, (BytesType)columnName);
            Assert.AreEqual(firstExpression.Op, IndexOperator.EQ);
            Assert.AreEqual((BytesType)firstExpression.Value, (BytesType)columnValue);
        }
예제 #2
0
        public void SingleExpression()
        {
            // arrange
            string key         = "test";
            int    count       = 20;
            var    columnName  = "test-column";
            var    columnValue = "test-value";

            // act
            var index = new CassandraIndexClause(
                key,
                count,
                family => family[columnName] == columnValue);
            var expressions = index.CompiledExpressions;

            // assert
            Assert.Equal(1, expressions.Count);

            var firstExpression = expressions[0];

            Assert.NotNull(firstExpression);
            Assert.Equal(CassandraObject.GetCassandraObjectFromDatabaseByteArray(firstExpression.Column_name, typeof(BytesType)), (BytesType)columnName);
            Assert.Equal(firstExpression.Op, IndexOperator.EQ);
            Assert.Equal(CassandraObject.GetCassandraObjectFromDatabaseByteArray(firstExpression.Value, typeof(BytesType)), (BytesType)columnValue);
        }
예제 #3
0
        public void TwoExpressions()
        {
            // arrange
            string key          = "test";
            int    count        = 20;
            var    columnName1  = "test1-column";
            var    columnValue1 = "test1-value";
            var    columnName2  = "test2-column";
            var    columnValue2 = Math.PI;

            // act
            var index = new CassandraIndexClause(
                key,
                count,
                family => family[columnName1] == columnValue1 &&
                family[columnName2] > columnValue2);
            var expressions = index.CompiledExpressions;

            // assert
            Assert.Equal(2, expressions.Count);

            var firstExpression = expressions[0];

            Assert.NotNull(firstExpression);
            Assert.Equal(CassandraObject.GetCassandraObjectFromDatabaseByteArray(firstExpression.Column_name, typeof(BytesType)), (BytesType)columnName1);
            Assert.Equal(firstExpression.Op, IndexOperator.EQ);
            Assert.Equal(CassandraObject.GetCassandraObjectFromDatabaseByteArray(firstExpression.Value, typeof(BytesType)), (BytesType)columnValue1);

            var secondExpression = expressions[1];

            Assert.Equal(CassandraObject.GetCassandraObjectFromDatabaseByteArray(secondExpression.Column_name, typeof(BytesType)), (BytesType)columnName2);
            Assert.Equal(secondExpression.Op, IndexOperator.GT);
            Assert.Equal(CassandraObject.GetCassandraObjectFromDatabaseByteArray(secondExpression.Value, typeof(BytesType)), (BytesType)columnValue2);
        }
예제 #4
0
 public static IndexClause CreateIndexClause(CassandraIndexClause index)
 {
     return(new IndexClause {
         Start_key = index.StartKey.TryToBigEndian(),
         Count = index.Count,
         Expressions = index.CompiledExpressions
     });
 }
		public List<Apache.Cassandra.KeySlice> get_indexed_slices(CassandraColumnParent column_parent, CassandraIndexClause index_clause, CassandraSlicePredicate column_predicate, Apache.Cassandra.ConsistencyLevel consistency_level)
		{
			return _client.get_indexed_slices(
				Helper.CreateColumnParent(column_parent),
				Helper.CreateIndexClause(index_clause),
				Helper.CreateSlicePredicate(column_predicate),
				consistency_level);
		}
예제 #6
0
		public static IndexClause CreateIndexClause(CassandraIndexClause index)
		{
			return new IndexClause {
				Start_key = index.StartKey.TryToBigEndian(),
				Count = index.Count,
				Expressions = index.CompiledExpressions
			};
		}
예제 #7
0
        private static object BuildOperation <TResult>(CassandraQuerySetup setup, CassandraSlicePredicate predicate, IDictionary <string, object> calls)
        {
            if (calls.ContainsKey("CountColumnsByKey"))
            {
                return(new MultiGetColumnCount(setup.Keys, setup.SuperColumnName, predicate));
            }

            if (calls.ContainsKey("CountColumns"))
            {
                return(new ColumnCount(setup.Keys.First(), setup.SuperColumnName, predicate));
            }

            var forSuperColumn = typeof(TResult) == typeof(FluentSuperColumnFamily);

            if (!forSuperColumn && setup.SuperColumnName != null)
            {
                throw new CassandraException("'ForSuperColumn' can only be used on a super column family.");
            }

            if (forSuperColumn)
            {
                if (setup.IndexClause != null)
                {
                    var indexClause = new CassandraIndexClause(setup.StartKey, setup.ColumnCount, setup.IndexClause);
                    return(new GetSuperColumnFamilyIndexedSlices(indexClause, predicate));
                }
                else if (setup.Keys.Count() > 0)
                {
                    return(new MultiGetSuperColumnFamilySlice(setup.Keys, setup.SuperColumnName, predicate));
                }
                else
                {
                    var keyRange = new CassandraKeyRange(setup.StartKey, setup.EndKey, setup.StartToken, setup.EndToken, setup.KeyCount);
                    return(new GetSuperColumnFamilyRangeSlices(keyRange, setup.SuperColumnName, predicate));
                }
            }
            else
            {
                if (setup.IndexClause != null)
                {
                    var indexClause = new CassandraIndexClause(setup.StartKey, setup.KeyCount, setup.IndexClause);
                    return(new GetColumnFamilyIndexedSlices(indexClause, predicate));
                }
                else if (setup.Keys.Count() > 0)
                {
                    return(new MultiGetColumnFamilySlice(setup.Keys, predicate));
                }
                else
                {
                    var keyRange = new CassandraKeyRange(setup.StartKey, setup.EndKey, setup.StartToken, setup.EndToken, setup.KeyCount);
                    return(new GetColumnFamilyRangeSlices(keyRange, predicate));
                }
            }
        }
예제 #8
0
        public void StartKeySet()
        {
            // arrange
            string key         = "test";
            int    count       = 20;
            string columnName  = "test-column";
            string columnValue = "test-value";

            // act
            var index = new CassandraIndexClause(
                key,
                count,
                family => family[columnName] == columnValue);

            // assert
            Assert.Same((string)index.StartKey, key);
        }
        public void CountSet()
        {
            // arrange
            string key = "test";
            int count = 20;
            string columnName = "test-column";
            string columnValue = "test-value";

            // act
            var index = new CassandraIndexClause(
                key,
                count,
                family => family[columnName] == columnValue);

            // assert
            Assert.Equal(index.Count, count);
        }
예제 #10
0
        public void CountSet()
        {
            // arrange
            string key         = "test";
            int    count       = 20;
            string columnName  = "test-column";
            string columnValue = "test-value";

            // act
            var index = new CassandraIndexClause(
                key,
                count,
                family => family[columnName] == columnValue);

            // assert
            Assert.Equal(index.Count, count);
        }
		public void StartKeySet()
		{
			// arrange
			string key = "test";
			int count = 20;
			string columnName = "test-column";
			string columnValue = "test-value";

			// act
			var index = new CassandraIndexClause(
				key,
				count,
				family => family[columnName] == columnValue);

			// assert
			Assert.Same((string)index.StartKey, key);
		}
예제 #12
0
        public void ThreeExpressions()
        {
            // arrange
            string key          = "test";
            int    count        = 20;
            var    columnName1  = "test1-column";
            var    columnValue1 = "test1-value";
            var    columnName2  = "test2-column";
            var    columnValue2 = Math.PI;
            var    columnName3  = new DateTimeOffset(1980, 3, 14, 0, 0, 0, TimeSpan.Zero);
            var    columnValue3 = Math.PI;

            // act
            var index = new CassandraIndexClause <BytesType>(
                key,
                count,
                family => family[columnName1] == columnValue1 &&
                family[columnName2] > columnValue2 &&
                family[columnName3] <= columnValue3);
            var expressions = index.CompiledExpressions;

            // assert
            Assert.AreEqual(3, expressions.Count);

            var firstExpression = expressions[0];

            Assert.IsNotNull(firstExpression);
            Assert.AreEqual((BytesType)firstExpression.Column_name, (BytesType)columnName1);
            Assert.AreEqual(firstExpression.Op, IndexOperator.EQ);
            Assert.AreEqual((BytesType)firstExpression.Value, (BytesType)columnValue1);

            var secondExpression = expressions[1];

            Assert.AreEqual((BytesType)secondExpression.Column_name, (BytesType)columnName2);
            Assert.AreEqual(secondExpression.Op, IndexOperator.GT);
            Assert.AreEqual((BytesType)secondExpression.Value, (BytesType)columnValue2);

            var thridExpression = expressions[2];

            Assert.AreEqual((BytesType)thridExpression.Column_name, (BytesType)columnName3);
            Assert.AreEqual(thridExpression.Op, IndexOperator.LTE);
            Assert.AreEqual((BytesType)thridExpression.Value, (BytesType)columnValue3);
        }
        public void GreaterThanExpression()
        {
            // arrange
            string key = "test";
            int count = 20;
            var columnName = "test-column";
            var columnValue = Math.PI;

            // act
            var index = new CassandraIndexClause<BytesType>(
                key,
                count,
                family => family[columnName] > columnValue);
            var expressions = index.CompiledExpressions;

            // assert
            Assert.AreEqual(1, expressions.Count);

            var firstExpression = expressions[0];
            Assert.IsNotNull(firstExpression);
            Assert.AreEqual((BytesType)firstExpression.Column_name, (BytesType)columnName);
            Assert.AreEqual(firstExpression.Op, IndexOperator.GT);
            Assert.AreEqual((BytesType)firstExpression.Value, (BytesType)columnValue);
        }
        public void GreaterThanExpression()
        {
            // arrange
            string key = "test";
            int count = 20;
            var columnName = "test-column";
            var columnValue = Math.PI;

            // act
            var index = new CassandraIndexClause(
                key,
                count,
                family => family[columnName] > columnValue);
            var expressions = index.CompiledExpressions;

            // assert
            Assert.Equal(1, expressions.Count);

            var firstExpression = expressions[0];
            Assert.NotNull(firstExpression);
            Assert.Equal(CassandraObject.GetCassandraObjectFromDatabaseByteArray(firstExpression.Column_name, typeof(BytesType)), (BytesType)columnName);
            Assert.Equal(firstExpression.Op, IndexOperator.GT);
            Assert.Equal(CassandraObject.GetCassandraObjectFromDatabaseByteArray(firstExpression.Value, typeof(BytesType)), (BytesType)columnValue);
        }
 public GetColumnFamilyIndexedSlices(CassandraIndexClause indexClause, CassandraSlicePredicate columnSlicePredicate)
 {
     IndexClause    = indexClause;
     SlicePredicate = columnSlicePredicate;
 }
        public void TwoExpressions()
        {
            // arrange
            string key = "test";
            int count = 20;
            var columnName1 = "test1-column";
            var columnValue1 = "test1-value";
            var columnName2 = "test2-column";
            var columnValue2 = Math.PI;

            // act
            var index = new CassandraIndexClause(
                key,
                count,
                family => family[columnName1] == columnValue1
                    && family[columnName2] > columnValue2);
            var expressions = index.CompiledExpressions;

            // assert
            Assert.Equal(2, expressions.Count);

            var firstExpression = expressions[0];
            Assert.NotNull(firstExpression);
            Assert.Equal(CassandraObject.GetCassandraObjectFromDatabaseByteArray(firstExpression.Column_name, typeof(BytesType)), (BytesType)columnName1);
            Assert.Equal(firstExpression.Op, IndexOperator.EQ);
            Assert.Equal(CassandraObject.GetCassandraObjectFromDatabaseByteArray(firstExpression.Value, typeof(BytesType)), (BytesType)columnValue1);

            var secondExpression = expressions[1];
            Assert.Equal(CassandraObject.GetCassandraObjectFromDatabaseByteArray(secondExpression.Column_name, typeof(BytesType)), (BytesType)columnName2);
            Assert.Equal(secondExpression.Op, IndexOperator.GT);
            Assert.Equal(CassandraObject.GetCassandraObjectFromDatabaseByteArray(secondExpression.Value, typeof(BytesType)), (BytesType)columnValue2);
        }
        public void SingleExpression()
        {
            // arrange
            string key = "test";
            int count = 20;
            var columnName = "test-column";
            var columnValue = "test-value";

            // act
            var index = new CassandraIndexClause(
                key,
                count,
                family => family[columnName] == columnValue);
            var expressions = index.CompiledExpressions;

            // assert
            Assert.AreEqual(1, expressions.Count);

            var firstExpression = expressions[0];
            Assert.IsNotNull(firstExpression);
            Assert.AreEqual(CassandraObject.GetTypeFromDatabaseValue(firstExpression.Column_name, typeof(BytesType)), (BytesType)columnName);
            Assert.AreEqual(firstExpression.Op, IndexOperator.EQ);
            Assert.AreEqual(CassandraObject.GetTypeFromDatabaseValue(firstExpression.Value, typeof(BytesType)), (BytesType)columnValue);
        }
예제 #18
0
 public List <Apache.Cassandra.KeySlice> get_indexed_slices(CassandraColumnParent column_parent, CassandraIndexClause index_clause, CassandraSlicePredicate column_predicate, Apache.Cassandra.ConsistencyLevel consistency_level)
 {
     return(_client.get_indexed_slices(
                Helper.CreateColumnParent(column_parent),
                Helper.CreateIndexClause(index_clause),
                Helper.CreateSlicePredicate(column_predicate),
                consistency_level));
 }
        public void ThreeExpressions()
        {
            // arrange
            string key = "test";
            int count = 20;
            var columnName1 = "test1-column";
            var columnValue1 = "test1-value";
            var columnName2 = "test2-column";
            var columnValue2 = Math.PI;
            var columnName3 = new DateTimeOffset(1980, 3, 14, 0, 0, 0, TimeSpan.Zero);
            var columnValue3 = Math.PI;

            // act
            var index = new CassandraIndexClause(
                key,
                count,
                family => family[columnName1] == columnValue1
                    && family[columnName2] > columnValue2
                    && family[columnName3] <= columnValue3);
            var expressions = index.CompiledExpressions;

            // assert
            Assert.AreEqual(3, expressions.Count);

            var firstExpression = expressions[0];
            Assert.IsNotNull(firstExpression);
            Assert.AreEqual(CassandraObject.GetTypeFromDatabaseValue(firstExpression.Column_name, typeof(BytesType)), (BytesType)columnName1);
            Assert.AreEqual(firstExpression.Op, IndexOperator.EQ);
            Assert.AreEqual(CassandraObject.GetTypeFromDatabaseValue(firstExpression.Value, typeof(BytesType)), (BytesType)columnValue1);

            var secondExpression = expressions[1];
            Assert.AreEqual(CassandraObject.GetTypeFromDatabaseValue(secondExpression.Column_name, typeof(BytesType)), (BytesType)columnName2);
            Assert.AreEqual(secondExpression.Op, IndexOperator.GT);
            Assert.AreEqual(CassandraObject.GetTypeFromDatabaseValue(secondExpression.Value, typeof(BytesType)), (BytesType)columnValue2);

            var thirdExpression = expressions[2];
            Assert.AreEqual(CassandraObject.GetTypeFromDatabaseValue(thirdExpression.Column_name, typeof(BytesType)), (BytesType)columnName3);
            Assert.AreEqual(secondExpression.Op, IndexOperator.GT);
            Assert.AreEqual(CassandraObject.GetTypeFromDatabaseValue(thirdExpression.Value, typeof(BytesType)), (BytesType)columnValue3);
        }
 public GetSuperColumnIndexedSlices(CassandraIndexClause indexClause, CassandraType superColumnName, CassandraSlicePredicate columnSlicePredicate)
 {
     IndexClause     = indexClause;
     SuperColumnName = superColumnName;
     SlicePredicate  = columnSlicePredicate;
 }