You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "frankgh (via GitHub)" <gi...@apache.org> on 2023/07/11 17:39:27 UTC

[GitHub] [cassandra-analytics] frankgh opened a new pull request, #10: CASSANDRA-18662: Fix cassandra-analytics-core-example

frankgh opened a new pull request, #10:
URL: https://github.com/apache/cassandra-analytics/pull/10

   This commit fixes the `SampleCassandraJob` available under the `cassandra-analytics-core-example` subproject.


-- 
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-unsubscribe@cassandra.apache.org

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


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


[GitHub] [cassandra-analytics] frankgh closed pull request #10: CASSANDRA-18662: Fix cassandra-analytics-core-example

Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh closed pull request #10: CASSANDRA-18662: Fix cassandra-analytics-core-example
URL: https://github.com/apache/cassandra-analytics/pull/10


-- 
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-unsubscribe@cassandra.apache.org

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


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


[GitHub] [cassandra-analytics] frankgh commented on pull request #10: CASSANDRA-18662: Fix cassandra-analytics-core-example

Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on PR #10:
URL: https://github.com/apache/cassandra-analytics/pull/10#issuecomment-1638929268

   Closed via https://github.com/apache/cassandra-analytics/commit/69766bca399cc779e0f2f8e859e39f7e29a17b7a


-- 
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-unsubscribe@cassandra.apache.org

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


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


[GitHub] [cassandra-analytics] frankgh commented on a diff in pull request #10: CASSANDRA-18662: Fix cassandra-analytics-core-example

Posted by "frankgh (via GitHub)" <gi...@apache.org>.
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-unsubscribe@cassandra.apache.org

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


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