I am using cassandra database cassandra:2.2.3 in my application and i should use like operator to get all the names starts with 'A%'.
CREATE CUSTOM INDEX empnames_idx ON d.emp (ename)
USING 'org.apache.cassandra.index.sasi.SASIIndex';
After creating the index when i run the below query :
select * from d.emp where ename like 'A%';
<Error from server: code=2000 [Syntax error in CQL query] message="line 1:49 no viable alternative at input 'LIKE' (...* from d.emp where ename like .....)"
It's not supported until 3.4+ but should upgrade to 3.11.latest. You may want to configure your index as well, an excellent walkthrough is here: http://www.doanduyhai.com/blog/?p=2058
Related
My table looks like :
CREATE TABLE prod_cust (
pid bigint,
cid bigint,
effective_date date,
expiry_date date,
PRIMARY KEY ((pid, cid))
);
My below query is giving no viable alternative at input 'OR' error
SELECT * FROM prod_cust
where
pid=101 and cid=201
OR
pid=102 and cid=202;
Does Cassandra not support OR operator if not, Is there any alternate way to achieve my result.
CQL does not support the OR operator. Sometimes you can get around that by using IN. But even IN won't let you do what you're attempting.
I see two options:
Submit each side of your OR as individual queries.
Restructure the table to better-suit what you're trying to do. Doing a "port-over" from a RDBMS to Cassandra almost never works as intended.
I use wso2 dss to insert data into a cassandra table.
for exemple this table :
CREATE TABLE logs.test (id int,code int, PRIMARY KEY (id));
Inside wso2 dss, I defined code column with default value like this : #{NULL}
When I Try the dss service like this without given the code parameter:
<p:test xmlns:p="http://ws.wso2.org/dataservice">
<xs:id xmlns:xs="http://ws.wso2.org/dataservice">1</xs:id>
</p:test>
I get this error :
<axis2ns56:source_data_service>
<axis2ns56:data_service_name>Cassandra</axis2ns56:data_service_name>
<axis2ns56:description>N/A</axis2ns56:description>
<axis2ns56:location>\Cassandra.dbs</axis2ns56:location>
<axis2ns56:default_namespace>http://ws.wso2.org/dataservice</axis2ns56:default_namespace>
</axis2ns56:source_data_service>
<axis2ns56:ds_code>UNKNOWN_ERROR</axis2ns56:ds_code>
<axis2ns56:nested_exception>java.lang.NumberFormatException: null</axis2ns56:nested_exception>
Nested Exception:- java.lang.NumberFormatException: For input string: "null"
Best regards,
Nicolas
Would it be possible to get the source of the dataservice?
Did you try with the following payload
<p:test xmlns:p="http://ws.wso2.org/dataservice">
<p:id>1</p:id>
<p:code>2</p:code>
</p:test>
So I guess your issue is in this part
<param defaultValue="#{NULL}" name="code" sqlType="INTEGER"/>.
I do not know your use case but if I remember well it's not so nice to insert null values in Cassandra because it create tombstones.
You could as well have a second query that simply inserts the id like
insert test (id) values (:id).
The execption sound to be raised by dss not cassandra, looks like it is not able to set a null value for integer field
I find a workaround, I use the jdbc cassandra instead of com.datatasax driver.
And it work well. The only problem is that I just can call only one node for the connection and not the cluster.
I hope the problem will be resolve soon and I will use the Dss Cassandra datasource connection again.
Thks for your help
I am new to Cassandra and I am using version 3.11.
I have below UDT type and I am trying to write ALTER Query to change. I am able to write separate command for RENAME, ADD but I want to have all in one query. Could I get help to have in one query.
create type if not exists payment_types (
billing_type int,
payer_id text
);
ALTER TYPE payment_types to have following fields
billing_type text,
billing_id text,
biller_name text,
payer_name text
Also when I was executing i am getting
Error from server: code=2200 [Invalid query] message="Altering of types is not allowed"
You are using cassandra 3.11 version.
Here is details:
https://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlAlterTable.html
There are some specifications to alter data types:
https://docs.datastax.com/en/cql/3.3/cql/cql_reference/cql_data_types_c.html#cql_data_types_c__cql_data_type_compatibility
USE users_tracking;
SELECT user_name FROM visits
where port_name IN
(SELECT port_name FROM ports where location = 'NY' )//as temp;
It gives an error
mismatched input 'SELECT' expecting RULE_T_R_PAREN
Is there any way I can store the inner query in a variable and then use that?
I tried using set#varname := query but it does not recognize the set command.
Nested queries are not allowed in Cassandra CQL. For this kind of complex querying feature you'll need to use Hive or SparkSQL.
Here is a full CQL reference,
http://cassandra.apache.org/doc/cql3/CQL.html
I am trying to run the following query
SELECT edge_id, b_id FROM booking_by_edge WHERE edge_id IN ?
I bind Java list of Long's as a parameter and I get an exception
SyntaxError: line 0:-1 mismatched input '<EOF>' expecting ')' (ResultSetFuture.java:242)
If I try to use (?) it expects single Long item to be bound, but I need a collection
Is there an error in my syntax?
Tested in Cassandra 2.1.3, the following code snippet works:
PreparedStatement prepared = session.prepare("SELECT edge_id, b_id FROM booking_by_edge WHERE edge_id IN ?;");
List<Long> edgeIds = Arrays.asList(1L, 2L, 3L);
session.execute(prepared.bind(edgeIds));
Got response on Datastax bugzilla, it is currently not supported, but planned
https://issues.apache.org/jira/browse/CASSANDRA-4210
Update: Supported in Cassandra 2.0.1
It's a bit hard to find in the documentation but it is described in the tuples section of the manual.
If you want to use named parameters you should use the setList() method.
BoundStatement bs = session.prepare("select col from table where col in :values").bind();
bs.setList("values", Arrays.asList(v1, v2, v3));