예제 #1
0
        public void selectByKeyNoIndex()
        {
            // Execute the Query
            Statement stmt = new Statement();
            stmt.Namespace = TestQueryEngine.NAMESPACE;
            stmt.SetName = SET;

            Qualifier qual1 = new Qualifier(mapBinNoIndex, Qualifier.FilterOperation.MAP_KEYS_CONTAINS, Value.Get("dogs7"));
            KeyRecordEnumerator it = queryEngine.Select(stmt, qual1);
            int count2 = 0;
            try
            {
                while (it.MoveNext())
                {
                    KeyRecord rec = it.Current;
                    Dictionary<string, Object> map = (Dictionary<string, Object>)rec.record.GetMap(mapBinNoIndex);
                    Assert.True(map.ContainsKey("dogs7"));
                    count2++;
                }
            }
            finally
            {
                it.Close();
            }
        }
예제 #2
0
 public void deleteStartsWith()
 {
     Qualifier qual1 = new Qualifier("color", Qualifier.FilterOperation.ENDS_WITH, Value.Get("e"));
     Statement stmt = new Statement();
     stmt.Namespace = TestQueryEngine.NAMESPACE;
     stmt.SetName = TestQueryEngine.SET_NAME;
     IDictionary<string, long> counts = queryEngine.Delete(stmt, qual1);
     Assert.AreEqual(400L, counts["read"]);
     Assert.AreEqual(400L, counts["write"]);
 }
예제 #3
0
 public void selectEndsWith()
 {
     Qualifier qual1 = new Qualifier("color", Qualifier.FilterOperation.EQ, Value.Get("blue"));
     Qualifier qual2 = new Qualifier("name", Qualifier.FilterOperation.START_WITH, Value.Get("na"));
     KeyRecordEnumerator it = queryEngine.Select(TestQueryEngine.NAMESPACE, TestQueryEngine.SET_NAME, null, qual1, qual2);
     try
     {
         while (it.MoveNext())
         {
             KeyRecord rec = it.Current;
             Assert.Equals("blue", rec.record.GetString("color"));
             Assert.True(rec.record.GetString("name").StartsWith("na"));
         }
     }
     finally
     {
         it.Close();
     }
 }
예제 #4
0
        public void selectByKey()
        {
            // Execute the Query
            Statement stmt = new Statement();
            stmt.Namespace = TestQueryEngine.NAMESPACE;
            stmt.SetName = SET;
            stmt.SetFilters(Filter.Contains(mapBin, IndexCollectionType.MAPKEYS, "dogs7"));
            int count = 0;
            RecordSet recordSet = client.Query(null, stmt);
            try
            {
                Console.WriteLine("\nRecords with map keys equal to dogs7:");
                while (recordSet != null & recordSet.Next())
                {
                    //Console.WriteLine("\t" + recordSet.getKey().userKey);
                    count++;
                }
            }
            finally
            {
                if (recordSet != null) recordSet.Close();
            }
            Console.WriteLine("\t" + count);

            Qualifier qual1 = new Qualifier(mapBin, Qualifier.FilterOperation.MAP_KEYS_CONTAINS, Value.Get("dogs7"));
            KeyRecordEnumerator it = queryEngine.Select(stmt, qual1);
            int count2 = 0;
            try
            {
                while (it.MoveNext())
                {
                    KeyRecord rec = it.Current;
                    Dictionary<string, Object> map = (Dictionary<string, Object>)rec.record.GetMap(mapBin);
                    Assert.True(map.ContainsKey("dogs7"));
                    count2++;
                }
            }
            finally
            {
                it.Close();
            }
            Assert.Equals(count, count2);
        }
