Created
June 29, 2016 22:58
-
-
Save mpenick/9e0f2182ff5b05ab61c1af5d386041c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $cluster = Cassandra::cluster()->build(); | |
| $session = $cluster->connect(); | |
| $session->execute(new Cassandra\SimpleStatement( | |
| "CREATE KEYSPACE IF NOT EXISTS examples | |
| WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '3' }")); | |
| $session->execute(new Cassandra\SimpleStatement( | |
| "CREATE TABLE IF NOT EXISTS examples.test3 (key int PRIMARY KEY, value1 list<text>, value2 set<text>, value3 map<text, text>, value4 map<frozen<set<text>>, frozen<list<text>>>)")); | |
| $query = "SELECT * FROM examples.test3 LIMIT 1"; | |
| $statement = new Cassandra\SimpleStatement($query); | |
| $rows = $session->execute($statement); | |
| if ($rows->count() === 0) { | |
| print "Populating table..."; | |
| $query = "INSERT INTO examples.test3 (key, value1, value2, value3, value4) VALUES (?, ?, ?, ?, ?)"; | |
| for ($i = 0; $i < 100000; $i++) { | |
| $statement = new Cassandra\SimpleStatement($query); | |
| $collection = Cassandra\Type::collection(Cassandra\Type::text())->create("1", "2", "3", "4", "5", "6", "7", "8"); | |
| $set = Cassandra\Type::set(Cassandra\Type::text())->create("1", "2", "3", "4", "5", "6", "7", "8"); | |
| $map = Cassandra\Type::map(Cassandra\Type::text(), Cassandra\Type::text())->create("a", "1", "b", "2", "c", "3", "d", "4", "e", "5", "f", "6", "g", "7", "h", "8"); | |
| $nested = Cassandra\Type::map(Cassandra\Type::set(Cassandra\Type::text()), Cassandra\Type::collection(Cassandra\Type::text()))->create( | |
| Cassandra\Type::set(Cassandra\Type::text())->create("a"), Cassandra\Type::collection(Cassandra\Type::text())->create("1"), | |
| Cassandra\Type::set(Cassandra\Type::text())->create("b"), Cassandra\Type::collection(Cassandra\Type::text())->create("2"), | |
| Cassandra\Type::set(Cassandra\Type::text())->create("c"), Cassandra\Type::collection(Cassandra\Type::text())->create("3"), | |
| Cassandra\Type::set(Cassandra\Type::text())->create("d"), Cassandra\Type::collection(Cassandra\Type::text())->create("4"), | |
| Cassandra\Type::set(Cassandra\Type::text())->create("e"), Cassandra\Type::collection(Cassandra\Type::text())->create("5"), | |
| Cassandra\Type::set(Cassandra\Type::text())->create("f"), Cassandra\Type::collection(Cassandra\Type::text())->create("6"), | |
| Cassandra\Type::set(Cassandra\Type::text())->create("g"), Cassandra\Type::collection(Cassandra\Type::text())->create("7"), | |
| Cassandra\Type::set(Cassandra\Type::text())->create("h"), Cassandra\Type::collection(Cassandra\Type::text())->create("8") | |
| ); | |
| $options = array('arguments' => array($i, $collection, $set, $map, $nested)); | |
| $options = new Cassandra\ExecutionOptions($options); | |
| $session->execute($statement, $options); | |
| } | |
| print "Done.\n"; | |
| } | |
| print "Paging table...\n"; | |
| $query = "SELECT * FROM examples.test3"; | |
| $statement = new Cassandra\SimpleStatement($query); | |
| $options = array('page_size' => 10); | |
| $options = new Cassandra\ExecutionOptions($options); | |
| $startMem = memory_get_usage(); | |
| $rows = $session->execute($statement, $options); | |
| $count = 0; | |
| while ($rows = $rows->nextPage()) { | |
| if ($count % 1000 == 0) { | |
| $endMem = memory_get_usage(); | |
| $memUsage = $endMem - $startMem; | |
| print "Memory usage = Delta: $memUsage, Start: $startMem, End: $endMem\n"; | |
| } | |
| $count += $rows->count(); | |
| } | |
| print "Done.\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment