I am trying to programatically COPY a csv file data to a table in Cassandra, using the below mentioned dependency in spring boot.
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-core</artifactId>
<version>4.15.0</version>
</dependency>
The code snippet below is how I'm trying to execute the COPY command in my cassandra instance.
@Override
public void copyData(String tableName, String filePath) {
// Implement logic to execute COPY command to load data into Cassandra table
String copyCommand = String.format(
"COPY %s FROM '%s' WITH HEADER = TRUE;",
tableName, filePath
);
log.info("Executing query: [{}]", copyCommand);
session.execute(copyCommand);
}
When executing the query in Spring Boot with the DataStax Java Driver, the below SyntaxError was encountered. However, the same query executed successfully in the CQLSH within a Docker container, and the data was copied to the table without any issues.
line 1:0 no viable alternative at input 'COPY' ([COPY]...)
Environment:
Spring boot version : 2.7.10
Java version: 17
Cassandra Docker: latest (6.1.0)
[This container is mounted to my local machine from where the csv is available to the container to execute]