예제 #5
0
        public void deleteWithFilter()
        {
            Key key = new Key(TestQueryEngine.NAMESPACE, TestQueryEngine.SET_NAME, "first-name-1");
            Bin firstNameBin = new Bin("first_name", "first-name-1");
            Bin lastNameBin = new Bin("last_name", "last-name-1");
            int age = 25;
            Bin ageBin = new Bin("age", age);
            this.client.Put(null, key, firstNameBin, lastNameBin, ageBin);

            Qualifier qual1 = new Qualifier("last_name", Qualifier.FilterOperation.EQ, Value.Get("last-name-1"));
            //DELETE FROM test.people WHERE last_name='last-name-1'
            Statement stmt = new Statement();
            stmt.Namespace = TestQueryEngine.NAMESPACE;
            stmt.SetName = TestQueryEngine.SET_NAME;
            IDictionary<string, long> counts = queryEngine.Delete(stmt, qual1);
            Assert.AreEqual(1L, counts["read"]);
            Assert.AreEqual(1L, counts["write"]);
            Record record = this.client.Get(null, key);
            Assert.Null(record);
        }
예제 #6
0
 public void selectOnIndexWithQualifiers()
 {
     IndexTask task = this.client.CreateIndex(null, TestQueryEngine.NAMESPACE, TestQueryEngine.SET_NAME, "age_index_selector", "age", IndexType.NUMERIC);
     task.Wait();
     Filter filter = Filter.Range("age", 25, 29);
     Qualifier qual1 = new Qualifier("color", Qualifier.FilterOperation.EQ, Value.Get("blue"));
     KeyRecordEnumerator it = queryEngine.Select(TestQueryEngine.NAMESPACE, TestQueryEngine.SET_NAME, filter, qual1);
     try
     {
         while (it.MoveNext())
         {
             KeyRecord rec = it.Current;
             Assert.Equals("blue", rec.record.GetString("color"));
             int age = rec.record.GetInt("age");
             Assert.True(age >= 25 && age <= 29);
         }
     }
     finally
     {
         it.Close();
     }
 }
예제 #7
0
 public void selectWithQualifiersOnly()
 {
     IndexTask task = this.client.CreateIndex(null, TestQueryEngine.NAMESPACE, TestQueryEngine.SET_NAME, "age_index", "age", IndexType.NUMERIC);
     task.Wait();
     queryEngine.refreshCluster();
     Qualifier qual1 = new Qualifier("color", Qualifier.FilterOperation.EQ, Value.Get("green"));
     Qualifier qual2 = new Qualifier("age", Qualifier.FilterOperation.BETWEEN, Value.Get(28), Value.Get(29));
     KeyRecordEnumerator it = queryEngine.Select(TestQueryEngine.NAMESPACE, TestQueryEngine.SET_NAME, null, qual1, qual2);
     try
     {
         while (it.MoveNext())
         {
             KeyRecord rec = it.Current;
             Assert.Equals("green", rec.record.GetString("color"));
             int age = rec.record.GetInt("age");
             Assert.True(age >= 28 && age <= 29);
         }
     }
     finally
     {
         it.Close();
     }
 }
예제 #8
0
        public void selectByValueEquals()
        {
            // Execute the Query
            Statement stmt = new Statement();
            stmt.Namespace = TestQueryEngine.NAMESPACE;
            stmt.SetName = SET;
            stmt.SetFilters(Filter.Contains(mapBin, IndexCollectionType.MAPVALUES, 310L));
            int count = 0;
            RecordSet recordSet = client.Query(null, stmt);
            try
            {
                while (recordSet != null & recordSet.Next())
                {
                    count++;
                }
            }
            finally
            {
                if (recordSet != null) recordSet.Close();
            }

            Qualifier qual1 = new Qualifier(mapBin, Qualifier.FilterOperation.MAP_VALUES_CONTAINS, Value.Get(310L));
            KeyRecordEnumerator it = queryEngine.Select(stmt, qual1);
            int count2 = 0;
            try
            {
                while (it.MoveNext())
                {
                    KeyRecord rec = it.Current;
                    Dictionary<string, long> map = (Dictionary<string, long>)rec.record.GetMap(mapBin);
                    Assert.True(map.ContainsValue(310L));
                    count2++;
                }
            }
            finally
            {
                it.Close();
            }
            Assert.Equals(count, count2);
        }
