title: Spark : Cassandra How to use a query to fetch data from cassandra with pyspark
body: <p>I want to pass query as argument but it is giving following error. </p>
  
  <blockquote>
    <p>url = 'jdbc:cassandra://localhost:9042/tutorialspoint'<br>
        query = 'select * from emp LIMIT 10'</p>
  </blockquote>
  
  <pre><code>#.option("driver", "com.dbschema.CassandraJdbcDriver")\
  df = spark_sql_context.read.format('jdbc')\
                 .option("driver", "com.dbschema.CassandraJdbcDriver")\
                 .option("url",url)\
                 .option("dbtable", query)\
                 .option("numPartitions", 2) \
                 .load()
  
  java.sql.SQLException: com.datastax.driver.core.exceptions.SyntaxError: line 1:14 no viable alternative at input 'select' (SELECT * FROM [select]...)
      at com.dbschema.CassandraPreparedStatement.executeQuery(CassandraPreparedStatement.java:113)
      at org.apache.spark.sql.execution.datasources.jdbc.JDBCRDD$.resolveTable(JDBCRDD.scala:62)
      at org.apache.spark.sql.execution.datasources.jdbc.JDBCRelation.&lt;init&gt;(JDBCRelation.scala:113)
      at org.apache.spark.sql.execution.datasources.jdbc.JdbcRelationProvider.createRelation(JdbcRelationProvider.scala:45)
      at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:330)
      at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:152)
      at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:125)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
      at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
      at py4j.Gateway.invoke(Gateway.java:282)
      at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
  </code></pre>