public void TestFixtureSetup() { if (Values == null || Values.Length == 0) { throw new InconclusiveException("You must specify the values to test"); } CcmHelper.Start(1); Cluster = DseCluster.Builder().AddContactPoint(CcmHelper.InitialContactPoint).Build(); Trace.TraceInformation("Waiting additional time for test Cluster to be ready"); Thread.Sleep(15000); Session = Cluster.Connect(); Session.Execute(string.Format(CreateKeyspaceQuery, Keyspace)); Session.Execute(string.Format("USE {0}", Keyspace)); _queries = new[] { string.Format("CREATE TABLE geotable1 (id text, value '{0}', PRIMARY KEY (id))", TypeName), string.Format("CREATE TABLE keyed (id '{0}', value text, PRIMARY KEY (id))", TypeName), string.Format("INSERT INTO keyed (id, value) VALUES ('{0}', 'hello')", Values[0]), string.Format("CREATE TYPE geo_udt (f text, v '{0}')", TypeName), "CREATE TABLE tbl_udts (id uuid PRIMARY KEY, value frozen<geo_udt>)", string.Format("CREATE TABLE tbl_tuple (id uuid PRIMARY KEY, value tuple<int, '{0}'>)", TypeName), string.Format("CREATE TABLE tbl_list (id uuid PRIMARY KEY, value list<'{0}'>)", TypeName), string.Format("CREATE TABLE tbl_set (id uuid PRIMARY KEY, value set<'{0}'>)", TypeName), string.Format("CREATE TABLE tbl_map (id uuid PRIMARY KEY, value map<text, '{0}'>)", TypeName) }; foreach (var query in _queries) { Session.Execute(query); } }
public Startup(IConfiguration configuration) { Configuration = configuration; String create_keyspace = @"CREATE KEYSPACE IF NOT EXISTS driver_test WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'DC1' : 1 } ; "; String create_user_table = @"CREATE TABLE IF NOT EXISTS driver_test.user ( id uuid, first_name text, last_name text, PRIMARY KEY (id) );"; IDseCluster cluster = DseCluster.Builder() .AddContactPoint("127.0.0.1") .Build(); IDseSession session = cluster.Connect(); session.Execute(create_keyspace); session.Execute(create_user_table); session.Dispose(); }
public static void Main() { IDseCluster cluster = DseCluster.Builder(). AddContactPoint("127.0.0.1"). WithGraphOptions(new GraphOptions().SetName("killrvideo")). Build(); IDseSession session = cluster.Connect(); var killr = DseGraph.Traversal(session); PrintHeader("Actors for Young Guns", "killr.Movies(\"Young Guns\").Actors().Values(\"name\")"); var results = killr.Movies("Young Guns").Actors().Values <string>("name").ToList(); PrintItems(results); PrintHeader("Ratings Distribution by Age for Young Guns", "killr.Movies(\"Young Guns\").Ratings().DistributionForAges(18, 40)"); IDictionary <string, long> ratingsByAge = killr.Movies("Young Guns").Ratings().DistributionForAges(18, 40).Next(); var pairs = String.Join(", ", ratingsByAge.Select(kvp => kvp.Key + "=" + kvp.Value.ToString())); Console.WriteLine($"[{pairs}]"); PrintHeader("Failed Validation", "killr.Movies(\"Young Guns\").Ratings().DistributionForAges(17,40)"); try { killr.Movies("Young Guns").Ratings().DistributionForAges(17, 40).Next(); } catch (ArgumentException ae) { Console.WriteLine($"Caught ArgumentException: {ae.Message}"); } PrintHeader("Five Recommendations for u460", "killr.Users(\"u460\").Recommend(5, 7).Values(KEY_TITLE)"); results = killr.Users("u460").Recommend(5, 7).Values <string>(KeyTitle).ToList(); PrintItems(results); PrintHeader("Five Recommendations for u460 that are comedies", "killr.Users(\"u460\").Recommend(5, 7, Genre(COMEDY)).Values(KEY_TITLE)"); results = killr.Users("u460").Recommend(5, 7, Genre(Comedy)).Values <string>(KeyTitle).ToList(); PrintItems(results); PrintHeader("Five Recommendations for u460 that use larger actor sampling and are comedies", "killr.users(\"u460\").recommend(5, 7, genre(COMEDY)).values(KEY_TITLE)"); results = killr.Users("u460").Recommend(5, 7, LargeSample, Genre(Comedy)).Values <string>(KeyTitle).ToList(); PrintItems(results); PrintHeader("Include some additional graph statistics about Young Guns", "killr.movies(\"Young Guns\").enrich(IN_DEGREE, OUT_DEGREE)"); IDictionary <object, object> enriched = killr.Movies("Young Guns").enrich(InDegree, OutDegree).Next(); pairs = String.Join(", ", enriched.Select(kvp => kvp.Key + "=" + kvp.Value.ToString())); Console.WriteLine($"[{pairs}]"); PrintHeader("Insert/update movie and a actors for that movie", "killr.movie(\"m100000\", \"Manos: The Hands of Fate\",...).actor(...)"); killr.Movie("m100000", "Manos: The Hands of Fate", 1966, 70, "USA", "Sun City Films"). Ensure <Vertex, object, Vertex>(__KillrVideo.Actor("p1000000", "Tom Neyman")). Ensure <Vertex, object, Vertex>(__KillrVideo.Actor("p1000001", "John Reynolds")). Ensure <Vertex, object, Vertex>(__KillrVideo.Actor("p1000002", "Diane Mahree")). Iterate(); Console.WriteLine("Updated 'Manos: The Hands of Fate'"); PrintHeader("Get the actors for the newly added movie", "killr.movies(\"Manos: The Hands of Fate\").actors().values(\"name\")"); results = killr.Movies("Manos: The Hands of Fate").Actors().Values <String>("name").ToList(); PrintItems(results); }
public void Should_Build_A_Cluster_With_DseLoadBalancingPolicy() { //without specifying load balancing policy IDseCluster cluster = DseCluster.Builder().AddContactPoint("192.168.1.159").Build(); Assert.NotNull(cluster.Configuration); Assert.IsInstanceOf <DseLoadBalancingPolicy>( cluster.Configuration.CassandraConfiguration.Policies.LoadBalancingPolicy); }
public void Should_Build_A_Cluster_With_Default_Graph_Options() { //without specifying graph options IDseCluster cluster = DseCluster.Builder().AddContactPoint("192.168.1.159").Build(); Assert.NotNull(cluster.Configuration); Assert.NotNull(cluster.Configuration.CassandraConfiguration); Assert.NotNull(cluster.Configuration.GraphOptions); }
public void Should_Build_A_Cluster_With_The_Specified_LoadBalancingPolicy() { var lbp = new TestLoadBalancingPolicy(); IDseCluster cluster = DseCluster.Builder() .AddContactPoint("192.168.1.159") .WithLoadBalancingPolicy(lbp) .Build(); Assert.NotNull(cluster.Configuration); Assert.AreSame(lbp, cluster.Configuration.CassandraConfiguration.Policies.LoadBalancingPolicy); }
public void Should_Build_A_Cluster_With_Graph_Options() { var graphOptions = new GraphOptions(); IDseCluster cluster = DseCluster.Builder() .WithGraphOptions(graphOptions) .AddContactPoint("192.168.1.159") .Build(); Assert.NotNull(cluster.Configuration); Assert.NotNull(cluster.Configuration.CassandraConfiguration); Assert.AreSame(graphOptions, cluster.Configuration.GraphOptions); }
public void OneTimeSetUp() { TestClusterManager.CreateNew(1, new TestClusterOptions { Workloads = new[] { "graph" } }); CreateClassicGraph(TestClusterManager.InitialContactPoint, GraphName); _cluster = DseCluster.Builder() .AddContactPoint(TestClusterManager.InitialContactPoint) .WithGraphOptions(new GraphOptions().SetName(GraphName)) .Build(); _session = _cluster.Connect(); }
public Guid Post([FromBody] User user) { IDseCluster cluster = DseCluster.Builder() .AddContactPoint("127.0.0.1") .Build(); IDseSession session = cluster.Connect(); Guid user_id = Guid.NewGuid(); var insert_user = session.Prepare( "INSERT INTO driver_test.user (id, first_name, last_name) VALUES(?,?,?)" ); RowSet results = session.Execute(insert_user.Bind(user_id, user.first_name, user.last_name)); return(user_id); }
public CassandraDBRepository(IOptions <CassandraDBOptions> optionsAccessor, ILoggerFactory loggerFactory) { var options = optionsAccessor.Value; IDseCluster cluster = DseCluster.Builder() .AddContactPoints(options.ContactPoints.Split(',')) .WithAuthProvider(new DsePlainTextAuthProvider(options.Username, options.Password)) .Build(); session = cluster.Connect(); tableName = options.Tablename; logger = loggerFactory.CreateLogger <CassandraDBRepository>(); }
static WarmPathFunction() { var contactPoints = Environment.GetEnvironmentVariable("CassandraContactPoints", EnvironmentVariableTarget.Process); var username = Environment.GetEnvironmentVariable("CassandraUsername", EnvironmentVariableTarget.Process); var password = Environment.GetEnvironmentVariable("CassandraPassword", EnvironmentVariableTarget.Process); tableName = Environment.GetEnvironmentVariable("CassandraTableName", EnvironmentVariableTarget.Process); IDseCluster cluster = DseCluster.Builder() .AddContactPoints(contactPoints.Split(',')) .WithAuthProvider(new DsePlainTextAuthProvider(username, password)) .Build(); session = cluster.Connect(); }
public Table <User> GetTable() { IDseCluster cluster = DseCluster.Builder() .AddContactPoint("127.0.0.1") .Build(); IDseSession session = cluster.Connect(); MappingConfiguration.Global.Define( new Map <User>() .TableName("user") .PartitionKey(u => u.Id) .Column(u => u.Id, cm => cm.WithName("id")) .Column(u => u.FirstName, cm => cm.WithName("first_name")) .Column(u => u.LastName, cm => cm.WithName("last_name"))); var users = new Table <User>(session); return(users); }
public string Get(Guid id) { IDseCluster cluster = DseCluster.Builder() .AddContactPoint("127.0.0.1") .Build(); IDseSession session = cluster.Connect(); var get_user = session.Prepare("SELECT * FROM driver_test.user where id = ?"); RowSet results = session.Execute(get_user.Bind(id)); if (results.Any()) { session.Dispose(); Row user = results.First(); return(user.GetValue <String>("first_name") + user.GetValue <String>("last_name")); } else { session.Dispose(); return("User not found"); } }
public IEnumerable <string> Get() { IDseCluster cluster = DseCluster.Builder() .AddContactPoint("127.0.0.1") .Build(); IDseSession session = cluster.Connect(); var get_users = session.Prepare("SELECT * FROM driver_test.user"); RowSet results = session.Execute(get_users.Bind()); List <string> final_results = new List <string>(); foreach (Row row in results.AsEnumerable()) { final_results.Add(row.GetValue <Guid>("id").ToString() + " " + row.GetValue <String>("first_name") + " " + row.GetValue <String>("last_name") + "\n"); } return(final_results); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); IDseCluster cluster = DseCluster.Builder(). AddContactPoint("127.0.0.1"). WithGraphOptions(new GraphOptions().SetName("STUDIO_TUTORIAL_GRAPH")). Build(); IDseSession session = cluster.Connect(); var g = DseGraph.Traversal(session); System.Console.WriteLine(g.V().Gods().As("g").Select <string>("g").By("name").Next()); System.Console.WriteLine(g.V().Gods().As("g").As("t").SelectBy <string>("g.name").Next()); System.Console.WriteLine(g.V().Gods().As("g").SelectValues <string>("g").Next()); var items = g.V().Gods().As("g").SelectValueMap <Dictionary <string, object> >("g").ToList(); foreach (var item in items) { Console.WriteLine(item); } var arr = new string[] { "g.name", "t.name" }; var t = g.V().Gods().As("g").As("t").SelectBy <Object>(arr).Next(); foreach (var r in t) { Console.WriteLine(r); } arr = new string[] { "g.name", "t.name", "p.name" }; var l = g.V().Gods().As("g").As("t").As("p").SelectBy <Object>(arr).Next(); foreach (var r in l) { Console.WriteLine(r); } }