CREATE TYPE IF NOT EXISTS myks.profiles (
"field" text
);
It gives me the below exception when I try to create a UDT with name profiles com.datastax.driver.core.exceptions.SyntaxError: line 1:17 no viable alternative at input 'profiles' (CREATE TYPE myks.[profiles]...)
Update: it looks like a bug. I suggest to use word profile instead...
Original answer:
Keyspaces in Cassandra are created with CREATE KEYSPACE command, and you're trying to create a new user-defined type instead. This error is returned because the keyspace myks is not yet defined.
In your case full command will be:
CREATE KEYSPACE IF NOT EXISTS profiles WITH replication =
{'class': 'NetworkTopologyStrategy', 'your_dc': 'rep_factor'};
you need to substitute the name of your datacenter(s) instead of your_dc, and adjust rep_factor to match number of nodes.
But for beginning I suggest to watch at least DS201 course on DatStax Academy - it should give your overview of basic operations, etc.
Related
create table if not exists map_table like position_map_view;
While using this it is giving me operation not allowed error
As pointed in documentation, you need to use CREATE TABLE AS, just use LIMIT 0 in SELECT:
create table map_table as select * from position_map_view limit 0;
I didn't find an easy way of getting CREATE TABLE LIKE to work, but I've got a workaround. On DBR in Databricks you should be able to use SHALLOW CLONE to do something similar:
%sql
CREATE OR REPLACE TABLE $new_database.$new_table
SHALLOW CLONE $original_database.$original_table`;
You'll need to replace $templates manually.
Notes:
This has an added side-effect of preserving the table content in case you need it.
Ironically, creating empty table is much harder and involves manipulating show create table statement with custom code
I'm using cassandra. I am trying to update the gc_grace value using new bind variable.
ALTER table keyspace.table_name with gc_grace_seconds = ? ;
I got the following error:
no viable alternative at input '?'
How can I solve this?
As I see from the source code (maybe I'm wrong), but ALTER TABLE doesn't support bindings, so you can't use them for this command (and all DDL commands), and need to just use execute with specific value
It looks like you're trying to bind parameters programatically to set GC grace on a table. It isn't possible to do that using the Cassandra drivers.
It will only work through cqlsh. For example:
cqlsh> ALTER TABLE community.maptbl WITH gc_grace_seconds = 3600;
It doesn't make sense to do it in your app and it is not recommended. Cheers!
I am working on a Cassandra database, where I have to recreate a keyspace, and redirect data in the table of that keyspace. I successfully create the keyspace, but when I want to redirect the data :
copy table_name from './file_name.csv' with header=false;
I get this error :
get_num_processes() takes no keyword arguments
I tried to delete the copyutil.so file, like it was suggested in the question :
get_num_processes() takes no keyword arguments (CSV <-> CASSANDRA)
but it didn't work...
Thank you
I'm trying to query a Cassandra 2.0.2 server using the phpcassa libraray.
I do the following:
<?php
require('phpcassa/lib/autoload.php');
use phpcassa\ColumnFamily;
use phpcassa\ColumnSlice;
use phpcassa\Connection\ConnectionPool;
$pool = new ConnectionPool('Cronnection', array('MY_SERVER_IP:9160'));
$conversations = new ColumnFamily($pool, 'conversations');
var_dump( $conversations->get('2521b0f0-8e36-11e3-a489-8f038e859082') );
When I do this I get an uncaught 'cassandra\NotFoundException' exception.
After reading in the source I see that this is because the column family 'conversations' is not getting loaded into the cloumn families array created by the ConnectionPool::describe_keyspace() method.
When I print the result of "describe_keyspace", using the following code, I can see that only one of my column families, called user_profiles, is getting loaded into my column families array.
<?php
require('phpcassa/lib/autoload.php');
use phpcassa\ColumnFamily;
use phpcassa\ColumnSlice;
use phpcassa\Connection\ConnectionPool;
$pool = new ConnectionPool('Cronnection', array('MY_SERVER_IP:9160'));
echo '<pre>';
var_dump($pool->describe_keyspace());
There are 6 column families defined in that keyspace but phpcassa is only listing "user_profiles"; the only difference between "user_profiles" and the other CFs is that "user_profiles" is using the "WITH COMPACT STORAGE" property.
Any thoughts on how to solve this or why is this happenning?
Thanks!
PS: I created the column families using CQL3 through cqlsh, when I do "describe" using cassandra-cli I can't see my column families, only the "user_profiles" one that I mentioned, could this somehow be related?
Yes, this is in fact related to COMPACT STORAGE and cassandra-cli not showing your other column families. phpcassa and other Thrift-based clients (such as cassandra-cli) can only use tables created through CQL3 if they are created WITH COMPACT STORAGE.
In short, I suggest sticking to COMPACT STORAGE tables if you will be working with phpcassa. If you want to read more, there is a somewhat advanced article that shows explains how Thrift, CQL3 and compact storage fit together.
I write because I've a problem with cassandra; after have imported the data from pentaho as show here
http://wiki.pentaho.com/display/BAD/Write+Data+To+Cassandra
when I try to execute the query
Select * FROM mytable;
cassandre give me an error message
Syntax error at position 7: unexpected "*" for Select * FROM mytable;.
and don't show the results of query.Why? what does it mean that error?
the step that i make are the follow:
start cassandra cli utility;
use keyspace added from pentaho; (use tpc_h);
select to show the data added (Select * FROM mytable;)
The cassandra-cli does not support any CQL version. It has its own syntax which you can find on datastax's website.
Just for clarity, in cql to select everything from a table (aka column-family) called mytable stored in a keyspace called myks you would use:
SELECT * FROM myks.mytable;
The equivalent in cassandra-cli would *roughly be :
USE myks;
LIST mytable;
***** In the cli you are limited to selecting the first 100 rows. If this is a problem you can use the limit clause to specify how many rows you want:
LIST mytable limit 10000;
As for this:
in cassandra i have read that isn't possible make the join such as sql, ther isn't a shortcut to issue this disadvantage
There is a reason why joins don't exist in Cassandra, its for the same reason that C* isn't ACID compliant, it sacrifices that functionality for it's amazing performance and scalability, so it's not a disadvantage, you just need to re-think your model if you need joins. Also take a look at this question / answer.