예제 #9
0
        public void selectByValueRange()
        {
            // Execute the Query
            Statement stmt = new Statement();
            stmt.Namespace = TestQueryEngine.NAMESPACE;
            stmt.SetName = SET;
            stmt.SetFilters(Filter.Range(mapBin, IndexCollectionType.MAPVALUES, 300, 350));
            int count = 0;
            RecordSet recordSet = client.Query(null, stmt);
            try
            {
                while (recordSet != null & recordSet.Next())
                {
                    count++;
                }
            }
            finally
            {
                if (recordSet != null) recordSet.Close();
            }

            Qualifier qual1 = new Qualifier(mapBin, Qualifier.FilterOperation.MAP_VALUES_BETWEEN, Value.Get(300), Value.Get(350));
            KeyRecordEnumerator it = queryEngine.Select(stmt, qual1);
            int count2 = 0;
            try
            {
                while (it.MoveNext())
                {
                    KeyRecord rec = it.Current;
                    Dictionary<string, long> map = (Dictionary<string, long>)rec.record.GetMap(mapBin);
                    bool found = false;
                    foreach (long value in map.Values)
                    {
                        if (value >= 300L && value <= 350L)
                        {
                            found = true;
                            break;
                        }
                    }
                    Assert.True(found);
                    count2++;
                }
            }
            finally
            {
                it.Close();
            }
            Assert.Equals(count, count2);
        }
예제 #10
0
        public void selectByValueRangeNoIndex()
        {
            // Execute the Query
            Statement stmt = new Statement();
            stmt.Namespace = TestQueryEngine.NAMESPACE;
            stmt.SetName = SET;

            Qualifier qual1 = new Qualifier(mapBinNoIndex, Qualifier.FilterOperation.MAP_VALUES_BETWEEN, Value.Get(300), Value.Get(350));
            KeyRecordEnumerator it = queryEngine.Select(stmt, qual1);
            int count2 = 0;
            try
            {
                while (it.MoveNext())
                {
                    KeyRecord rec = it.Current;
                    Dictionary<string, long> map = (Dictionary<string, long>)rec.record.GetMap(mapBinNoIndex);
                    bool found = false;
                    foreach (var value in map.Values)
                    {
                        if (value >= 300L && value <= 350L)
                        {
                            found = true;
                            break;
                        }
                    }
                    Assert.True(found);
                    count2++;
                }
            }
            finally
            {
                it.Close();
            }
        }
예제 #11
0
        private String buildFilterFunction(Qualifier[] qualifiers)
        {
            int count = 0;
            StringBuilder sb = new StringBuilder ("if ");
            for (int i = 0; i < qualifiers.Length; i++) {
                if (qualifiers [i] == null) //Skip nulls
                    continue;
                if (qualifiers [i] is KeyQualifier) //Skip primary key -- should not happen
                    continue;
                if (count > 0)
                    sb.Append (" and ");

                sb.Append (qualifiers [i].luaFilterString ());
                count++;
            }
            sb.Append (" then selectedRec = true end");
            return sb.ToString ();
        }
예제 #12
0
        protected bool isIndexedBin(Qualifier qualifier)
        {
            Qualifier.FilterOperation operation = qualifier.getOperation();
            if (operation != Qualifier.FilterOperation.EQ && operation != Qualifier.FilterOperation.BETWEEN)
                return false;

            if (this.indexCache.ContainsKey(qualifier.Field))
                return true;
            else
                return false;
        }
