public void MakeIndexes() { IndexTask task = Client.CreateIndex(Policy, Options.Namespace, Options.Set.Collection, "nameCollectionInd", "Name", IndexType.STRING); task.Wait(); task = Client.CreateIndex(Policy, Options.Namespace, Options.Set.User, "loginUserInd", "Login", IndexType.STRING); task.Wait(); }
public static void Prepare(TestContext testContext) { Assembly assembly = Assembly.GetExecutingAssembly(); RegisterTask rtask = client.Register(null, assembly, "Aerospike.Test.Resources.record_example.lua", "record_example.lua", Language.LUA); rtask.Wait(); Policy policy = new Policy(); policy.timeout = 0; // Do not timeout on index create. IndexTask task = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.STRING, IndexCollectionType.MAPKEYS); task.Wait(); for (int i = 1; i <= size; i++) { Key key = new Key(args.ns, args.set, keyPrefix + i); Dictionary <string, string> map = new Dictionary <string, string>(); map[mapKeyPrefix + 1] = mapValuePrefix + i; if (i % 2 == 0) { map[mapKeyPrefix + 2] = mapValuePrefix + i; } if (i % 3 == 0) { map[mapKeyPrefix + 3] = mapValuePrefix + i; } Bin bin = new Bin(binName, map); client.Put(null, key, bin); } }
public QueryKeyInit() { Policy policy = new Policy(); policy.totalTimeout = 0; // Do not timeout on index create. try { IndexTask itask = client.CreateIndex(policy, args.ns, args.set, TestQueryKey.indexName, TestQueryKey.binName, IndexType.NUMERIC); itask.Wait(); } catch (AerospikeException ae) { if (ae.Result != ResultCode.INDEX_ALREADY_EXISTS) { throw; } } WritePolicy writePolicy = new WritePolicy(); writePolicy.sendKey = true; for (int i = 1; i <= TestQueryKey.size; i++) { Key key = new Key(args.ns, args.set, TestQueryKey.keyPrefix + i); Bin bin = new Bin(TestQueryKey.binName, i); client.Put(writePolicy, key, bin); } }
public static void Prepare(TestContext testContext) { Assembly assembly = Assembly.GetExecutingAssembly(); RegisterTask rtask = client.Register(null, assembly, "Aerospike.Test.Resources.filter_example.lua", "filter_example.lua", Language.LUA); rtask.Wait(); Policy policy = new Policy(); policy.totalTimeout = 0; // Do not timeout on index create. try { IndexTask itask = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.STRING); itask.Wait(); } catch (AerospikeException ae) { if (ae.Result != ResultCode.INDEX_ALREADY_EXISTS) { throw; } } WriteRecord(keyPrefix + 1, "Charlie", "cpass"); WriteRecord(keyPrefix + 2, "Bill", "hknfpkj"); WriteRecord(keyPrefix + 3, "Doug", "dj6554"); }
public QueryExecuteInit() { Assembly assembly = typeof(QueryExecuteInit).GetTypeInfo().Assembly; RegisterTask rtask = client.Register(null, assembly, "AerospikeTest.record_example.lua", "record_example.lua", Language.LUA); rtask.Wait(); Policy policy = new Policy(); policy.totalTimeout = 0; // Do not timeout on index create. try { IndexTask itask = client.CreateIndex(policy, args.ns, args.set, TestQueryExecute.indexName, TestQueryExecute.binName1, IndexType.NUMERIC); itask.Wait(); } catch (AerospikeException ae) { if (ae.Result != ResultCode.INDEX_ALREADY_EXISTS) { throw; } } for (int i = 1; i <= TestQueryExecute.size; i++) { Key key = new Key(args.ns, args.set, TestQueryExecute.keyPrefix + i); client.Put(null, key, new Bin(TestQueryExecute.binName1, i), new Bin(TestQueryExecute.binName2, i)); } }
public static void Prepare(TestContext testContext) { Policy policy = new Policy(); policy.totalTimeout = 0; // Do not timeout on index create. try { IndexTask itask = client.CreateIndex(policy, args.ns, setName, indexName, binName, IndexType.NUMERIC); itask.Wait(); } catch (AerospikeException ae) { if (ae.Result != ResultCode.INDEX_ALREADY_EXISTS) { throw; } } // Write records with string keys for (int i = 1; i <= size; i++) { Key key = new Key(args.ns, setName, keyPrefix + i); List <int> list = null; Dictionary <string, string> map = null; if (i == 1) { list = new List <int>(5); list.Add(1); list.Add(2); list.Add(4); list.Add(9); list.Add(20); // map will be null, which means mapbin will not exist in this record. } else if (i == 2) { list = new List <int>(3); list.Add(5); list.Add(9); list.Add(100); // map will be null, which means mapbin will not exist in this record. } else if (i == 3) { map = new Dictionary <string, string>(); map["A"] = "AAA"; map["B"] = "BBB"; map["C"] = "BBB"; // list will be null, which means listbin will not exist in this record. } else { list = new List <int>(0); map = new Dictionary <string, string>(0); } client.Put(null, key, new Bin(binName, i), new Bin("bin2", i), new Bin("listbin", list), new Bin("mapbin", map)); } }
public static void Prepare(TestContext testContext) { Policy policy = new Policy(); policy.totalTimeout = 0; // Do not timeout on index create. try { IndexTask task = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.STRING); task.Wait(); } catch (AerospikeException ae) { if (ae.Result != ResultCode.INDEX_ALREADY_EXISTS) { throw; } } for (int i = 1; i <= size; i++) { Key key = new Key(args.ns, args.set, keyPrefix + i); Bin bin = new Bin(binName, valuePrefix + i); client.Put(null, key, bin); } }
public static void Prepare(TestContext testContext) { Assembly assembly = Assembly.GetExecutingAssembly(); RegisterTask rtask = client.Register(null, assembly, "Aerospike.Test.Resources.record_example.lua", "record_example.lua", Language.LUA); rtask.Wait(); Policy policy = new Policy(); policy.totalTimeout = 0; // Do not timeout on index create. try { IndexTask itask = client.CreateIndex(policy, args.ns, args.set, indexName, binName1, IndexType.NUMERIC); itask.Wait(); } catch (AerospikeException ae) { if (ae.Result != ResultCode.INDEX_ALREADY_EXISTS) { throw; } } for (int i = 1; i <= size; i++) { Key key = new Key(args.ns, args.set, keyPrefix + i); client.Put(null, key, new Bin(binName1, i), new Bin(binName2, i)); } }
public static void Prepare(TestContext testContext) { Policy policy = new Policy(); policy.timeout = 0; // Do not timeout on index create. IndexTask task = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.NUMERIC); task.Wait(); }
private static void CreateIndex(AerospikeClient client, string ns, string set, string indexName, string binName) { Console.WriteLine("Create index"); Policy policy = new Policy(); policy.SetTimeout(0); // Do not timeout on index create. IndexTask task = client.CreateIndex(policy, ns, set, indexName, binName, IndexType.NUMERIC); task.Wait(); }
private void CreateIndex(AsyncClient client, Arguments args, string indexName, string binName) { console.Info("Create index: ns=" + args.ns + " set=" + args.set + " index=" + indexName + " bin=" + binName); Policy policy = new Policy(); policy.timeout = 0; // Do not timeout on index create. IndexTask task = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.NUMERIC); task.Wait(); }
private void CreateIndex(AerospikeClient client, Arguments args, IndexCollectionType indexType, string indexName, string binName) { console.Info("Create GeoJSON {0} index: ns={1} set={2} index={3} bin={4}", indexType, args.ns, args.set, indexName, binName); Policy policy = new Policy(); policy.timeout = 0; // Do not timeout on index create. IndexTask task = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.GEO2DSPHERE, indexType); task.Wait(); }
private void CreateIndex(AerospikeClient client, Arguments args, string indexName, string binName) { console.Info("Create index: ns={0} set={1} index={2} bin={3}", args.ns, args.set, indexName, binName); Policy policy = new Policy(); policy.timeout = 0; // Do not timeout on index create. IndexTask task = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.NUMERIC); task.Wait(); }
} //scanTweetsCallback public void queryTweetsByUsername() { Console.WriteLine("\n********** Query Tweets By Username **********\n"); RecordSet rs = null; try { // Get username string username; Console.WriteLine("\nEnter username:"******"test", "tweets", "username_index", "username", IndexType.STRING); task.Wait(); string[] bins = { "tweet" }; Statement stmt = new Statement(); stmt.SetNamespace("test"); stmt.SetSetName("tweets"); stmt.SetIndexName("username_index"); stmt.SetBinNames(bins); stmt.SetFilters(Filter.Equal("username", username)); Console.WriteLine("\nHere's " + username + "'s tweet(s):\n"); rs = client.Query(null, stmt); while (rs.Next()) { Record r = rs.Record; Console.WriteLine(r.GetValue("tweet")); } } else { Console.WriteLine("ERROR: User record not found!"); } } finally { if (rs != null) { // Close record set rs.Close(); } } } //queryTweetsByUsername
public static void Prepare(TestContext testContext) { Policy policy = new Policy(); policy.timeout = 0; // Do not timeout on index create. IndexTask task = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.STRING); task.Wait(); for (int i = 1; i <= size; i++) { Key key = new Key(args.ns, args.set, keyPrefix + i); Bin bin = new Bin(binName, valuePrefix + i); client.Put(null, key, bin); } }
} //queryTweetsByUsername public void queryUsersByTweetCount() { Console.WriteLine("\n********** Query Users By Tweet Count Range **********\n"); RecordSet rs = null; try { // NOTE: Index creation has been included in here for convenience and to demonstrate the syntax // NOTE: The recommended way of creating indexes in production env is via AQL IndexTask task = client.CreateIndex(null, "test", "users", "tweetcount_index", "tweetcount", IndexType.NUMERIC); task.Wait(); // Get min and max tweet counts int min; int max; Console.WriteLine("\nEnter Min Tweet Count:"); min = int.Parse(Console.ReadLine()); Console.WriteLine("Enter Max Tweet Count:"); max = int.Parse(Console.ReadLine()); string[] bins = { "username", "tweetcount" }; Statement stmt = new Statement(); stmt.SetNamespace("test"); stmt.SetSetName("users"); stmt.SetIndexName("tweetcount_index"); stmt.SetBinNames(bins); stmt.SetFilters(Filter.Range("tweetcount", min, max)); Console.WriteLine("\nList of users with " + min + "-" + max + " tweets:\n"); rs = client.Query(null, stmt); while (rs.Next()) { Record r = rs.Record; Console.WriteLine(r.GetValue("username") + " has " + r.GetValue("tweetcount") + " tweets"); } } finally { if (rs != null) { // Close record set rs.Close(); } } } //queryUsersByTweetCount
public QueryCollectionInit() { Assembly assembly = typeof(QueryCollectionInit).GetTypeInfo().Assembly; RegisterTask rtask = client.Register(null, assembly, "AerospikeTest.record_example.lua", "record_example.lua", Language.LUA); rtask.Wait(); Policy policy = new Policy(); policy.totalTimeout = 0; // Do not timeout on index create. try { IndexTask task = client.CreateIndex(policy, args.ns, args.set, TestQueryCollection.indexName, TestQueryCollection.binName, IndexType.STRING, IndexCollectionType.MAPKEYS); task.Wait(); } catch (AerospikeException ae) { if (ae.Result != ResultCode.INDEX_ALREADY_EXISTS) { throw; } } for (int i = 1; i <= TestQueryCollection.size; i++) { Key key = new Key(args.ns, args.set, TestQueryCollection.keyPrefix + i); Dictionary <string, string> map = new Dictionary <string, string>(); map[TestQueryCollection.mapKeyPrefix + 1] = TestQueryCollection.mapValuePrefix + i; if (i % 2 == 0) { map[TestQueryCollection.mapKeyPrefix + 2] = TestQueryCollection.mapValuePrefix + i; } if (i % 3 == 0) { map[TestQueryCollection.mapKeyPrefix + 3] = TestQueryCollection.mapValuePrefix + i; } Bin bin = new Bin(TestQueryCollection.binName, map); client.Put(null, key, bin); } }
public static void Prepare(TestContext testContext) { Policy policy = new Policy(); policy.socketTimeout = 0; // Do not timeout on index create. try { IndexTask task = client.CreateIndex(policy, args.ns, setName, indexName, binName, IndexType.GEO2DSPHERE); task.Wait(); } catch (AerospikeException ae) { if (ae.Result != ResultCode.INDEX_ALREADY_EXISTS) { throw ae; } } // Insert points for (int i = 1; i <= size; i++) { Key key = new Key(args.ns, setNamePoints, i); double lng = -122 + (0.1 * i); double lat = 37.5 + (0.1 * i); string loc = "{ \"type\": \"Point\", \"coordinates\": [" + lng + ", " + lat + "] }"; Bin bin = Bin.AsGeoJSON("loc", loc); client.Put(null, key, bin); } // Insert regions double[][] starbucks = new double[][] { new double[] { -122.1708441, 37.4241193 }, new double[] { -122.1492040, 37.4273569 }, new double[] { -122.1441078, 37.4268202 }, new double[] { -122.1251714, 37.4130590 }, new double[] { -122.0964289, 37.4218102 }, new double[] { -122.0776641, 37.4158199 }, new double[] { -122.0943475, 37.4114654 }, new double[] { -122.1122861, 37.4028493 }, new double[] { -122.0947230, 37.3909250 }, new double[] { -122.0831037, 37.3876090 }, new double[] { -122.0707119, 37.3787855 }, new double[] { -122.0303178, 37.3882739 }, new double[] { -122.0464861, 37.3786236 }, new double[] { -122.0582128, 37.3726980 }, new double[] { -122.0365083, 37.3676930 } }; for (int i = 0; i < starbucks.Length; i++) { Key key = new Key(args.ns, setNameRegions, i); string loc = "{ \"type\": \"AeroCircle\", \"coordinates\": [[" + starbucks[i][0] + ", " + starbucks[i][1] + "], 3000.0 ] }"; Bin bin = Bin.AsGeoJSON("loc", loc); client.Put(null, key, bin); } }
public AsyncQueryInit() { Policy policy = new Policy(); policy.totalTimeout = 0; // Do not timeout on index create. try { IndexTask task = client.CreateIndex(policy, args.ns, args.set, TestAsyncQuery.indexName, TestAsyncQuery.binName, IndexType.NUMERIC); task.Wait(); } catch (AerospikeException ae) { if (ae.Result != ResultCode.INDEX_ALREADY_EXISTS) { throw; } } }
public static void Prepare(TestContext testContext) { Policy policy = new Policy(); policy.totalTimeout = 0; // Do not timeout on index create. try { IndexTask task = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.NUMERIC); task.Wait(); } catch (AerospikeException ae) { if (ae.Result != ResultCode.INDEX_ALREADY_EXISTS) { throw; } } }
public static void Prepare(TestContext testContext) { Policy policy = new Policy(); policy.timeout = 0; // Do not timeout on index create. IndexTask itask = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.NUMERIC); itask.Wait(); WritePolicy writePolicy = new WritePolicy(); writePolicy.sendKey = true; for (int i = 1; i <= size; i++) { Key key = new Key(args.ns, args.set, keyPrefix + i); Bin bin = new Bin(binName, i); client.Put(writePolicy, key, bin); } }
private void CreateIndex(AerospikeClient client, Arguments args, IndexCollectionType indexType, string indexName, string binName) { console.Info("Create GeoJSON {0} index: ns={1} set={2} index={3} bin={4}", indexType, args.ns, args.set, indexName, binName); Policy policy = new Policy(); policy.totalTimeout = 0; // Do not timeout on index create. try { IndexTask task = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.GEO2DSPHERE, indexType); task.Wait(); } catch (AerospikeException ae) { if (ae.Result != ResultCode.INDEX_ALREADY_EXISTS) { throw; } } }
public static void Prepare(TestContext testContext) { Assembly assembly = Assembly.GetExecutingAssembly(); RegisterTask task = client.Register(null, assembly, "Aerospike.Test.Resources.average_example.lua", "average_example.lua", Language.LUA); task.Wait(); Policy policy = new Policy(); policy.timeout = 0; // Do not timeout on index create. IndexTask itask = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.NUMERIC); itask.Wait(); for (int i = 1; i <= size; i++) { Key key = new Key(args.ns, args.set, keyPrefix + i); Bin bin = new Bin("l1", i); client.Put(null, key, bin, new Bin("l2", 1)); } }
private void CreateIndex(AsyncClient client, Arguments args, string indexName, string binName) { console.Info("Create index: ns=" + args.ns + " set=" + args.set + " index=" + indexName + " bin=" + binName); Policy policy = new Policy(); policy.totalTimeout = 0; // Do not timeout on index create. try { IndexTask task = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.NUMERIC); task.Wait(); } catch (AerospikeException ae) { if (ae.Result != ResultCode.INDEX_ALREADY_EXISTS) { throw; } } }
public void createSecondaryIndexes() { // NOTE: Index creation has been included in here for convenience and to demonstrate the syntax. The recommended way of creating indexes in production env is via AQL IndexTask task1 = client.CreateIndex(null, "test", "tweets", "username_index", "username", IndexType.STRING); task1.Wait(); Console.WriteLine("Done creating secondary index on: set=tweets, bin=username"); Console.WriteLine("\nCreating secondary index on: set=tweets, bin=ts. Hang on..."); IndexTask task2 = client.CreateIndex(null, "test", "tweets", "ts_index", "ts", IndexType.NUMERIC); task2.Wait(); Console.WriteLine("Done creating secondary index on: set=tweets, bin=ts"); Console.WriteLine("\nCreating secondary index on: set=users, bin=tweetcount. Hang on..."); IndexTask task3 = client.CreateIndex(null, "test", "users", "tweetcount_index", "tweetcount", IndexType.NUMERIC); task3.Wait(); Console.WriteLine("Done creating secondary index on: set=users, bin=tweetcount"); }
} //main public void aggregateUsersByTweetCountByRegion(AerospikeClient client) { ResultSet rs = null; try { int min; int max; Console.WriteLine("\nEnter Min Tweet Count:"); min = int.Parse(Console.ReadLine()); Console.WriteLine("Enter Max Tweet Count:"); max = int.Parse(Console.ReadLine()); Console.WriteLine("\nAggregating users with " + min + "-" + max + " tweets by region. Hang on...\n"); // NOTE: Index creation has been included in here for convenience and to demonstrate the syntax. // NOTE: The recommended way of creating indexes in production env is via AQL. IndexTask task = client.CreateIndex(null, "test", "testusers", "tweetcountindex", "tweetcount", IndexType.NUMERIC); task.Wait(); // NOTE: UDF registration has been included here for convenience and to demonstrate the syntax. // NOTE: The recommended way of registering UDFs in production env is via AQL string luaDirectory = @"..\..\udf"; LuaConfig.PackagePath = luaDirectory + @"\?.lua"; string filename = "aggregationByRegion.lua"; string path = Path.Combine(luaDirectory, filename); RegisterTask rt = client.Register(null, path, filename, Language.LUA); rt.Wait(); Statement stmt = new Statement(); stmt.SetNamespace("test"); stmt.SetSetName("testusers"); stmt.SetIndexName("tweetcountindex"); stmt.SetFilters(Filter.Range("tweetcount", min, max)); rs = client.QueryAggregate(null, stmt, "aggregationByRegion", "sum"); if (rs.Next()) { Dictionary <object, object> result = (Dictionary <object, object>)rs.Object; Console.WriteLine("Here's the breakdown...\n"); Console.WriteLine("Total Users in North: " + result["n"]); Console.WriteLine("Total Users in South: " + result["s"]); Console.WriteLine("Total Users in East: " + result["e"]); Console.WriteLine("Total Users in West: " + result["w"]); } } catch (AerospikeException e) { Console.WriteLine("AerospikeException - Message: " + e.Message); Console.WriteLine("AerospikeException - StackTrace: " + e.StackTrace); } finally { if (rs != null) { // Close record set rs.Close(); } } } //aggregateUsersByTweetCountByRegion