Reputation: 81
I'm setting up a Cassandra database and try to create tables with an MD5 hash code as table name.
When I do this, I get an com.datastax.oss.driver.api.core.servererrors.SyntaxError: line 1:35 mismatched character '2' expecting '-'
exception.
My Query:
CREATE TABLE IF NOT EXISTS 77f2d6b127b7d4a89a940d0829ff1e672afb4362_status (
jsonSchema TEXT,
onlineStatus INT,
key text,
timestamp timeuuid,
primary key(key, timestamp)
) WITH CLUSTERING ORDER BY (timestamp DESC)
AND compaction = {'class': 'TimeWindowCompactionStrategy',
'compaction_window_size': 1,
'compaction_window_unit': 'DAYS'};
And the exception:
Caused by: com.datastax.oss.driver.api.core.servererrors.SyntaxError: line 1:35 mismatched character '2' expecting '-'
at com.datastax.oss.driver.api.core.servererrors.SyntaxError.copy(SyntaxError.java:48)
at com.datastax.oss.driver.internal.core.util.concurrent.CompletableFutures.getUninterruptibly(CompletableFutures.java:113)
at com.datastax.oss.driver.internal.core.cql.CqlRequestSyncProcessor.process(CqlRequestSyncProcessor.java:53)
at com.datastax.oss.driver.internal.core.cql.CqlRequestSyncProcessor.process(CqlRequestSyncProcessor.java:30)
at com.datastax.oss.driver.internal.core.session.DefaultSession.execute(DefaultSession.java:207)
at com.datastax.oss.driver.api.core.CqlSession.execute(CqlSession.java:47)
at com.datastax.oss.driver.api.core.CqlSession.execute(CqlSession.java:56)
I wonder why this happens. According to https://docs.datastax.com/en/archived/cql/3.3/cql/cql_reference/ref-lexical-valid-chars.html the query should have a correct syntax.
It works when I put the table name in double quotation marks (CREATE TABLE IF NOT EXISTS "77f2d6b127b7d4a89a940d0829ff1e672afb4362_status" (...
but then I get problems with my IntelliJ database IDE because it does not query the database using double quotation marks for the table names.
When I add in front of the table name manually a letter (not a number; e.g. a77f2d6b127b7d4a89a940d0829ff1e672afb4362_status
), the table is created but I get another timeout exception:
com.datastax.oss.driver.api.core.DriverTimeoutException: Query timed out after PT2S
at com.datastax.oss.driver.api.core.DriverTimeoutException.copy(DriverTimeoutException.java:34)
at com.datastax.oss.driver.internal.core.util.concurrent.CompletableFutures.getUninterruptibly(CompletableFutures.java:113)
at com.datastax.oss.driver.internal.core.cql.CqlRequestSyncProcessor.process(CqlRequestSyncProcessor.java:53)
at com.datastax.oss.driver.internal.core.cql.CqlRequestSyncProcessor.process(CqlRequestSyncProcessor.java:30)
at com.datastax.oss.driver.internal.core.session.DefaultSession.execute(DefaultSession.java:207)
at com.datastax.oss.driver.api.core.CqlSession.execute(CqlSession.java:47)
at com.datastax.oss.driver.api.core.CqlSession.execute(CqlSession.java:56)
After the timeout exception I can execute the same query again. This time without errors -> table was successfully created.
I use following Java driver: [Maven: com.datastax.oss:java-driver-core:4.0.1]
Any help is more than welcome.
Upvotes: 2
Views: 2347
Reputation: 4526
cfName
. As you can see a table name can be either a non-quoted identifier (IDENT
), a quoted name (QUOTED_NAME
) or unreserved keywords. The rule for IDENT
is defined here. As you can see, it needs to start with a letter. To create a table named like yours, you need to double quote it (I tried with CQLSH, and it worked – sorry if IntelliJ cannot understand that).session.execute( SimpleStatement.newInstance( "CREATE TABLE IF NOT EXISTS ...") .setTimeout(Duration.ofSeconds(30)));
Upvotes: 1
Reputation: 87154
I think that documentation is incorrect - it should say:
starts with alpha character, and contains alpha-numeric, ...
I haven't found this definition for table/keyspace names in the grammar for CQL (only for column names), but it's visible in the cqlsh code.
Upvotes: 1