예제 #13
0
        public void selectByRange()
        {
            // Execute the Query
            Statement stmt = new Statement();
            stmt.Namespace = TestQueryEngine.NAMESPACE;
            stmt.SetName = SET;
            stmt.SetFilters(Filter.Range(listBin, IndexCollectionType.LIST, 300, 350));
            int count = 0;
            RecordSet recordSet = client.Query(null, stmt);
            try
            {
                while (recordSet != null & recordSet.Next())
                {
                    count++;
                }
            }
            finally
            {
                if (recordSet != null) recordSet.Close();
            }

            Qualifier qual1 = new Qualifier(listBin, Qualifier.FilterOperation.LIST_BETWEEN, Value.Get(300), Value.Get(350));
            Qualifier qual2 = new Qualifier(listBinNoIndex, Qualifier.FilterOperation.LIST_BETWEEN, Value.Get(300), Value.Get(350));
            KeyRecordEnumerator it = queryEngine.Select(stmt, qual1, qual2);
            int count2 = 0;
            try
            {
                while (it.MoveNext())
                {
                    KeyRecord rec = it.Current;
                    List<long> list = (List<long>)rec.record.GetList(listBin);
                    bool found = false;
                    if (list == null) Assert.Fail();
                    foreach (long value in list)
                    {
                        if (value >= 300L && value <= 350L)
                        {
                            found = true;
                            break;
                        }
                    }
                    Assert.True(found);
                    found = false;
                    List<long> list2 = (List<long>)rec.record.GetList(listBinNoIndex);
                    if (list2 == null) Assert.Fail();
                    foreach (long value in list2)
                    {
                        if (value >= 300L && value <= 350L)
                        {
                            found = true;
                            break;
                        }
                    }
                    Assert.True(found);
                    count2++;
                }
            }
            finally
            {
                it.Close();
            }
            Assert.Equals(count, count2);
        }
예제 #14
0
        public void selectNoIndexByValueEquals()
        {
            // Execute the Query
            Statement stmt = new Statement();
            stmt.Namespace = TestQueryEngine.NAMESPACE;
            stmt.SetName = SET;

            Qualifier qual1 = new Qualifier(listBinNoIndex, Qualifier.FilterOperation.LIST_CONTAINS, Value.Get(310L));
            KeyRecordEnumerator it = queryEngine.Select(stmt, qual1);
            int count2 = 0;
            try
            {
                while (it.MoveNext())
                {
                    KeyRecord rec = it.Current;
                    List<long> list = (List<long>)rec.record.GetList(listBinNoIndex);
                    Assert.True(list.Contains(310L));
                    count2++;
                }
            }
            finally
            {
                it.Close();
            }
        }
예제 #15
0
        public void selectByValueEquals()
        {
            // Execute the Query
            Statement stmt = new Statement();
            stmt.Namespace = TestQueryEngine.NAMESPACE;
            stmt.SetName = SET;
            stmt.SetFilters(Filter.Contains(listBin, IndexCollectionType.LIST, 310L));
            int count = 0;
            RecordSet recordSet = client.Query(null, stmt);
            try
            {
                while (recordSet != null & recordSet.Next())
                {
                    count++;
                }
            }
            finally
            {
                if (recordSet != null) recordSet.Close();
            }

            Qualifier qual1 = new Qualifier(listBin, Qualifier.FilterOperation.LIST_CONTAINS, Value.Get(310L));
            Qualifier qual2 = new Qualifier(listBinNoIndex, Qualifier.FilterOperation.LIST_CONTAINS, Value.Get(310L));
            KeyRecordEnumerator it = queryEngine.Select(stmt, qual1, qual2);
            int count2 = 0;
            try
            {
                while (it.MoveNext())
                {
                    KeyRecord rec = it.Current;
                    List<long> list = (List<long>)rec.record.GetList(listBin);
                    if (list == null) Assert.Fail();
                    Assert.True(list.Contains(310L));
                    List<long> list2 = (List<long>)rec.record.GetList(listBinNoIndex);
                    if (list2 == null) Assert.Fail();

                    count2++;
                }
            }
            finally
            {
                it.Close();
            }
            Assert.Equals(count, count2);
        }