title: Spark Cassandra : java.lang.IllegalArgumentException: requirement failed: Column features must be of type org.apache.spark.mllib.linalg.VectorUDT
body: <p>Can some help me convert the data from Cassandra row to be converted to Vector using Java</p>
  
  <p>The code snippet where its failing is as below.</p>
  
  <p>I am reading data from Cassandra table and trying to create a RandomForestClassifier model as below. </p>
  
  <pre><code>    JavaRDD&lt;VibrationData1&gt; vibrationReadRdd = CassandraJavaUtil
              .javaFunctions(sc)
              .cassandraTable("vibration_ks", "vibration_data_feature",
                      CassandraJavaUtil.mapRowTo(VibrationData1.class))
              .select("classifier", "features");
  
      System.out.println("vibrationRdd.count()   --------- "
              + vibrationReadRdd.count());
  
      SQLContext sqlContext = new SQLContext(sc);
  
      DataFrame data = sqlContext.createDataFrame(vibrationReadRdd,
              VibrationData1.class);
  
      StringIndexerModel labelIndexer = new StringIndexer()
              .setInputCol("classifier").setOutputCol("indexedLabel")
              .fit(data);
      // Automatically identify categorical features, and index them.
      // Set maxCategories so features with &gt; 4 distinct values are treated as
      // continuous.
      VectorIndexerModel featureIndexer = new VectorIndexer()
              .setInputCol("features").setOutputCol("indexedFeatures")
              .setMaxCategories(4).fit(data);
  </code></pre>
  
  <p>The error is observed at line       </p>
  
  <pre><code>VectorIndexerModel featureIndexer = new  VectorIndexer().setInputCol("features"). setOutputCol("indexedFeatures").setMaxCategories(4).fit(data);
  </code></pre>
  
  <p>The error message below</p>
  
  <p>17/01/18 13:15:49 INFO DAGScheduler: Job 2 finished: countByValue at StringIndexer.scala:86, took 3.331207 s
  Exception in thread "main" java.lang.IllegalArgumentException: requirement failed: Column features must be of type org.apache.spark.mllib.linalg.VectorUDT@f71b0bce but was actually StringType.
          at scala.Predef$.require(Predef.scala:233)
          at org.apache.spark.ml.util.SchemaUtils$.checkColumnType(SchemaUtils.scala:42)
          at org.apache.spark.ml.feature.VectorIndexer.transformSchema(VectorIndexer.scala:134)
          at org.apache.spark.ml.PipelineStage.transformSchema(Pipeline.scala:68)
          at org.apache.spark.ml.feature.VectorIndexer.fit(VectorIndexer.scala:112)
          at com.edge.database.test.VibrationDBUtil.createSchema(VibrationDBUtil.java:161)
          at com.edge.database.test.VibrationDBUtil.run(VibrationDBUtil.java:95)
          at com.edge.database.test.VibrationDBUtil.main(VibrationDBUtil.java:217)
          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 org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:731)
          at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:181)
          at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:206)
          at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121)
          at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)</p>
  
  <p>The cassandra table is as below</p>
  
  <p>cqlsh:vibration_ks> select * from vibration_data_feature;</p>
  
  <p>uid | classifier | features </p>
  
  <p>-----+------------+-----------------------------------------</p>
  
  <p>  15 |          0 | 10:0.0092 11:0.0093 20:0.0094 21:0.0095 </p>
  
  <p>17 |          1 | 10:0.192 11:0.3093 20:0.8094 21:0.9095</p>
  
  <p>Thanks in advance.</p>