frankgh commented on code in PR #10:
URL: 
https://github.com/apache/cassandra-analytics/pull/10#discussion_r1260089139


##########
cassandra-analytics-core-example/src/main/java/org/apache/cassandra/spark/example/SampleCassandraJob.java:
##########
@@ -128,26 +130,46 @@ private static Dataset<Row> write(long rowCount, 
SparkConf sparkConf, SQLContext
     {
         JavaSparkContext javaSparkContext = 
JavaSparkContext.fromSparkContext(sc);
         int parallelism = sc.defaultParallelism();
-        boolean addTTLColumn = true;
-        boolean addTimestampColumn = true;
+        boolean addTTLColumn = false;
+        boolean addTimestampColumn = false;
         JavaRDD<Row> rows = genDataset(javaSparkContext, rowCount, 
parallelism, addTTLColumn, addTimestampColumn);
         Dataset<Row> df = sql.createDataFrame(rows, 
getWriteSchema(addTTLColumn, addTimestampColumn));
 
-        df.write()
-          .format("org.apache.cassandra.spark.sparksql.CassandraDataSink")
-          .option("sidecar_instances", "localhost,localhost2,localhost3")
-          .option("keyspace", "spark_test")
-          .option("table", "test")
-          .option("local_dc", "datacenter1")
-          .option("bulk_writer_cl", "LOCAL_QUORUM")
-          .option("number_splits", "-1")
-          // A constant timestamp and TTL can be used by setting the following 
options.
-          // .option(WriterOptions.TIMESTAMP.name(), 
TimestampOption.constant(System.currentTimeMillis() * 1000))
-          // .option(WriterOptions.TTL.name(), TTLOption.constant(20))
-          .option(WriterOptions.TTL.name(), TTLOption.perRow("ttl"))
-          .option(WriterOptions.TIMESTAMP.name(), 
TimestampOption.perRow("timestamp"))
-          .mode("append")
-          .save();
+        DataFrameWriter<Row> dfWriter = df.write()
+                                          
.format("org.apache.cassandra.spark.sparksql.CassandraDataSink")
+                                          .option("sidecar_instances", 
"localhost,localhost2,localhost3")
+                                          .option("keyspace", "spark_test")
+                                          .option("table", "test")
+                                          .option("local_dc", "datacenter1")
+                                          .option("bulk_writer_cl", 
"LOCAL_QUORUM")
+                                          .option("number_splits", "-1")
+                                          // A constant timestamp and TTL can 
be used by setting the following options.
+                                          // .option(WriterOptions.TTL.name(), 
TTLOption.constant(20))
+                                          // 
.option(WriterOptions.TIMESTAMP.name(), 
TimestampOption.constant(System.currentTimeMillis() * 1000))
+                                          .mode("append");
+
+        List<String> addedColumns = new ArrayList<>();
+        if (addTTLColumn)
+        {
+            addedColumns.add("ttl");
+            dfWriter = dfWriter
+                       .option(WriterOptions.TTL.name(), 
TTLOption.perRow("ttl"));
+        }
+
+        if (addTimestampColumn)
+        {
+            addedColumns.add("timestamp");
+            dfWriter = dfWriter
+                       .option(WriterOptions.TIMESTAMP.name(), 
TimestampOption.perRow("timestamp"));
+        }
+
+        dfWriter.save();
+
+        if (!addedColumns.isEmpty())
+        {
+            df = df.drop(addedColumns.toArray(new String[0]));

Review Comment:
   remove the columns from the schema, so we can validate.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to